Skip to content

Commit

Permalink
reverse data lookup
Browse files Browse the repository at this point in the history
Performance-wise, it makes much more sense to iterate through shorter sensor mapping instead of whole coordinator data.
  • Loading branch information
denpamusic committed Dec 24, 2023
1 parent 8e4058c commit 0926101
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions custom_components/econet300/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
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 0926101

Please sign in to comment.