Skip to content

Commit 4b7932e

Browse files
authored
fix bad str to int conversion (#147)
* fix bad str to int conversion * Round 2 * Round 2
1 parent a7ab525 commit 4b7932e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

custom_components/iec/coordinator.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ async def _async_update_data(
433433

434434
else:
435435
devices_by_id: Devices = await self._get_devices_by_device_id(device.device_number)
436-
last_meter_read = devices_by_id.counter_devices[0].last_mr
436+
last_meter_read = int(devices_by_id.counter_devices[0].last_mr)
437437
last_meter_read_date = devices_by_id.counter_devices[0].last_mr_date
438438
phase_count = devices_by_id.counter_devices[0].connection_size.phase
439439
connection_size = (devices_by_id.counter_devices[0].
@@ -657,7 +657,7 @@ def _calculate_estimated_bill(meter_id, future_consumptions: dict[str, FutureCon
657657
distribution_price = 0
658658
delivery_price = 0
659659

660-
consumption_price = future_consumption * kwh_tariff
660+
consumption_price = round(future_consumption * kwh_tariff, 2)
661661
total_days = 0
662662

663663
today = TIMEZONE.localize(datetime.today())
@@ -684,16 +684,16 @@ def _calculate_estimated_bill(meter_id, future_consumptions: dict[str, FutureCon
684684
total_days = today.day
685685
days_in_current_month = calendar.monthrange(today.year, today.month)[1]
686686

687-
consumption_price = future_consumption * kwh_tariff
688-
total_kva_price = kva_price * total_days
689-
distribution_price = (distribution_tariff / days_in_current_month) * total_days
687+
consumption_price = future_consumption * kwh_tariff, 2
688+
total_kva_price = kva_price * total_days, 2
689+
distribution_price = (distribution_tariff / days_in_current_month) * total_days, 2
690690
delivery_price = (delivery_tariff / days_in_current_month) * total_days
691691

692692
_LOGGER.debug(f'Calculated estimated bill: No. of days: {total_days}, total KVA price: {total_kva_price}, '
693693
f'total distribution price: {distribution_price}, total delivery price: {delivery_price}, '
694694
f'consumption price: {consumption_price}')
695695

696-
fixed_price = total_kva_price + distribution_price + delivery_price
697-
total_estimated_bill = consumption_price + fixed_price
698-
return total_estimated_bill, fixed_price, consumption_price, total_days, \
699-
delivery_price, distribution_price, total_kva_price, future_consumption
696+
fixed_price = round(total_kva_price + distribution_price + delivery_price, 2)
697+
total_estimated_bill = round(consumption_price + fixed_price, 2)
698+
return total_estimated_bill, fixed_price, round(consumption_price, 2), total_days, \
699+
round(delivery_price, 2), round(distribution_price, 2), round(total_kva_price, 2), future_consumption

0 commit comments

Comments
 (0)