Skip to content

Commit 760f270

Browse files
committed
fix: No Contracts text in Multi Contract Config Flow
1 parent 3a52e42 commit 760f270

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

custom_components/iec/config_flow.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ async def async_step_mfa(
136136
for contract in contracts
137137
if contract.status == 1
138138
]
139-
if len(contract_ids) == 1:
139+
if not contracts:
140+
errors["base"] = "no_contracts"
141+
elif len(contract_ids) == 1:
140142
data[CONF_SELECTED_CONTRACTS] = [contract_ids[0]]
141143
return self._async_create_iec_entry(data)
142144
else:
@@ -181,7 +183,7 @@ async def async_step_select_contracts(
181183
and user_input.get(CONF_SELECTED_CONTRACTS) is not None
182184
):
183185
if len(user_input.get(CONF_SELECTED_CONTRACTS)) == 0:
184-
errors["base"] = "no_contracts"
186+
errors["base"] = "no_selected_contracts"
185187
else:
186188
data = {**self.data, **user_input}
187189
if data.get(CONF_AVAILABLE_CONTRACTS):

custom_components/iec/coordinator.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ async def _verify_daily_readings_exist(
317317
)
318318
if not daily_reading:
319319
_LOGGER.debug(
320-
f'Daily reading for date: {desired_date.strftime("%Y-%m-%d")} is missing, calculating manually'
320+
f"Daily reading for date: {desired_date.strftime('%Y-%m-%d')} is missing, calculating manually"
321321
)
322322
readings = prefetched_reading
323323
if not readings:
@@ -330,7 +330,7 @@ async def _verify_daily_readings_exist(
330330
)
331331
else:
332332
_LOGGER.debug(
333-
f'Daily reading for date: {desired_date.strftime("%Y-%m-%d")} - using existing prefetched readings'
333+
f"Daily reading for date: {desired_date.strftime('%Y-%m-%d')} - using existing prefetched readings"
334334
)
335335

336336
if readings and readings.data:
@@ -353,16 +353,16 @@ async def _verify_daily_readings_exist(
353353
)
354354
if desired_date_reading is None or desired_date_reading.value <= 0:
355355
_LOGGER.debug(
356-
f'Couldn\'t find daily reading for: {desired_date.strftime("%Y-%m-%d")}'
356+
f"Couldn't find daily reading for: {desired_date.strftime('%Y-%m-%d')}"
357357
)
358358
else:
359359
daily_readings[device.device_number].append(
360360
RemoteReading(0, desired_date, desired_date_reading.value)
361361
)
362362
else:
363363
_LOGGER.debug(
364-
f'Daily reading for date: {daily_reading.date.strftime("%Y-%m-%d")}'
365-
f' is present: {daily_reading.value}'
364+
f"Daily reading for date: {daily_reading.date.strftime('%Y-%m-%d')}"
365+
f" is present: {daily_reading.value}"
366366
)
367367

368368
async def _update_data(
@@ -454,7 +454,9 @@ async def _update_data(
454454

455455
devices = await self._get_devices_by_contract_id(contract_id)
456456
if not devices:
457-
_LOGGER.debug(f"No devices for contract {contract_id}. Skipping creating devices.")
457+
_LOGGER.debug(
458+
f"No devices for contract {contract_id}. Skipping creating devices."
459+
)
458460
continue
459461

460462
for device in devices or []:
@@ -705,7 +707,14 @@ async def _insert_statistics(self, contract_id: int, is_smart_meter: bool) -> No
705707

706708
if readings and readings.meter_start_date:
707709
# Fetching the last reading from either the installation date or a month ago
708-
month_ago_time = max(month_ago_time, TIMEZONE.localize(datetime.combine(readings.meter_start_date, datetime.min.time())))
710+
month_ago_time = max(
711+
month_ago_time,
712+
TIMEZONE.localize(
713+
datetime.combine(
714+
readings.meter_start_date, datetime.min.time()
715+
)
716+
),
717+
)
709718
else:
710719
_LOGGER.debug(
711720
"[IEC Statistics] Failed to extract field `meterStartDate`, falling back to a month ago"
@@ -1016,8 +1025,10 @@ def _calculate_estimated_bill(
10161025
future_consumption_info.total_import - last_meter_read
10171026
)
10181027
else:
1019-
_LOGGER.warn(f"Failed to calculate Future Consumption, Assuming last meter read \
1020-
({last_meter_read}) as full consumption")
1028+
_LOGGER.warn(
1029+
f"Failed to calculate Future Consumption, Assuming last meter read \
1030+
({last_meter_read}) as full consumption"
1031+
)
10211032
future_consumption = last_meter_read
10221033

10231034
kva_price = power_size * kva_tariff / 365

custom_components/iec/translations/en.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@
8181
},
8282
"select_contracts": {
8383
"title": "Select Contract",
84-
"description": "Select which contract to use"
84+
"description": "Select which contract to use",
85+
"data": {
86+
"no_contracts": "No Contracts Found"
87+
}
8588
},
8689
"reauth_confirm": {
8790
"title": "[%key:common::config_flow::title::reauth%]",
@@ -95,7 +98,8 @@
9598
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
9699
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
97100
"invalid_id": "Invalid Israeli ID",
98-
"no_contracts": "You should select at least one contract"
101+
"no_selected_contracts": "You should select at least one contract",
102+
"no_contracts": "No Contracts Found"
99103
},
100104
"abort": {
101105
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",

custom_components/iec/translations/he.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@
8181
},
8282
"select_contracts": {
8383
"title": "בחירת חשבון חוזה",
84-
"description": "בחרו באיזה חשבון חוזה להשתמש"
84+
"description": "בחרו באיזה חשבון חוזה להשתמש",
85+
"data": {
86+
"no_contracts": "לא נמצאו חשבונות חוזה"
87+
}
8588
},
8689
"reauth_confirm": {
8790
"title": "[%key:common::config_flow::title::reauth%]",
@@ -95,7 +98,8 @@
9598
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
9699
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
97100
"invalid_id": "תעודת זהות לא תקנית",
98-
"no_contracts": "נא לבחור לפחות חוזה אחד"
101+
"no_selected_contracts": "נא לבחור לפחות חוזה אחד",
102+
"no_contracts": "לא נמצאו חוזים"
99103
},
100104
"abort": {
101105
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",

0 commit comments

Comments
 (0)