mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Simplify unique ID handling in Plugwise (#65839)
This commit is contained in:
parent
acb7e24852
commit
a6e36a6eb9
@ -92,6 +92,7 @@ class SmileBinarySensor(PlugwiseEntity, BinarySensorEntity):
|
||||
super().__init__(api, coordinator, name, dev_id)
|
||||
self._binary_sensor = binary_sensor
|
||||
self._attr_is_on = False
|
||||
self._attr_unique_id = f"{dev_id}-{binary_sensor}"
|
||||
|
||||
if dev_id == self._api.heater_id:
|
||||
self._entity_name = "Auxiliary"
|
||||
@ -102,8 +103,6 @@ class SmileBinarySensor(PlugwiseEntity, BinarySensorEntity):
|
||||
if dev_id == self._api.gateway_id:
|
||||
self._entity_name = f"Smile {self._entity_name}"
|
||||
|
||||
self._unique_id = f"{dev_id}-{binary_sensor}"
|
||||
|
||||
@callback
|
||||
def _async_process_data(self) -> None:
|
||||
"""Update the entity."""
|
||||
|
@ -99,6 +99,7 @@ class PwThermostat(PlugwiseEntity, ClimateEntity):
|
||||
"""Set up the Plugwise API."""
|
||||
super().__init__(api, coordinator, name, dev_id)
|
||||
self._attr_extra_state_attributes = {}
|
||||
self._attr_unique_id = f"{dev_id}-climate"
|
||||
|
||||
self._api = api
|
||||
self._loc_id = loc_id
|
||||
@ -106,7 +107,6 @@ class PwThermostat(PlugwiseEntity, ClimateEntity):
|
||||
|
||||
self._presets = None
|
||||
self._single_thermostat = self._api.single_master_thermostat()
|
||||
self._unique_id = f"{dev_id}-climate"
|
||||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
|
@ -22,6 +22,8 @@ from .const import DOMAIN
|
||||
class PlugwiseEntity(CoordinatorEntity):
|
||||
"""Represent a PlugWise Entity."""
|
||||
|
||||
_model: str | None = None
|
||||
|
||||
def __init__(
|
||||
self, api: Smile, coordinator: DataUpdateCoordinator, name: str, dev_id: str
|
||||
) -> None:
|
||||
@ -31,17 +33,8 @@ class PlugwiseEntity(CoordinatorEntity):
|
||||
self._api = api
|
||||
self._name = name
|
||||
self._dev_id = dev_id
|
||||
|
||||
self._unique_id: str | None = None
|
||||
self._model: str | None = None
|
||||
|
||||
self._entity_name = self._name
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str | None:
|
||||
"""Return a unique ID."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> str | None:
|
||||
"""Return the name of the entity, if any."""
|
||||
|
@ -313,7 +313,9 @@ class SmileSensor(PlugwiseEntity, SensorEntity):
|
||||
) -> None:
|
||||
"""Initialise the sensor."""
|
||||
super().__init__(api, coordinator, name, dev_id)
|
||||
self._attr_unique_id = f"{dev_id}-{sensor}"
|
||||
self._sensor = sensor
|
||||
|
||||
if dev_id == self._api.heater_id:
|
||||
self._entity_name = "Auxiliary"
|
||||
|
||||
@ -323,8 +325,6 @@ class SmileSensor(PlugwiseEntity, SensorEntity):
|
||||
if dev_id == self._api.gateway_id:
|
||||
self._entity_name = f"Smile {self._entity_name}"
|
||||
|
||||
self._unique_id = f"{dev_id}-{sensor}"
|
||||
|
||||
|
||||
class PwThermostatSensor(SmileSensor):
|
||||
"""Thermostat (or generic) sensor devices."""
|
||||
|
@ -62,6 +62,7 @@ class GwSwitch(PlugwiseEntity, SwitchEntity):
|
||||
def __init__(self, api, coordinator, name, dev_id, members, model):
|
||||
"""Set up the Plugwise API."""
|
||||
super().__init__(api, coordinator, name, dev_id)
|
||||
self._attr_unique_id = f"{dev_id}-plug"
|
||||
|
||||
self._members = members
|
||||
self._model = model
|
||||
@ -69,8 +70,6 @@ class GwSwitch(PlugwiseEntity, SwitchEntity):
|
||||
self._is_on = False
|
||||
self._icon = SWITCH_ICON
|
||||
|
||||
self._unique_id = f"{dev_id}-plug"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if device is on."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user