Skip to content

Commit

Permalink
refactor: consolidate entity gathering logic into a dedicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
jontofront committed Dec 20, 2024
1 parent 8bf2d78 commit 0e0a5ab
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions custom_components/econet300/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,20 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> bool:
"""Set up the sensor platform."""

def async_gather_entities(
coordinator: EconetDataCoordinator, api: Econet300Api
) -> list[EconetSensor]:
"""Collect all sensor entities."""
entities = []
entities.extend(create_controller_sensors(coordinator, api))
entities.extend(create_mixer_sensors(coordinator, api))
entities.extend(create_lambda_sensors(coordinator, api))
return entities

coordinator = hass.data[DOMAIN][entry.entry_id][SERVICE_COORDINATOR]
api = hass.data[DOMAIN][entry.entry_id][SERVICE_API]

entities: list[EconetSensor] = []
entities.extend(create_controller_sensors(coordinator, api))
entities.extend(create_mixer_sensors(coordinator, api))
entities.extend(create_lambda_sensors(coordinator, api))

entities = async_gather_entities(coordinator, api)
async_add_entities(entities)
return True

0 comments on commit 0e0a5ab

Please sign in to comment.