From 5d262708e49402e5203d0b87a073ed992407f6b7 Mon Sep 17 00:00:00 2001 From: jontofront Date: Thu, 14 Nov 2024 20:11:55 +0200 Subject: [PATCH] separates endpoint data --- custom_components/econet300/binary_sensor.py | 2 +- custom_components/econet300/common.py | 2 +- custom_components/econet300/entity.py | 12 +++++++----- custom_components/econet300/number.py | 5 ++++- custom_components/econet300/sensor.py | 8 +++++--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/custom_components/econet300/binary_sensor.py b/custom_components/econet300/binary_sensor.py index 372b2b0..531e138 100644 --- a/custom_components/econet300/binary_sensor.py +++ b/custom_components/econet300/binary_sensor.py @@ -91,7 +91,7 @@ def create_binary_entity_description(key: str) -> EconetBinarySensorEntityDescri def create_binary_sensors(coordinator: EconetDataCoordinator, api: Econet300Api): """Create binary sensors.""" entities: list[EconetBinarySensor] = [] - coordinator_data = coordinator.data + coordinator_data = coordinator.data["sysParams"] for data_key in BINARY_SENSOR_MAP: _LOGGER.debug("Processing data_key: %s", data_key) if data_key in coordinator_data: diff --git a/custom_components/econet300/common.py b/custom_components/econet300/common.py index f347914..d58837f 100644 --- a/custom_components/econet300/common.py +++ b/custom_components/econet300/common.py @@ -46,7 +46,7 @@ async def _async_update_data(self): async with asyncio.timeout(10): data = await self._api.fetch_data() reg_params = await self._api.fetch_reg_params() - return data, reg_params + return {"sysParams": data, "regParams": reg_params} except AuthError as err: raise ConfigEntryAuthFailed from err except ApiError as err: diff --git a/custom_components/econet300/entity.py b/custom_components/econet300/entity.py index a54b55b..7fc9a8b 100644 --- a/custom_components/econet300/entity.py +++ b/custom_components/econet300/entity.py @@ -56,10 +56,10 @@ def _handle_coordinator_update(self) -> None: "Update EconetEntity, entity name: %s", self.entity_description.name ) - if self.coordinator.data[self.entity_description.key] is None: + if self.coordinator.data["sysParams"][self.entity_description.key] is None: return - value = self.coordinator.data[self.entity_description.key] + value = self.coordinator.data["sysParams"][self.entity_description.key] self._sync_state(value) @@ -77,18 +77,20 @@ async def async_added_to_hass(self): if ( not self.coordinator.has_data(self.entity_description.key) - or self.coordinator.data[self.entity_description.key] is None + or self.coordinator.data["sysParams"][self.entity_description.key] is None ): _LOGGER.warning( "Data key: %s was expected to exist but it doesn't", self.entity_description.key, ) - _LOGGER.debug("Coordinator available data: %s", self.coordinator.data) + _LOGGER.debug( + "Coordinator available data: %s", self.coordinator.data["sysParams"] + ) _LOGGER.debug("Exiting async_added_to_hass method") return - value = self.coordinator.data[self.entity_description.key] + value = self.coordinator.data["sysParams"][self.entity_description.key] await super().async_added_to_hass() self._sync_state(value) diff --git a/custom_components/econet300/number.py b/custom_components/econet300/number.py index 27486c0..19dcd0a 100644 --- a/custom_components/econet300/number.py +++ b/custom_components/econet300/number.py @@ -112,7 +112,10 @@ async def async_set_native_value(self, value: float) -> None: def can_add(key: str, coordinator: EconetDataCoordinator): """Check if a given entity can be added based on the availability of data in the coordinator.""" - return coordinator.has_data(key) and coordinator.data[key] + return ( + coordinator.data["sysParams"].has_data(key) + and coordinator.data["sysParams"][key] + ) def apply_limits(desc: EconetNumberEntityDescription, limits: Limits): diff --git a/custom_components/econet300/sensor.py b/custom_components/econet300/sensor.py index faaf3db..d38bd12 100644 --- a/custom_components/econet300/sensor.py +++ b/custom_components/econet300/sensor.py @@ -105,7 +105,7 @@ def create_entity_description(key: str) -> EconetSensorEntityDescription: def create_controller_sensors(coordinator: EconetDataCoordinator, api: Econet300Api): """Create controller sensor entities.""" entities: list[EconetSensor] = [] - coordinator_data = coordinator.data + coordinator_data = coordinator.data["sysParams"] for data_key in SENSOR_MAP: if data_key in coordinator_data: entities.append( @@ -127,9 +127,11 @@ def create_controller_sensors(coordinator: EconetDataCoordinator, api: Econet300 def can_add_mixer(key: str, coordinator: EconetDataCoordinator): """Check if a mixer can be added.""" _LOGGER.debug( - "Checking if mixer can be added for key: %s, data %s", key, coordinator.data + "Checking if mixer can be added for key: %s, data %s", + key, + coordinator.data["sysParams"], ) - return coordinator.has_data(key) and coordinator.data[key] is not None + return coordinator.has_data(key) and coordinator.data["sysParams"][key] is not None def create_mixer_sensor_entity_description(