diff --git a/homeassistant/components/template/alarm_control_panel.py b/homeassistant/components/template/alarm_control_panel.py index b136364253e..ca037f23bc4 100644 --- a/homeassistant/components/template/alarm_control_panel.py +++ b/homeassistant/components/template/alarm_control_panel.py @@ -138,7 +138,9 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity): unique_id, ): """Initialize the panel.""" - super().__init__(hass, config=config, fallback_name=object_id) + super().__init__( + hass, config=config, fallback_name=object_id, unique_id=unique_id + ) self.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, object_id, hass=hass ) @@ -160,12 +162,6 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity): self._arm_night_script = Script(hass, arm_night_action, name, DOMAIN) self._state = None - self._unique_id = unique_id - - @property - def unique_id(self): - """Return the unique id of this alarm control panel.""" - return self._unique_id @property def state(self): diff --git a/homeassistant/components/template/binary_sensor.py b/homeassistant/components/template/binary_sensor.py index bea5acfc740..d2578468886 100644 --- a/homeassistant/components/template/binary_sensor.py +++ b/homeassistant/components/template/binary_sensor.py @@ -196,7 +196,7 @@ class BinarySensorTemplate(TemplateEntity, BinarySensorEntity): unique_id: str | None, ) -> None: """Initialize the Template binary sensor.""" - super().__init__(hass, config=config) + super().__init__(hass, config=config, unique_id=unique_id) if (object_id := config.get(CONF_OBJECT_ID)) is not None: self.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, object_id, hass=hass @@ -210,7 +210,6 @@ class BinarySensorTemplate(TemplateEntity, BinarySensorEntity): self._delay_on_raw = config.get(CONF_DELAY_ON) self._delay_off = None self._delay_off_raw = config.get(CONF_DELAY_OFF) - self._unique_id = unique_id async def async_added_to_hass(self): """Register callbacks.""" @@ -270,11 +269,6 @@ class BinarySensorTemplate(TemplateEntity, BinarySensorEntity): # state with delay. Cancelled if template result changes. self._delay_cancel = async_call_later(self.hass, delay, _set_state) - @property - def unique_id(self): - """Return the unique id of this binary sensor.""" - return self._unique_id - @property def is_on(self): """Return true if sensor is on.""" diff --git a/homeassistant/components/template/button.py b/homeassistant/components/template/button.py index 1e2fcc8cc8b..86f481d7032 100644 --- a/homeassistant/components/template/button.py +++ b/homeassistant/components/template/button.py @@ -85,10 +85,9 @@ class TemplateButtonEntity(TemplateEntity, ButtonEntity): unique_id: str | None, ) -> None: """Initialize the button.""" - super().__init__(hass, config=config) + super().__init__(hass, config=config, unique_id=unique_id) self._command_press = Script(hass, config[CONF_PRESS], self._attr_name, DOMAIN) self._attr_device_class = config.get(CONF_DEVICE_CLASS) - self._attr_unique_id = unique_id self._attr_state = None async def async_press(self) -> None: diff --git a/homeassistant/components/template/cover.py b/homeassistant/components/template/cover.py index f688069dc8f..6c1bad3124e 100644 --- a/homeassistant/components/template/cover.py +++ b/homeassistant/components/template/cover.py @@ -148,7 +148,9 @@ class CoverTemplate(TemplateEntity, CoverEntity): unique_id, ): """Initialize the Template cover.""" - super().__init__(hass, config=config, fallback_name=object_id) + super().__init__( + hass, config=config, fallback_name=object_id, unique_id=unique_id + ) self.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, object_id, hass=hass ) @@ -182,7 +184,6 @@ class CoverTemplate(TemplateEntity, CoverEntity): self._is_opening = False self._is_closing = False self._tilt_value = None - self._unique_id = unique_id async def async_added_to_hass(self): """Register callbacks.""" @@ -271,11 +272,6 @@ class CoverTemplate(TemplateEntity, CoverEntity): else: self._tilt_value = state - @property - def unique_id(self): - """Return the unique id of this cover.""" - return self._unique_id - @property def is_closed(self): """Return if the cover is closed.""" diff --git a/homeassistant/components/template/fan.py b/homeassistant/components/template/fan.py index e1c786f56c0..9d0a32f3edd 100644 --- a/homeassistant/components/template/fan.py +++ b/homeassistant/components/template/fan.py @@ -138,7 +138,9 @@ class TemplateFan(TemplateEntity, FanEntity): unique_id, ): """Initialize the fan.""" - super().__init__(hass, config=config, fallback_name=object_id) + super().__init__( + hass, config=config, fallback_name=object_id, unique_id=unique_id + ) self.hass = hass self.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, object_id, hass=hass @@ -206,13 +208,6 @@ class TemplateFan(TemplateEntity, FanEntity): if self._direction_template: self._supported_features |= SUPPORT_DIRECTION - self._unique_id = unique_id - - @property - def unique_id(self): - """Return the unique id of this fan.""" - return self._unique_id - @property def supported_features(self) -> int: """Flag supported features.""" diff --git a/homeassistant/components/template/light.py b/homeassistant/components/template/light.py index 0395925e28e..d2260aa10dc 100644 --- a/homeassistant/components/template/light.py +++ b/homeassistant/components/template/light.py @@ -140,7 +140,9 @@ class LightTemplate(TemplateEntity, LightEntity): unique_id, ): """Initialize the light.""" - super().__init__(hass, config=config, fallback_name=object_id) + super().__init__( + hass, config=config, fallback_name=object_id, unique_id=unique_id + ) self.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, object_id, hass=hass ) @@ -187,7 +189,6 @@ class LightTemplate(TemplateEntity, LightEntity): self._max_mireds = None self._min_mireds = None self._supports_transition = False - self._unique_id = unique_id @property def brightness(self): @@ -235,11 +236,6 @@ class LightTemplate(TemplateEntity, LightEntity): """Return the effect list.""" return self._effect_list - @property - def unique_id(self): - """Return the unique id of this light.""" - return self._unique_id - @property def supported_features(self): """Flag supported features.""" diff --git a/homeassistant/components/template/lock.py b/homeassistant/components/template/lock.py index 1835d768a01..78141c0d25e 100644 --- a/homeassistant/components/template/lock.py +++ b/homeassistant/components/template/lock.py @@ -77,25 +77,21 @@ class TemplateLock(TemplateEntity, LockEntity): unique_id, ): """Initialize the lock.""" - super().__init__(hass, config=config, fallback_name=DEFAULT_NAME) + super().__init__( + hass, config=config, fallback_name=DEFAULT_NAME, unique_id=unique_id + ) self._state = None name = self._attr_name self._state_template = config.get(CONF_VALUE_TEMPLATE) self._command_lock = Script(hass, config[CONF_LOCK], name, DOMAIN) self._command_unlock = Script(hass, config[CONF_UNLOCK], name, DOMAIN) self._optimistic = config.get(CONF_OPTIMISTIC) - self._unique_id = unique_id @property def assumed_state(self): """Return true if we do optimistic updates.""" return self._optimistic - @property - def unique_id(self): - """Return the unique id of this lock.""" - return self._unique_id - @property def is_locked(self): """Return true if lock is locked.""" diff --git a/homeassistant/components/template/number.py b/homeassistant/components/template/number.py index a0b3f0340fa..036485cd363 100644 --- a/homeassistant/components/template/number.py +++ b/homeassistant/components/template/number.py @@ -107,7 +107,7 @@ class TemplateNumber(TemplateEntity, NumberEntity): unique_id: str | None, ) -> None: """Initialize the number.""" - super().__init__(hass, config=config) + super().__init__(hass, config=config, unique_id=unique_id) self._value_template = config[CONF_STATE] self._command_set_value = Script( hass, config[CONF_SET_VALUE], self._attr_name, DOMAIN @@ -116,7 +116,6 @@ class TemplateNumber(TemplateEntity, NumberEntity): self._min_value_template = config[ATTR_MIN] self._max_value_template = config[ATTR_MAX] self._attr_assumed_state = self._optimistic = config[CONF_OPTIMISTIC] - self._attr_unique_id = unique_id self._attr_value = None self._attr_step = None self._attr_min_value = None diff --git a/homeassistant/components/template/select.py b/homeassistant/components/template/select.py index 7fec0a8d388..28295835318 100644 --- a/homeassistant/components/template/select.py +++ b/homeassistant/components/template/select.py @@ -101,14 +101,13 @@ class TemplateSelect(TemplateEntity, SelectEntity): unique_id: str | None, ) -> None: """Initialize the select.""" - super().__init__(hass, config=config) + super().__init__(hass, config=config, unique_id=unique_id) self._value_template = config[CONF_STATE] self._command_select_option = Script( hass, config[CONF_SELECT_OPTION], self._attr_name, DOMAIN ) self._options_template = config[ATTR_OPTIONS] self._attr_assumed_state = self._optimistic = config[CONF_OPTIMISTIC] - self._attr_unique_id = unique_id self._attr_options = None self._attr_current_option = None diff --git a/homeassistant/components/template/sensor.py b/homeassistant/components/template/sensor.py index 7974d6d457c..c1fae1f4f3b 100644 --- a/homeassistant/components/template/sensor.py +++ b/homeassistant/components/template/sensor.py @@ -199,7 +199,7 @@ class SensorTemplate(TemplateEntity, SensorEntity): unique_id: str | None, ) -> None: """Initialize the sensor.""" - super().__init__(hass, config=config) + super().__init__(hass, config=config, unique_id=unique_id) if (object_id := config.get(CONF_OBJECT_ID)) is not None: self.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, object_id, hass=hass @@ -209,7 +209,6 @@ class SensorTemplate(TemplateEntity, SensorEntity): self._template = config.get(CONF_STATE) self._attr_device_class = config.get(CONF_DEVICE_CLASS) self._attr_state_class = config.get(CONF_STATE_CLASS) - self._attr_unique_id = unique_id async def async_added_to_hass(self): """Register callbacks.""" diff --git a/homeassistant/components/template/switch.py b/homeassistant/components/template/switch.py index 32e184b451a..8a3955db007 100644 --- a/homeassistant/components/template/switch.py +++ b/homeassistant/components/template/switch.py @@ -98,7 +98,9 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity): unique_id, ): """Initialize the Template switch.""" - super().__init__(hass, config=config, fallback_name=object_id) + super().__init__( + hass, config=config, fallback_name=object_id, unique_id=unique_id + ) self.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, object_id, hass=hass ) @@ -107,7 +109,6 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity): self._on_script = Script(hass, config[ON_ACTION], friendly_name, DOMAIN) self._off_script = Script(hass, config[OFF_ACTION], friendly_name, DOMAIN) self._state = False - self._unique_id = unique_id @callback def _update_state(self, result): @@ -143,11 +144,6 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity): await super().async_added_to_hass() - @property - def unique_id(self): - """Return the unique id of this switch.""" - return self._unique_id - @property def is_on(self): """Return true if device is on.""" diff --git a/homeassistant/components/template/template_entity.py b/homeassistant/components/template/template_entity.py index 768d662b4ea..ee4b6244757 100644 --- a/homeassistant/components/template/template_entity.py +++ b/homeassistant/components/template/template_entity.py @@ -222,12 +222,14 @@ class TemplateEntity(Entity): attribute_templates=None, config=None, fallback_name=None, + unique_id=None, ): """Template Entity.""" self._template_attrs = {} self._async_update = None self._attr_extra_state_attributes = {} self._self_ref_update_count = 0 + self._attr_unique_id = unique_id if config is None: self._attribute_templates = attribute_templates self._availability_template = availability_template diff --git a/homeassistant/components/template/vacuum.py b/homeassistant/components/template/vacuum.py index b12dfbcf04d..f76c64f739a 100644 --- a/homeassistant/components/template/vacuum.py +++ b/homeassistant/components/template/vacuum.py @@ -142,7 +142,9 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity): unique_id, ): """Initialize the vacuum.""" - super().__init__(hass, config=config, fallback_name=object_id) + super().__init__( + hass, config=config, fallback_name=object_id, unique_id=unique_id + ) self.entity_id = async_generate_entity_id( ENTITY_ID_FORMAT, object_id, hass=hass ) @@ -200,16 +202,9 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity): if self._battery_level_template: self._supported_features |= SUPPORT_BATTERY - self._unique_id = unique_id - # List of valid fan speeds self._fan_speed_list = config[CONF_FAN_SPEED_LIST] - @property - def unique_id(self): - """Return the unique id of this vacuum.""" - return self._unique_id - @property def supported_features(self) -> int: """Flag supported features.""" diff --git a/homeassistant/components/template/weather.py b/homeassistant/components/template/weather.py index 93b81b5fb97..d4069096553 100644 --- a/homeassistant/components/template/weather.py +++ b/homeassistant/components/template/weather.py @@ -112,7 +112,7 @@ class WeatherTemplate(TemplateEntity, WeatherEntity): unique_id, ): """Initialize the Template weather.""" - super().__init__(hass, config=config) + super().__init__(hass, config=config, unique_id=unique_id) name = self._attr_name self._condition_template = config[CONF_CONDITION_TEMPLATE] @@ -125,7 +125,6 @@ class WeatherTemplate(TemplateEntity, WeatherEntity): self._ozone_template = config.get(CONF_OZONE_TEMPLATE) self._visibility_template = config.get(CONF_VISIBILITY_TEMPLATE) self._forecast_template = config.get(CONF_FORECAST_TEMPLATE) - self._unique_id = unique_id self.entity_id = async_generate_entity_id(ENTITY_ID_FORMAT, name, hass=hass) @@ -197,11 +196,6 @@ class WeatherTemplate(TemplateEntity, WeatherEntity): return "Powered by Home Assistant" return self._attribution - @property - def unique_id(self): - """Return the unique id of this weather instance.""" - return self._unique_id - async def async_added_to_hass(self): """Register callbacks."""