diff --git a/homeassistant/components/template/binary_sensor.py b/homeassistant/components/template/binary_sensor.py index ab7c88e8b8c..bad4a7d7059 100644 --- a/homeassistant/components/template/binary_sensor.py +++ b/homeassistant/components/template/binary_sensor.py @@ -14,6 +14,7 @@ from homeassistant.components.binary_sensor import ( DOMAIN as BINARY_SENSOR_DOMAIN, ENTITY_ID_FORMAT, PLATFORM_SCHEMA, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.const import ( @@ -208,16 +209,18 @@ class BinarySensorTemplate(TemplateEntity, BinarySensorEntity, RestoreEntity): ENTITY_ID_FORMAT, object_id, hass=hass ) - self._device_class = config.get(CONF_DEVICE_CLASS) + self._device_class: BinarySensorDeviceClass | None = config.get( + CONF_DEVICE_CLASS + ) self._template = config[CONF_STATE] - self._state = None + self._state: bool | None = None self._delay_cancel = None self._delay_on = None self._delay_on_raw = config.get(CONF_DELAY_ON) self._delay_off = None self._delay_off_raw = config.get(CONF_DELAY_OFF) - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Restore state and register callbacks.""" if ( (self._delay_on_raw is not None or self._delay_off_raw is not None) @@ -283,12 +286,12 @@ class BinarySensorTemplate(TemplateEntity, BinarySensorEntity, RestoreEntity): self._delay_cancel = async_call_later(self.hass, delay, _set_state) @property - def is_on(self): + def is_on(self) -> bool | None: """Return true if sensor is on.""" return self._state @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | None: """Return the sensor class of the binary sensor.""" return self._device_class diff --git a/homeassistant/components/template/light.py b/homeassistant/components/template/light.py index 807e3e79ef8..f4ad971c1d6 100644 --- a/homeassistant/components/template/light.py +++ b/homeassistant/components/template/light.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +from typing import Any import voluptuous as vol @@ -197,17 +198,17 @@ class LightTemplate(TemplateEntity, LightEntity): self._supports_transition = False @property - def brightness(self): + def brightness(self) -> int | None: """Return the brightness of the light.""" return self._brightness @property - def color_temp(self): + def color_temp(self) -> int | None: """Return the CT color value in mireds.""" return self._temperature @property - def max_mireds(self): + def max_mireds(self) -> int: """Return the max mireds value in mireds.""" if self._max_mireds is not None: return self._max_mireds @@ -215,7 +216,7 @@ class LightTemplate(TemplateEntity, LightEntity): return super().max_mireds @property - def min_mireds(self): + def min_mireds(self) -> int: """Return the min mireds value in mireds.""" if self._min_mireds is not None: return self._min_mireds @@ -223,27 +224,27 @@ class LightTemplate(TemplateEntity, LightEntity): return super().min_mireds @property - def white_value(self): + def white_value(self) -> int | None: """Return the white value.""" return self._white_value @property - def hs_color(self): + def hs_color(self) -> tuple[float, float] | None: """Return the hue and saturation color value [float, float].""" return self._color @property - def effect(self): + def effect(self) -> str | None: """Return the effect.""" return self._effect @property - def effect_list(self): + def effect_list(self) -> list[str] | None: """Return the effect list.""" return self._effect_list @property - def supported_features(self): + def supported_features(self) -> int: """Flag supported features.""" supported_features = 0 if self._level_script is not None: @@ -261,11 +262,11 @@ class LightTemplate(TemplateEntity, LightEntity): return supported_features @property - def is_on(self): + def is_on(self) -> bool | None: """Return true if device is on.""" return self._state - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" if self._template: self.add_template_attribute( @@ -345,7 +346,7 @@ class LightTemplate(TemplateEntity, LightEntity): ) await super().async_added_to_hass() - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn the light on.""" optimistic_set = False # set optimistic states @@ -448,7 +449,7 @@ class LightTemplate(TemplateEntity, LightEntity): if optimistic_set: self.async_write_ha_state() - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Turn the light off.""" if ATTR_TRANSITION in kwargs and self._supports_transition is True: await self.async_run_script( diff --git a/homeassistant/components/template/sensor.py b/homeassistant/components/template/sensor.py index ee1ddfa8c2d..8dcda988e9f 100644 --- a/homeassistant/components/template/sensor.py +++ b/homeassistant/components/template/sensor.py @@ -211,7 +211,7 @@ class SensorTemplate(TemplateSensor): ENTITY_ID_FORMAT, object_id, hass=hass ) - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.add_template_attribute( "_attr_native_value", self._template, None, self._update_state diff --git a/homeassistant/components/template/switch.py b/homeassistant/components/template/switch.py index f04f2b5ba7a..9f282cb9b11 100644 --- a/homeassistant/components/template/switch.py +++ b/homeassistant/components/template/switch.py @@ -1,6 +1,8 @@ """Support for switches which integrates with other components.""" from __future__ import annotations +from typing import Any + import voluptuous as vol from homeassistant.components.switch import ( @@ -110,7 +112,7 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity): self._template = config.get(CONF_VALUE_TEMPLATE) 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._state: bool | None = False @callback def _update_state(self, result): @@ -129,7 +131,7 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity): self._state = False - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" if self._template is None: @@ -147,18 +149,18 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity): await super().async_added_to_hass() @property - def is_on(self): + def is_on(self) -> bool | None: """Return true if device is on.""" return self._state - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Fire the on action.""" await self.async_run_script(self._on_script, context=self._context) if self._template is None: self._state = True self.async_write_ha_state() - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Fire the off action.""" await self.async_run_script(self._off_script, context=self._context) if self._template is None: @@ -166,6 +168,6 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity): self.async_write_ha_state() @property - def assumed_state(self): + def assumed_state(self) -> bool: """State is assumed, if no template given.""" return self._template is None diff --git a/homeassistant/components/template/vacuum.py b/homeassistant/components/template/vacuum.py index 5f306bfa5e1..0a74ee5c5fc 100644 --- a/homeassistant/components/template/vacuum.py +++ b/homeassistant/components/template/vacuum.py @@ -200,7 +200,7 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity): self._attr_fan_speed_list = config[CONF_FAN_SPEED_LIST] @property - def state(self): + def state(self) -> str | None: """Return the status of the vacuum cleaner.""" return self._state @@ -263,7 +263,7 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity): self._attr_fan_speed_list, ) - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" if self._template is not None: self.add_template_attribute(