diff --git a/custom_components/iec/config_flow.py b/custom_components/iec/config_flow.py index 7443e66..bcbc375 100644 --- a/custom_components/iec/config_flow.py +++ b/custom_components/iec/config_flow.py @@ -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: @@ -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): diff --git a/custom_components/iec/coordinator.py b/custom_components/iec/coordinator.py index 47baf1d..13cea3a 100644 --- a/custom_components/iec/coordinator.py +++ b/custom_components/iec/coordinator.py @@ -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: @@ -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: @@ -353,7 +353,7 @@ 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( @@ -361,8 +361,8 @@ async def _verify_daily_readings_exist( ) 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( @@ -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 []: @@ -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 @@ -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" @@ -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 diff --git a/custom_components/iec/translations/en.json b/custom_components/iec/translations/en.json index 48cbcd9..39f5917 100644 --- a/custom_components/iec/translations/en.json +++ b/custom_components/iec/translations/en.json @@ -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%]", @@ -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%]", diff --git a/custom_components/iec/translations/he.json b/custom_components/iec/translations/he.json index 31b8a35..0c7b18e 100644 --- a/custom_components/iec/translations/he.json +++ b/custom_components/iec/translations/he.json @@ -81,7 +81,10 @@ }, "select_contracts": { "title": "בחירת חשבון חוזה", - "description": "בחרו באיזה חשבון חוזה להשתמש" + "description": "בחרו באיזה חשבון חוזה להשתמש", + "data": { + "no_contracts": "לא נמצאו חשבונות חוזה" + } }, "reauth_confirm": { "title": "[%key:common::config_flow::title::reauth%]", @@ -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%]",