Skip to content

Commit

Permalink
Keep same unique id and identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmeu committed Sep 18, 2024
1 parent 98a977a commit 12b547e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/aseko_pool_live/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
aseko = Aseko(entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD])

try:
user = await aseko.login()
await aseko.login()
except AsekoNotLoggedIn as err:
raise ConfigEntryAuthFailed from err

coordinator = AsekoDataUpdateCoordinator(hass, aseko)
await coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (user.user_id, coordinator)
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True

Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/aseko_pool_live/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AsekoBinarySensorEntityDescription(BinarySensorEntityDescription):

BINARY_SENSORS: tuple[AsekoBinarySensorEntityDescription, ...] = (
AsekoBinarySensorEntityDescription(
key="water_flow_to_probes",
key="water_flow",
translation_key="water_flow_to_probes",
value_fn=lambda unit: unit.water_flow_to_probes,
),
Expand All @@ -47,13 +47,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Aseko Pool Live binary sensors."""
data: tuple[str, AsekoDataUpdateCoordinator] = hass.data[DOMAIN][
config_entry.entry_id
]
user_id, coordinator = data
coordinator: AsekoDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
units = coordinator.data.values()
async_add_entities(
AsekoBinarySensorEntity(unit, user_id, coordinator, description)
AsekoBinarySensorEntity(unit, coordinator, description)
for description in BINARY_SENSORS
for unit in units
if description.value_fn(unit) is not None
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/aseko_pool_live/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AsekoEntity(CoordinatorEntity[AsekoDataUpdateCoordinator]):
def __init__(
self,
unit: Unit,
user_id: str,
coordinator: AsekoDataUpdateCoordinator,
description: EntityDescription,
) -> None:
Expand All @@ -27,10 +26,10 @@ def __init__(
self.entity_description = description
self._unit = unit
self._attr_unique_id = (
f"{user_id}_{self.unit.serial_number}_{self.entity_description.key}"
f"{self.unit.serial_number}_{self.entity_description.key}"
)
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{user_id}_{self.unit.serial_number}")},
identifiers={(DOMAIN, self.unit.serial_number)},
serial_number=self.unit.serial_number,
name=unit.name or unit.serial_number,
manufacturer=(
Expand Down
17 changes: 7 additions & 10 deletions homeassistant/components/aseko_pool_live/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class AsekoSensorEntityDescription(SensorEntityDescription):

SENSORS: list[AsekoSensorEntityDescription] = [
AsekoSensorEntityDescription(
key="air_temperature",
key="airTemp",
translation_key="air_temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda unit: unit.air_temperature,
),
AsekoSensorEntityDescription(
key="cl_free",
key="free_chlorine",
translation_key="cl_free",
native_unit_of_measurement="mg/l",
state_class=SensorStateClass.MEASUREMENT,
Expand All @@ -54,7 +54,7 @@ class AsekoSensorEntityDescription(SensorEntityDescription):
value_fn=lambda unit: unit.ph,
),
AsekoSensorEntityDescription(
key="redox",
key="rx",
translation_key="redox",
native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
state_class=SensorStateClass.MEASUREMENT,
Expand All @@ -68,7 +68,7 @@ class AsekoSensorEntityDescription(SensorEntityDescription):
value_fn=lambda unit: unit.salinity,
),
AsekoSensorEntityDescription(
key="water_temperature",
key="waterTemp",
translation_key="water_temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
Expand All @@ -84,16 +84,13 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Aseko Pool Live sensors."""
data: tuple[str, AsekoDataUpdateCoordinator] = hass.data[DOMAIN][
config_entry.entry_id
]
user_id, coordinator = data
coordinator: AsekoDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
units = coordinator.data.values()
async_add_entities(
AsekoSensorEntity(unit, user_id, coordinator, description)
AsekoSensorEntity(unit, coordinator, description)
for description in SENSORS
for unit in units
if getattr(unit, description.key) is not None
if description.value_fn(unit) is not None
)


Expand Down

0 comments on commit 12b547e

Please sign in to comment.