From f0c4258eb28d01b3719bf7bb1671916027d0386f Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Sun, 23 Jul 2023 08:45:31 +0100 Subject: [PATCH] fix: Removed empty gas meter devices --- custom_components/octopus_energy/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/custom_components/octopus_energy/__init__.py b/custom_components/octopus_energy/__init__.py index f964cc29..49f6d9f2 100644 --- a/custom_components/octopus_energy/__init__.py +++ b/custom_components/octopus_energy/__init__.py @@ -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 @@ -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])