Skip to content

Commit

Permalink
fix: Removed empty gas meter devices
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Jul 23, 2023
1 parent 080d2cc commit f0c4258
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions custom_components/octopus_energy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import timedelta

from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr

from .coordinators.account import async_setup_account_info_coordinator
from .coordinators.intelligent_dispatches import async_setup_intelligent_dispatches_coordinator
Expand Down Expand Up @@ -103,6 +104,17 @@ async def async_setup_dependencies(hass, config):

hass.data[DOMAIN][DATA_ACCOUNT] = account_info

# Remove gas meter devices which had incorrect identifier
if account_info is not None and len(account_info["gas_meter_points"]) > 0:
device_registry = dr.async_get(hass)
for point in account_info["gas_meter_points"]:
mprn = point["mprn"]
for meter in point["meters"]:
serial_number = meter["serial_number"]
device = device_registry.async_get_device(identifiers={(DOMAIN, f"electricity_{serial_number}_{mprn}")})
if device is not None:
device_registry.async_remove_device(device.id)

await async_setup_account_info_coordinator(hass, config[CONFIG_MAIN_ACCOUNT_ID])

await async_setup_intelligent_dispatches_coordinator(hass, config[CONFIG_MAIN_ACCOUNT_ID])
Expand Down

0 comments on commit f0c4258

Please sign in to comment.