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