Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions custom_components/iec/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ async def async_step_mfa(
for contract in contracts
if contract.status == 1
]
if len(contract_ids) == 1:
if not contracts:
errors["base"] = "no_contracts"
elif len(contract_ids) == 1:
data[CONF_SELECTED_CONTRACTS] = [contract_ids[0]]
return self._async_create_iec_entry(data)
else:
Expand Down Expand Up @@ -181,7 +183,7 @@ async def async_step_select_contracts(
and user_input.get(CONF_SELECTED_CONTRACTS) is not None
):
if len(user_input.get(CONF_SELECTED_CONTRACTS)) == 0:
errors["base"] = "no_contracts"
errors["base"] = "no_selected_contracts"
else:
data = {**self.data, **user_input}
if data.get(CONF_AVAILABLE_CONTRACTS):
Expand Down
31 changes: 21 additions & 10 deletions custom_components/iec/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ async def _verify_daily_readings_exist(
)
if not daily_reading:
_LOGGER.debug(
f'Daily reading for date: {desired_date.strftime("%Y-%m-%d")} is missing, calculating manually'
f"Daily reading for date: {desired_date.strftime('%Y-%m-%d')} is missing, calculating manually"
)
readings = prefetched_reading
if not readings:
Expand All @@ -330,7 +330,7 @@ async def _verify_daily_readings_exist(
)
else:
_LOGGER.debug(
f'Daily reading for date: {desired_date.strftime("%Y-%m-%d")} - using existing prefetched readings'
f"Daily reading for date: {desired_date.strftime('%Y-%m-%d')} - using existing prefetched readings"
)

if readings and readings.data:
Expand All @@ -353,16 +353,16 @@ async def _verify_daily_readings_exist(
)
if desired_date_reading is None or desired_date_reading.value <= 0:
_LOGGER.debug(
f'Couldn\'t find daily reading for: {desired_date.strftime("%Y-%m-%d")}'
f"Couldn't find daily reading for: {desired_date.strftime('%Y-%m-%d')}"
)
else:
daily_readings[device.device_number].append(
RemoteReading(0, desired_date, desired_date_reading.value)
)
else:
_LOGGER.debug(
f'Daily reading for date: {daily_reading.date.strftime("%Y-%m-%d")}'
f' is present: {daily_reading.value}'
f"Daily reading for date: {daily_reading.date.strftime('%Y-%m-%d')}"
f" is present: {daily_reading.value}"
)

async def _update_data(
Expand Down Expand Up @@ -454,7 +454,9 @@ async def _update_data(

devices = await self._get_devices_by_contract_id(contract_id)
if not devices:
_LOGGER.debug(f"No devices for contract {contract_id}. Skipping creating devices.")
_LOGGER.debug(
f"No devices for contract {contract_id}. Skipping creating devices."
)
continue

for device in devices or []:
Expand Down Expand Up @@ -589,7 +591,7 @@ async def _update_data(
last_invoice,
)
except Exception as e:
_LOGGER.warn("Failed to calculate estimated next bill", e)
_LOGGER.warning("Failed to calculate estimated next bill", e)
estimated_bill = 0
consumption_price = 0
total_days = 0
Expand Down Expand Up @@ -705,7 +707,14 @@ async def _insert_statistics(self, contract_id: int, is_smart_meter: bool) -> No

if readings and readings.meter_start_date:
# Fetching the last reading from either the installation date or a month ago
month_ago_time = max(month_ago_time, TIMEZONE.localize(datetime.combine(readings.meter_start_date, datetime.min.time())))
month_ago_time = max(
month_ago_time,
TIMEZONE.localize(
datetime.combine(
readings.meter_start_date, datetime.min.time()
)
),
)
else:
_LOGGER.debug(
"[IEC Statistics] Failed to extract field `meterStartDate`, falling back to a month ago"
Expand Down Expand Up @@ -1016,8 +1025,10 @@ def _calculate_estimated_bill(
future_consumption_info.total_import - last_meter_read
)
else:
_LOGGER.warn(f"Failed to calculate Future Consumption, Assuming last meter read \
({last_meter_read}) as full consumption")
_LOGGER.warning(
f"Failed to calculate Future Consumption, Assuming last meter read \
({last_meter_read}) as full consumption"
)
future_consumption = last_meter_read

kva_price = power_size * kva_tariff / 365
Expand Down
8 changes: 6 additions & 2 deletions custom_components/iec/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@
},
"select_contracts": {
"title": "Select Contract",
"description": "Select which contract to use"
"description": "Select which contract to use",
"data": {
"no_contracts": "No Contracts Found"
}
},
"reauth_confirm": {
"title": "[%key:common::config_flow::title::reauth%]",
Expand All @@ -95,7 +98,8 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"invalid_id": "Invalid Israeli ID",
"no_contracts": "You should select at least one contract"
"no_selected_contracts": "You should select at least one contract",
"no_contracts": "No Contracts Found"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
Expand Down
8 changes: 6 additions & 2 deletions custom_components/iec/translations/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@
},
"select_contracts": {
"title": "בחירת חשבון חוזה",
"description": "בחרו באיזה חשבון חוזה להשתמש"
"description": "בחרו באיזה חשבון חוזה להשתמש",
"data": {
"no_contracts": "לא נמצאו חשבונות חוזה"
}
},
"reauth_confirm": {
"title": "[%key:common::config_flow::title::reauth%]",
Expand All @@ -95,7 +98,8 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"invalid_id": "תעודת זהות לא תקנית",
"no_contracts": "נא לבחור לפחות חוזה אחד"
"no_selected_contracts": "נא לבחור לפחות חוזה אחד",
"no_contracts": "לא נמצאו חוזים"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
Expand Down