From 87a697665ce74d3393a16201b97e4e2b164af403 Mon Sep 17 00:00:00 2001 From: denpamusic Date: Sun, 24 Dec 2023 03:11:37 +0300 Subject: [PATCH 1/3] fix binary sensor issue --- custom_components/econet300/binary_sensor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/econet300/binary_sensor.py b/custom_components/econet300/binary_sensor.py index 72f54b8..5f34803 100644 --- a/custom_components/econet300/binary_sensor.py +++ b/custom_components/econet300/binary_sensor.py @@ -94,9 +94,9 @@ def create_binary_sensors(coordinator: EconetDataCoordinator, api: Econet300Api) _LOGGER.debug("api: %s", api) entities: list[EconetBinarySensor] = [] _LOGGER.debug("Initialized entities list: %s", entities) - coordinator = coordinator.data - _LOGGER.debug("Updated coordinator with its data: %s", coordinator) - for data_key in BINARY_SENSOR_MAP: + coordinator_data = coordinator.data + _LOGGER.debug("Updated coordinator with its data: %s", coordinator_data) + for data_key in coordinator_data: _LOGGER.debug("Processing data_key: %s", data_key) if data_key in BINARY_SENSOR_MAP: entity = EconetBinarySensor( From 8e4058c46647ba76fa4ec70c496308b02d6d842b Mon Sep 17 00:00:00 2001 From: denpamusic Date: Sun, 24 Dec 2023 03:20:18 +0300 Subject: [PATCH 2/3] fix typo --- custom_components/econet300/binary_sensor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/econet300/binary_sensor.py b/custom_components/econet300/binary_sensor.py index 5f34803..9ef6135 100644 --- a/custom_components/econet300/binary_sensor.py +++ b/custom_components/econet300/binary_sensor.py @@ -73,10 +73,10 @@ def icon(self) -> str | None: ) -def create_binary_entity_descritpion(key: str) -> EconetBinarySensorEntityDescription: +def create_binary_entity_description(key: str) -> EconetBinarySensorEntityDescription: """Create Econet300 binary entity description""" map_key = BINARY_SENSOR_MAP.get(key, key) - _LOGGER.debug("create_binary_entity_descritpion: %s", map_key) + _LOGGER.debug("create_binary_entity_description: %s", map_key) entity_description = EconetBinarySensorEntityDescription( key=key, translation_key=camel_to_snake(map_key), @@ -84,7 +84,7 @@ def create_binary_entity_descritpion(key: str) -> EconetBinarySensorEntityDescri icon=ENTITY_ICON.get(map_key, None), icon_off=ENTITY_ICON_OFF.get(map_key, None), ) - _LOGGER.debug("create_binary_entity_descritpion: %s", entity_description) + _LOGGER.debug("create_binary_entity_description: %s", entity_description) return entity_description @@ -100,7 +100,7 @@ def create_binary_sensors(coordinator: EconetDataCoordinator, api: Econet300Api) _LOGGER.debug("Processing data_key: %s", data_key) if data_key in BINARY_SENSOR_MAP: entity = EconetBinarySensor( - create_binary_entity_descritpion(data_key), coordinator, api + create_binary_entity_description(data_key), coordinator, api ) entities.append(entity) _LOGGER.debug("Created and appended entity: %s", entity) From 0926101beceafa4bc42b83207ff8c9e9d51f0e27 Mon Sep 17 00:00:00 2001 From: denpamusic Date: Sun, 24 Dec 2023 06:44:36 +0300 Subject: [PATCH 3/3] reverse data lookup Performance-wise, it makes much more sense to iterate through shorter sensor mapping instead of whole coordinator data. --- custom_components/econet300/binary_sensor.py | 4 ++-- custom_components/econet300/sensor.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/custom_components/econet300/binary_sensor.py b/custom_components/econet300/binary_sensor.py index 9ef6135..bdebc4a 100644 --- a/custom_components/econet300/binary_sensor.py +++ b/custom_components/econet300/binary_sensor.py @@ -96,9 +96,9 @@ def create_binary_sensors(coordinator: EconetDataCoordinator, api: Econet300Api) _LOGGER.debug("Initialized entities list: %s", entities) coordinator_data = coordinator.data _LOGGER.debug("Updated coordinator with its data: %s", coordinator_data) - for data_key in coordinator_data: + for data_key in BINARY_SENSOR_MAP: _LOGGER.debug("Processing data_key: %s", data_key) - if data_key in BINARY_SENSOR_MAP: + if data_key in coordinator_data: entity = EconetBinarySensor( create_binary_entity_description(data_key), coordinator, api ) diff --git a/custom_components/econet300/sensor.py b/custom_components/econet300/sensor.py index 7cf2310..c6bdb52 100644 --- a/custom_components/econet300/sensor.py +++ b/custom_components/econet300/sensor.py @@ -93,8 +93,8 @@ def create_controller_sensors(coordinator: EconetDataCoordinator, api: Econet300 """Creating controller sensor entities""" entities: list[EconetSensor] = [] coordinator_data = coordinator.data - for data_key in coordinator_data: - if data_key in SENSOR_MAP: + for data_key in SENSOR_MAP: + if data_key in coordinator_data: entities.append( EconetSensor(create_entity_description(data_key), coordinator, api) ) @@ -102,6 +102,7 @@ def create_controller_sensors(coordinator: EconetDataCoordinator, api: Econet300 "Key: %s mapped, sensor entity will be added", data_key, ) + continue else: _LOGGER.debug( "Key: %s is not mapped, sensor entity will not be added",