Skip to content

Commit

Permalink
fix: Fixed issue with gas tariff comparison not persisting configured…
Browse files Browse the repository at this point in the history
… calorific value (1 hour dev time)
  • Loading branch information
BottlecapDave committed Dec 15, 2024
1 parent 4589a6a commit b16cd1d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
25 changes: 24 additions & 1 deletion custom_components/octopus_energy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ async def async_close_connection(_) -> None:
# the correct references (e.g. rate coordinators)
child_entries = hass.config_entries.async_entries(DOMAIN)
for child_entry in child_entries:
if child_entry.data[CONFIG_KIND] != CONFIG_KIND_ACCOUNT and child_entry.data[CONFIG_ACCOUNT_ID] == account_id:
child_entry_config = dict(child_entry.data)

if child_entry.options:
child_entry_config.update(child_entry.options)

if child_entry_config[CONFIG_KIND] != CONFIG_KIND_ACCOUNT and child_entry_config[CONFIG_ACCOUNT_ID] == account_id:
await hass.config_entries.async_reload(child_entry.entry_id)

elif config[CONFIG_KIND] == CONFIG_KIND_TARGET_RATE:
Expand Down Expand Up @@ -446,6 +451,21 @@ async def options_update_listener(hass, entry):
"""Handle options update."""
await hass.config_entries.async_reload(entry.entry_id)

if entry.data[CONFIG_KIND] == CONFIG_KIND_ACCOUNT:
account_id = entry.data[CONFIG_ACCOUNT_ID]

# If the main account has been reloaded, then reload all other entries to make sure they're referencing
# the correct references (e.g. rate coordinators)
child_entries = hass.config_entries.async_entries(DOMAIN)
for child_entry in child_entries:
child_entry_config = dict(child_entry.data)

if child_entry.options:
child_entry_config.update(child_entry.options)

if child_entry_config[CONFIG_KIND] != CONFIG_KIND_ACCOUNT and child_entry_config[CONFIG_ACCOUNT_ID] == account_id:
await hass.config_entries.async_reload(child_entry.entry_id)

async def async_unload_entry(hass, entry):
"""Unload a config entry."""

Expand All @@ -457,6 +477,9 @@ async def async_unload_entry(hass, entry):
await _async_close_client(hass, account_id)
hass.data[DOMAIN].pop(account_id)

elif entry.data[CONFIG_KIND] == CONFIG_KIND_TARIFF_COMPARISON:
unload_ok = await hass.config_entries.async_unload_platforms(entry, TARIFF_COMPARISON_PLATFORMS)

elif entry.data[CONFIG_KIND] == CONFIG_KIND_TARGET_RATE or entry.data[CONFIG_KIND] == CONFIG_KIND_ROLLING_TARGET_RATE:
unload_ok = await hass.config_entries.async_unload_platforms(entry, TARGET_RATE_PLATFORMS)

Expand Down
9 changes: 7 additions & 2 deletions custom_components/octopus_energy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,13 @@ async def async_setup_tariff_comparison_sensors(hass: HomeAssistant, entry, conf
calorific_value = DEFAULT_CALORIFIC_VALUE
config_entries = hass.config_entries.async_entries(DOMAIN)
for entry in config_entries:
if entry.data[CONFIG_KIND] == CONFIG_KIND_ACCOUNT and entry.data[CONFIG_ACCOUNT_ID] == account_id and CONFIG_MAIN_CALORIFIC_VALUE in config:
calorific_value = config[CONFIG_MAIN_CALORIFIC_VALUE]
config_entry_data = dict(entry.data)

if entry.options:
config_entry_data.update(entry.options)

if config_entry_data[CONFIG_KIND] == CONFIG_KIND_ACCOUNT and config_entry_data[CONFIG_ACCOUNT_ID] == account_id and CONFIG_MAIN_CALORIFIC_VALUE in config_entry_data:
calorific_value = config_entry_data[CONFIG_MAIN_CALORIFIC_VALUE]

now = utcnow()
for point in account_info["electricity_meter_points"]:
Expand Down

0 comments on commit b16cd1d

Please sign in to comment.