Skip to content

Commit

Permalink
Merge pull request #48 from denpaforks/binary_sensor_fix
Browse files Browse the repository at this point in the history
Fix binary sensor issue
  • Loading branch information
jontofront authored Dec 25, 2023
2 parents ef76f65 + 0926101 commit a735ac1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 7 additions & 7 deletions custom_components/econet300/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ 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),
device_class=ENTITY_DEVICE_CLASS_MAP.get(map_key, None),
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


Expand All @@ -94,13 +94,13 @@ 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)
coordinator_data = coordinator.data
_LOGGER.debug("Updated coordinator with its data: %s", 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_descritpion(data_key), coordinator, api
create_binary_entity_description(data_key), coordinator, api
)
entities.append(entity)
_LOGGER.debug("Created and appended entity: %s", entity)
Expand Down
5 changes: 3 additions & 2 deletions custom_components/econet300/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,16 @@ 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)
)
_LOGGER.debug(
"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",
Expand Down

0 comments on commit a735ac1

Please sign in to comment.