Skip to content

Commit

Permalink
separates endpoint data
Browse files Browse the repository at this point in the history
  • Loading branch information
jontofront committed Nov 14, 2024
1 parent 97cb63b commit 5d26270
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion custom_components/econet300/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/econet300/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions custom_components/econet300/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion custom_components/econet300/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions custom_components/econet300/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 5d26270

Please sign in to comment.