diff --git a/homeassistant/components/acer_projector/switch.py b/homeassistant/components/acer_projector/switch.py index 101f7cbd615..4a61ec793db 100644 --- a/homeassistant/components/acer_projector/switch.py +++ b/homeassistant/components/acer_projector/switch.py @@ -132,7 +132,7 @@ class AcerSwitch(SwitchEntity): return self._state @property - def state_attributes(self): + def extra_state_attributes(self): """Return state attributes.""" return self._attributes diff --git a/homeassistant/components/air_quality/__init__.py b/homeassistant/components/air_quality/__init__.py index 52c9208854a..d69a02f83bd 100644 --- a/homeassistant/components/air_quality/__init__.py +++ b/homeassistant/components/air_quality/__init__.py @@ -1,6 +1,7 @@ """Component for handling Air Quality data for your location.""" from datetime import timedelta import logging +from typing import final from homeassistant.const import ( ATTR_ATTRIBUTION, @@ -131,6 +132,7 @@ class AirQualityEntity(Entity): """Return the NO2 (nitrogen dioxide) level.""" return None + @final @property def state_attributes(self): """Return the state attributes.""" diff --git a/homeassistant/components/alarm_control_panel/__init__.py b/homeassistant/components/alarm_control_panel/__init__.py index 114abfa9cd6..7d9e47fbcbe 100644 --- a/homeassistant/components/alarm_control_panel/__init__.py +++ b/homeassistant/components/alarm_control_panel/__init__.py @@ -2,6 +2,7 @@ from abc import abstractmethod from datetime import timedelta import logging +from typing import final import voluptuous as vol @@ -172,6 +173,7 @@ class AlarmControlPanelEntity(Entity): def supported_features(self) -> int: """Return the list of supported features.""" + @final @property def state_attributes(self): """Return the state attributes.""" diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py index 18186e8b871..d68549ea95c 100644 --- a/homeassistant/components/arwn/sensor.py +++ b/homeassistant/components/arwn/sensor.py @@ -154,7 +154,7 @@ class ArwnSensor(Entity): return self._uid @property - def state_attributes(self): + def extra_state_attributes(self): """Return all the state attributes.""" return self.event diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 425ffe17979..4c278cbf5f0 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -274,7 +274,7 @@ class AutomationEntity(ToggleEntity, RestoreEntity): return False @property - def state_attributes(self): + def extra_state_attributes(self): """Return the entity state attributes.""" attrs = { ATTR_LAST_TRIGGERED: self.action_script.last_triggered, diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index 81ce49e9c94..11a6916ba83 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -4,7 +4,7 @@ from __future__ import annotations from datetime import timedelta import logging import re -from typing import cast +from typing import cast, final from aiohttp import web @@ -129,13 +129,14 @@ def is_offset_reached(event): class CalendarEventDevice(Entity): - """A calendar event device.""" + """Base class for calendar event entities.""" @property def event(self): """Return the next upcoming event.""" raise NotImplementedError() + @final @property def state_attributes(self): """Return the entity state attributes.""" diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index 99b5cebc2a3..70739857587 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -8,6 +8,7 @@ import hashlib import logging import os from random import SystemRandom +from typing import final from aiohttp import web import async_timeout @@ -441,6 +442,7 @@ class Camera(Entity): """Call the job and disable motion detection.""" await self.hass.async_add_executor_job(self.disable_motion_detection) + @final @property def state_attributes(self): """Return the camera state attributes.""" diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index 93041a6bb33..ef2d34aba9b 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -5,7 +5,7 @@ from abc import abstractmethod from datetime import timedelta import functools as ft import logging -from typing import Any +from typing import Any, final import voluptuous as vol @@ -167,7 +167,7 @@ async def async_unload_entry(hass: HomeAssistantType, entry): class ClimateEntity(Entity): - """Representation of a climate entity.""" + """Base class for climate entities.""" @property def state(self) -> str: @@ -213,6 +213,7 @@ class ClimateEntity(Entity): return data + @final @property def state_attributes(self) -> dict[str, Any]: """Return the optional state attributes.""" diff --git a/homeassistant/components/counter/__init__.py b/homeassistant/components/counter/__init__.py index a4e04825ef6..39cca0527eb 100644 --- a/homeassistant/components/counter/__init__.py +++ b/homeassistant/components/counter/__init__.py @@ -208,7 +208,7 @@ class Counter(RestoreEntity): return self._state @property - def state_attributes(self) -> dict: + def extra_state_attributes(self) -> dict: """Return the state attributes.""" ret = { ATTR_EDITABLE: self.editable, diff --git a/homeassistant/components/cover/__init__.py b/homeassistant/components/cover/__init__.py index c63963c87dc..034beb7f9db 100644 --- a/homeassistant/components/cover/__init__.py +++ b/homeassistant/components/cover/__init__.py @@ -2,7 +2,7 @@ from datetime import timedelta import functools as ft import logging -from typing import Any +from typing import Any, final import voluptuous as vol @@ -165,7 +165,7 @@ async def async_unload_entry(hass, entry): class CoverEntity(Entity): - """Representation of a cover.""" + """Base class for cover entities.""" @property def current_cover_position(self): @@ -196,6 +196,7 @@ class CoverEntity(Entity): return STATE_CLOSED if closed else STATE_OPEN + @final @property def state_attributes(self): """Return the state attributes.""" diff --git a/homeassistant/components/device_tracker/config_entry.py b/homeassistant/components/device_tracker/config_entry.py index 0d8970e087b..05fa4b4a60d 100644 --- a/homeassistant/components/device_tracker/config_entry.py +++ b/homeassistant/components/device_tracker/config_entry.py @@ -1,6 +1,8 @@ """Code to set up a device tracker platform using a config entry.""" from __future__ import annotations +from typing import final + from homeassistant.components import zone from homeassistant.const import ( ATTR_BATTERY_LEVEL, @@ -59,7 +61,7 @@ class BaseTrackerEntity(Entity): class TrackerEntity(BaseTrackerEntity): - """Represent a tracked device.""" + """Base class for a tracked device.""" @property def should_poll(self): @@ -114,6 +116,7 @@ class TrackerEntity(BaseTrackerEntity): return None + @final @property def state_attributes(self): """Return the device state attributes.""" @@ -128,7 +131,7 @@ class TrackerEntity(BaseTrackerEntity): class ScannerEntity(BaseTrackerEntity): - """Represent a tracked device that is on a scanned network.""" + """Base class for a tracked device that is on a scanned network.""" @property def ip_address(self) -> str: @@ -157,6 +160,7 @@ class ScannerEntity(BaseTrackerEntity): """Return true if the device is connected to the network.""" raise NotImplementedError + @final @property def state_attributes(self): """Return the device state attributes.""" diff --git a/homeassistant/components/device_tracker/legacy.py b/homeassistant/components/device_tracker/legacy.py index 1d3e428b46a..7ab8df1de87 100644 --- a/homeassistant/components/device_tracker/legacy.py +++ b/homeassistant/components/device_tracker/legacy.py @@ -5,7 +5,7 @@ import asyncio from datetime import timedelta import hashlib from types import ModuleType -from typing import Any, Callable, Sequence +from typing import Any, Callable, Sequence, final import attr import voluptuous as vol @@ -588,7 +588,7 @@ class DeviceTracker: class Device(RestoreEntity): - """Represent a tracked device.""" + """Base class for a tracked device.""" host_name: str = None location_name: str = None @@ -661,6 +661,7 @@ class Device(RestoreEntity): """Return the picture of the device.""" return self.config_picture + @final @property def state_attributes(self): """Return the device state attributes.""" diff --git a/homeassistant/components/fail2ban/sensor.py b/homeassistant/components/fail2ban/sensor.py index 2f206dca737..30aa0c69838 100644 --- a/homeassistant/components/fail2ban/sensor.py +++ b/homeassistant/components/fail2ban/sensor.py @@ -66,7 +66,7 @@ class BanSensor(Entity): return self._name @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes of the fail2ban sensor.""" return self.ban_dict diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index 85b31c31576..da2224aaf33 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -5,6 +5,7 @@ from datetime import timedelta import functools as ft import logging import math +from typing import final import voluptuous as vol @@ -220,7 +221,7 @@ def _fan_native(method): class FanEntity(ToggleEntity): - """Representation of a fan.""" + """Base class for fan entities.""" @_fan_native def set_speed(self, speed: str) -> None: @@ -586,6 +587,7 @@ class FanEntity(ToggleEntity): f"The speed_list {speed_list} does not contain any valid speeds." ) from ex + @final @property def state_attributes(self) -> dict: """Return optional state attributes.""" diff --git a/homeassistant/components/fritzbox_netmonitor/sensor.py b/homeassistant/components/fritzbox_netmonitor/sensor.py index 13b822ae8a4..320144ae163 100644 --- a/homeassistant/components/fritzbox_netmonitor/sensor.py +++ b/homeassistant/components/fritzbox_netmonitor/sensor.py @@ -93,7 +93,7 @@ class FritzboxMonitorSensor(Entity): return self._state @property - def state_attributes(self): + def extra_state_attributes(self): """Return the device state attributes.""" # Don't return attributes if FritzBox is unreachable if self._state == STATE_UNAVAILABLE: diff --git a/homeassistant/components/geo_location/__init__.py b/homeassistant/components/geo_location/__init__.py index 2041c147b2b..11294e73f63 100644 --- a/homeassistant/components/geo_location/__init__.py +++ b/homeassistant/components/geo_location/__init__.py @@ -3,6 +3,7 @@ from __future__ import annotations from datetime import timedelta import logging +from typing import final from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE from homeassistant.helpers.config_validation import ( # noqa: F401 @@ -46,7 +47,7 @@ async def async_unload_entry(hass, entry): class GeolocationEvent(Entity): - """This represents an external event with an associated geolocation.""" + """Base class for an external event with an associated geolocation.""" @property def state(self): @@ -75,6 +76,7 @@ class GeolocationEvent(Entity): """Return longitude value of this external event.""" return None + @final @property def state_attributes(self): """Return the state attributes of this external event.""" diff --git a/homeassistant/components/group/__init__.py b/homeassistant/components/group/__init__.py index 96822b9f993..5e8a2e679f6 100644 --- a/homeassistant/components/group/__init__.py +++ b/homeassistant/components/group/__init__.py @@ -547,7 +547,7 @@ class Group(Entity): self._icon = value @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes for the group.""" data = {ATTR_ENTITY_ID: self.tracking, ATTR_ORDER: self._order} if not self.user_defined: diff --git a/homeassistant/components/homematic/entity.py b/homeassistant/components/homematic/entity.py index 3643871c607..50b9bcb2bfc 100644 --- a/homeassistant/components/homematic/entity.py +++ b/homeassistant/components/homematic/entity.py @@ -231,7 +231,7 @@ class HMHub(Entity): return self._state @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" return self._variables.copy() diff --git a/homeassistant/components/humidifier/__init__.py b/homeassistant/components/humidifier/__init__.py index 01a9fc2ada0..f6a4ebcccd9 100644 --- a/homeassistant/components/humidifier/__init__.py +++ b/homeassistant/components/humidifier/__init__.py @@ -3,7 +3,7 @@ from __future__ import annotations from datetime import timedelta import logging -from typing import Any +from typing import Any, final import voluptuous as vol @@ -99,7 +99,7 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> boo class HumidifierEntity(ToggleEntity): - """Representation of a humidifier device.""" + """Base class for humidifier entities.""" @property def capability_attributes(self) -> dict[str, Any]: @@ -115,6 +115,7 @@ class HumidifierEntity(ToggleEntity): return data + @final @property def state_attributes(self) -> dict[str, Any]: """Return the optional state attributes.""" diff --git a/homeassistant/components/icloud/account.py b/homeassistant/components/icloud/account.py index 97bba3c5ca6..2fc8f7124d0 100644 --- a/homeassistant/components/icloud/account.py +++ b/homeassistant/components/icloud/account.py @@ -502,6 +502,6 @@ class IcloudDevice: return self._location @property - def state_attributes(self) -> dict[str, any]: + def exta_state_attributes(self) -> dict[str, any]: """Return the attributes.""" return self._attrs diff --git a/homeassistant/components/image_processing/__init__.py b/homeassistant/components/image_processing/__init__.py index e885a9ca7a9..1320629aeb4 100644 --- a/homeassistant/components/image_processing/__init__.py +++ b/homeassistant/components/image_processing/__init__.py @@ -2,6 +2,7 @@ import asyncio from datetime import timedelta import logging +from typing import final import voluptuous as vol @@ -175,6 +176,7 @@ class ImageProcessingFaceEntity(ImageProcessingEntity): """Return the class of this device, from component DEVICE_CLASSES.""" return "face" + @final @property def state_attributes(self): """Return device specific state attributes.""" diff --git a/homeassistant/components/input_boolean/__init__.py b/homeassistant/components/input_boolean/__init__.py index f1e4ebd57dc..b46135d934a 100644 --- a/homeassistant/components/input_boolean/__init__.py +++ b/homeassistant/components/input_boolean/__init__.py @@ -169,7 +169,7 @@ class InputBoolean(ToggleEntity, RestoreEntity): return self._config.get(CONF_NAME) @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes of the entity.""" return {ATTR_EDITABLE: self.editable} diff --git a/homeassistant/components/input_datetime/__init__.py b/homeassistant/components/input_datetime/__init__.py index 8273652be43..c408c73f869 100644 --- a/homeassistant/components/input_datetime/__init__.py +++ b/homeassistant/components/input_datetime/__init__.py @@ -319,7 +319,7 @@ class InputDatetime(RestoreEntity): return self._current_datetime.strftime(FMT_TIME) @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" attrs = { ATTR_EDITABLE: self.editable, diff --git a/homeassistant/components/input_number/__init__.py b/homeassistant/components/input_number/__init__.py index 5f73dec0192..d22a43c3330 100644 --- a/homeassistant/components/input_number/__init__.py +++ b/homeassistant/components/input_number/__init__.py @@ -256,7 +256,7 @@ class InputNumber(RestoreEntity): return self._config[CONF_ID] @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" return { ATTR_INITIAL: self._config.get(CONF_INITIAL), diff --git a/homeassistant/components/input_select/__init__.py b/homeassistant/components/input_select/__init__.py index f14d23124e7..92defe2ded9 100644 --- a/homeassistant/components/input_select/__init__.py +++ b/homeassistant/components/input_select/__init__.py @@ -253,7 +253,7 @@ class InputSelect(RestoreEntity): return self._current_option @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" return {ATTR_OPTIONS: self._config[ATTR_OPTIONS], ATTR_EDITABLE: self.editable} diff --git a/homeassistant/components/input_text/__init__.py b/homeassistant/components/input_text/__init__.py index d4e0fc705f2..3eef18f01b1 100644 --- a/homeassistant/components/input_text/__init__.py +++ b/homeassistant/components/input_text/__init__.py @@ -245,7 +245,7 @@ class InputText(RestoreEntity): return self._config[CONF_ID] @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" return { ATTR_EDITABLE: self.editable, diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 7934874db0b..06b6829d31c 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -6,7 +6,7 @@ import dataclasses from datetime import timedelta import logging import os -from typing import cast +from typing import cast, final import voluptuous as vol @@ -478,7 +478,7 @@ class Profiles: class LightEntity(ToggleEntity): - """Representation of a light.""" + """Base class for light entities.""" @property def brightness(self) -> int | None: @@ -634,6 +634,7 @@ class LightEntity(ToggleEntity): data[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color) return data + @final @property def state_attributes(self): """Return state attributes.""" diff --git a/homeassistant/components/lock/__init__.py b/homeassistant/components/lock/__init__.py index bc7dc10ba8d..237daedae80 100644 --- a/homeassistant/components/lock/__init__.py +++ b/homeassistant/components/lock/__init__.py @@ -2,6 +2,7 @@ from datetime import timedelta import functools as ft import logging +from typing import final import voluptuous as vol @@ -76,7 +77,7 @@ async def async_unload_entry(hass, entry): class LockEntity(Entity): - """Representation of a lock.""" + """Base class for lock entities.""" @property def changed_by(self): @@ -117,6 +118,7 @@ class LockEntity(Entity): """Open the door latch.""" await self.hass.async_add_executor_job(ft.partial(self.open, **kwargs)) + @final @property def state_attributes(self): """Return the state attributes.""" diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 8e3ffe5dd0d..faa2c488216 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -9,6 +9,7 @@ import functools as ft import hashlib import logging import secrets +from typing import final from urllib.parse import urlparse from aiohttp import web @@ -853,6 +854,7 @@ class MediaPlayerEntity(Entity): return data + @final @property def state_attributes(self): """Return the state attributes.""" diff --git a/homeassistant/components/netio/switch.py b/homeassistant/components/netio/switch.py index 3c1482844ad..a254d06fc06 100644 --- a/homeassistant/components/netio/switch.py +++ b/homeassistant/components/netio/switch.py @@ -169,7 +169,7 @@ class NetioSwitch(SwitchEntity): self.netio.update() @property - def state_attributes(self): + def extra_state_attributes(self): """Return optional state attributes.""" return { ATTR_TOTAL_CONSUMPTION_KWH: self.cumulated_consumption_kwh, diff --git a/homeassistant/components/openalpr_local/image_processing.py b/homeassistant/components/openalpr_local/image_processing.py index ee913070a11..d098edba5b2 100644 --- a/homeassistant/components/openalpr_local/image_processing.py +++ b/homeassistant/components/openalpr_local/image_processing.py @@ -99,7 +99,7 @@ class ImageProcessingAlprEntity(ImageProcessingEntity): return "alpr" @property - def state_attributes(self): + def extra_state_attributes(self): """Return device specific state attributes.""" return {ATTR_PLATES: self.plates, ATTR_VEHICLES: self.vehicles} diff --git a/homeassistant/components/opencv/image_processing.py b/homeassistant/components/opencv/image_processing.py index 028d6eacf24..bf63ec0bfff 100644 --- a/homeassistant/components/opencv/image_processing.py +++ b/homeassistant/components/opencv/image_processing.py @@ -152,7 +152,7 @@ class OpenCVImageProcessor(ImageProcessingEntity): return self._total_matches @property - def state_attributes(self): + def extra_state_attributes(self): """Return device specific state attributes.""" return {ATTR_MATCHES: self._matches, ATTR_TOTAL_MATCHES: self._total_matches} diff --git a/homeassistant/components/openhardwaremonitor/sensor.py b/homeassistant/components/openhardwaremonitor/sensor.py index 115366dac66..3254f0824f1 100644 --- a/homeassistant/components/openhardwaremonitor/sensor.py +++ b/homeassistant/components/openhardwaremonitor/sensor.py @@ -73,8 +73,8 @@ class OpenHardwareMonitorDevice(Entity): return self.value @property - def state_attributes(self): - """Return the state attributes of the sun.""" + def extra_state_attributes(self): + """Return the state attributes of the entity.""" return self.attributes @classmethod diff --git a/homeassistant/components/person/__init__.py b/homeassistant/components/person/__init__.py index cf6403b7334..7774694ff4e 100644 --- a/homeassistant/components/person/__init__.py +++ b/homeassistant/components/person/__init__.py @@ -400,7 +400,7 @@ class Person(RestoreEntity): return self._state @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes of the person.""" data = {ATTR_EDITABLE: self.editable, ATTR_ID: self.unique_id} if self._latitude is not None: diff --git a/homeassistant/components/plant/__init__.py b/homeassistant/components/plant/__init__.py index 2d829187560..7c0c8e9b46f 100644 --- a/homeassistant/components/plant/__init__.py +++ b/homeassistant/components/plant/__init__.py @@ -348,7 +348,7 @@ class Plant(Entity): return self._state @property - def state_attributes(self): + def extra_state_attributes(self): """Return the attributes of the entity. Provide the individual measurements from the diff --git a/homeassistant/components/proximity/__init__.py b/homeassistant/components/proximity/__init__.py index 6df0f50b720..de9d6247f9f 100644 --- a/homeassistant/components/proximity/__init__.py +++ b/homeassistant/components/proximity/__init__.py @@ -148,7 +148,7 @@ class Proximity(Entity): return self._unit_of_measurement @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" return {ATTR_DIR_OF_TRAVEL: self.dir_of_travel, ATTR_NEAREST: self.nearest} diff --git a/homeassistant/components/remote/__init__.py b/homeassistant/components/remote/__init__.py index fe220dd46a8..ecde6f67b67 100644 --- a/homeassistant/components/remote/__init__.py +++ b/homeassistant/components/remote/__init__.py @@ -4,7 +4,7 @@ from __future__ import annotations from datetime import timedelta import functools as ft import logging -from typing import Any, Iterable, cast +from typing import Any, Iterable, cast, final import voluptuous as vol @@ -141,7 +141,7 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> boo class RemoteEntity(ToggleEntity): - """Representation of a remote.""" + """Base class for remote entities.""" @property def supported_features(self) -> int: @@ -158,6 +158,7 @@ class RemoteEntity(ToggleEntity): """List of available activities.""" return None + @final @property def state_attributes(self) -> dict[str, Any] | None: """Return optional state attributes.""" diff --git a/homeassistant/components/rmvtransport/sensor.py b/homeassistant/components/rmvtransport/sensor.py index ad1ceea3d86..555f545d0c7 100644 --- a/homeassistant/components/rmvtransport/sensor.py +++ b/homeassistant/components/rmvtransport/sensor.py @@ -151,7 +151,7 @@ class RMVDepartureSensor(Entity): return self._state @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" try: return { diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index ec0bee73528..243cdaddd81 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -284,7 +284,7 @@ class ScriptEntity(ToggleEntity): return self.script.name @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" attrs = { ATTR_LAST_TRIGGERED: self.script.last_triggered, diff --git a/homeassistant/components/sony_projector/switch.py b/homeassistant/components/sony_projector/switch.py index 723478ac34b..935b33cc5df 100644 --- a/homeassistant/components/sony_projector/switch.py +++ b/homeassistant/components/sony_projector/switch.py @@ -65,7 +65,7 @@ class SonyProjector(SwitchEntity): return self._state @property - def state_attributes(self): + def extra_state_attributes(self): """Return state attributes.""" return self._attributes diff --git a/homeassistant/components/sun/__init__.py b/homeassistant/components/sun/__init__.py index 2d921da4a46..dfe3b15c110 100644 --- a/homeassistant/components/sun/__init__.py +++ b/homeassistant/components/sun/__init__.py @@ -124,7 +124,7 @@ class Sun(Entity): return STATE_BELOW_HORIZON @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes of the sun.""" return { STATE_ATTR_NEXT_DAWN: self.next_dawn.isoformat(), diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index 1d9b54a0424..c585fdc22d3 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -1,6 +1,7 @@ """Component to interface with switches that can be controlled remotely.""" from datetime import timedelta import logging +from typing import final import voluptuous as vol @@ -79,7 +80,7 @@ async def async_unload_entry(hass, entry): class SwitchEntity(ToggleEntity): - """Representation of a switch.""" + """Base class for switch entities.""" @property def current_power_w(self): @@ -96,6 +97,7 @@ class SwitchEntity(ToggleEntity): """Return true if device is in standby.""" return None + @final @property def state_attributes(self): """Return the optional state attributes.""" diff --git a/homeassistant/components/timer/__init__.py b/homeassistant/components/timer/__init__.py index 05955b46b5c..216ab3217a5 100644 --- a/homeassistant/components/timer/__init__.py +++ b/homeassistant/components/timer/__init__.py @@ -232,7 +232,7 @@ class Timer(RestoreEntity): return self._state @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" attrs = { ATTR_DURATION: _format_timedelta(self._duration), diff --git a/homeassistant/components/twinkly/light.py b/homeassistant/components/twinkly/light.py index ece3e0b048c..4353aa2707b 100644 --- a/homeassistant/components/twinkly/light.py +++ b/homeassistant/components/twinkly/light.py @@ -129,7 +129,7 @@ class TwinklyLight(LightEntity): return self._brightness @property - def state_attributes(self) -> dict: + def extra_state_attributes(self) -> dict: """Return device specific state attributes.""" attributes = self._attributes diff --git a/homeassistant/components/utility_meter/__init__.py b/homeassistant/components/utility_meter/__init__.py index 24bfd77f762..5442cd583e2 100644 --- a/homeassistant/components/utility_meter/__init__.py +++ b/homeassistant/components/utility_meter/__init__.py @@ -165,7 +165,7 @@ class TariffSelect(RestoreEntity): return self._current_tariff @property - def state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" return {ATTR_TARIFFS: self._tariffs} diff --git a/homeassistant/components/vacuum/__init__.py b/homeassistant/components/vacuum/__init__.py index ca5caec7ac1..d8803931f38 100644 --- a/homeassistant/components/vacuum/__init__.py +++ b/homeassistant/components/vacuum/__init__.py @@ -2,6 +2,7 @@ from datetime import timedelta from functools import partial import logging +from typing import final import voluptuous as vol @@ -271,6 +272,7 @@ class VacuumEntity(_BaseVacuum, ToggleEntity): battery_level=self.battery_level, charging=charging ) + @final @property def state_attributes(self): """Return the state attributes of the vacuum cleaner.""" diff --git a/homeassistant/components/water_heater/__init__.py b/homeassistant/components/water_heater/__init__.py index 0763c552075..5ae22c77b5e 100644 --- a/homeassistant/components/water_heater/__init__.py +++ b/homeassistant/components/water_heater/__init__.py @@ -2,6 +2,7 @@ from datetime import timedelta import functools as ft import logging +from typing import final import voluptuous as vol @@ -129,7 +130,7 @@ async def async_unload_entry(hass, entry): class WaterHeaterEntity(Entity): - """Representation of a water_heater device.""" + """Base class for water heater entities.""" @property def state(self): @@ -162,6 +163,7 @@ class WaterHeaterEntity(Entity): return data + @final @property def state_attributes(self): """Return the optional state attributes.""" diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index 5127dae1102..da66c354d5a 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -1,6 +1,7 @@ """Weather component that handles meteorological data for your location.""" from datetime import timedelta import logging +from typing import final from homeassistant.const import PRECISION_TENTHS, PRECISION_WHOLE, TEMP_CELSIUS from homeassistant.helpers.config_validation import ( # noqa: F401 @@ -138,6 +139,7 @@ class WeatherEntity(Entity): else PRECISION_WHOLE ) + @final @property def state_attributes(self): """Return the state attributes.""" diff --git a/homeassistant/components/workday/binary_sensor.py b/homeassistant/components/workday/binary_sensor.py index 7a414035900..ed3822b9698 100644 --- a/homeassistant/components/workday/binary_sensor.py +++ b/homeassistant/components/workday/binary_sensor.py @@ -171,7 +171,7 @@ class IsWorkdaySensor(BinarySensorEntity): return False @property - def state_attributes(self): + def extra_state_attributes(self): """Return the attributes of the entity.""" # return self._attributes return { diff --git a/homeassistant/components/zone/__init__.py b/homeassistant/components/zone/__init__.py index 7e329127d03..4866c278074 100644 --- a/homeassistant/components/zone/__init__.py +++ b/homeassistant/components/zone/__init__.py @@ -315,7 +315,7 @@ class Zone(entity.Entity): return self._config.get(CONF_ICON) @property - def state_attributes(self) -> dict | None: + def extra_state_attributes(self) -> dict | None: """Return the state attributes of the zone.""" return self._attrs diff --git a/tests/components/fail2ban/test_sensor.py b/tests/components/fail2ban/test_sensor.py index e43064c54ab..f9c78e14888 100644 --- a/tests/components/fail2ban/test_sensor.py +++ b/tests/components/fail2ban/test_sensor.py @@ -89,8 +89,8 @@ async def test_single_ban(hass): sensor.update() assert sensor.state == "111.111.111.111" - assert sensor.state_attributes[STATE_CURRENT_BANS] == ["111.111.111.111"] - assert sensor.state_attributes[STATE_ALL_BANS] == ["111.111.111.111"] + assert sensor.extra_state_attributes[STATE_CURRENT_BANS] == ["111.111.111.111"] + assert sensor.extra_state_attributes[STATE_ALL_BANS] == ["111.111.111.111"] async def test_ipv6_ban(hass): @@ -103,8 +103,8 @@ async def test_ipv6_ban(hass): sensor.update() assert sensor.state == "2607:f0d0:1002:51::4" - assert sensor.state_attributes[STATE_CURRENT_BANS] == ["2607:f0d0:1002:51::4"] - assert sensor.state_attributes[STATE_ALL_BANS] == ["2607:f0d0:1002:51::4"] + assert sensor.extra_state_attributes[STATE_CURRENT_BANS] == ["2607:f0d0:1002:51::4"] + assert sensor.extra_state_attributes[STATE_ALL_BANS] == ["2607:f0d0:1002:51::4"] async def test_multiple_ban(hass): @@ -117,11 +117,11 @@ async def test_multiple_ban(hass): sensor.update() assert sensor.state == "222.222.222.222" - assert sensor.state_attributes[STATE_CURRENT_BANS] == [ + assert sensor.extra_state_attributes[STATE_CURRENT_BANS] == [ "111.111.111.111", "222.222.222.222", ] - assert sensor.state_attributes[STATE_ALL_BANS] == [ + assert sensor.extra_state_attributes[STATE_ALL_BANS] == [ "111.111.111.111", "222.222.222.222", ] @@ -137,8 +137,8 @@ async def test_unban_all(hass): sensor.update() assert sensor.state == "None" - assert sensor.state_attributes[STATE_CURRENT_BANS] == [] - assert sensor.state_attributes[STATE_ALL_BANS] == [ + assert sensor.extra_state_attributes[STATE_CURRENT_BANS] == [] + assert sensor.extra_state_attributes[STATE_ALL_BANS] == [ "111.111.111.111", "222.222.222.222", ] @@ -154,8 +154,8 @@ async def test_unban_one(hass): sensor.update() assert sensor.state == "222.222.222.222" - assert sensor.state_attributes[STATE_CURRENT_BANS] == ["222.222.222.222"] - assert sensor.state_attributes[STATE_ALL_BANS] == [ + assert sensor.extra_state_attributes[STATE_CURRENT_BANS] == ["222.222.222.222"] + assert sensor.extra_state_attributes[STATE_ALL_BANS] == [ "111.111.111.111", "222.222.222.222", ] @@ -174,11 +174,11 @@ async def test_multi_jail(hass): sensor2.update() assert sensor1.state == "111.111.111.111" - assert sensor1.state_attributes[STATE_CURRENT_BANS] == ["111.111.111.111"] - assert sensor1.state_attributes[STATE_ALL_BANS] == ["111.111.111.111"] + assert sensor1.extra_state_attributes[STATE_CURRENT_BANS] == ["111.111.111.111"] + assert sensor1.extra_state_attributes[STATE_ALL_BANS] == ["111.111.111.111"] assert sensor2.state == "222.222.222.222" - assert sensor2.state_attributes[STATE_CURRENT_BANS] == ["222.222.222.222"] - assert sensor2.state_attributes[STATE_ALL_BANS] == ["222.222.222.222"] + assert sensor2.extra_state_attributes[STATE_CURRENT_BANS] == ["222.222.222.222"] + assert sensor2.extra_state_attributes[STATE_ALL_BANS] == ["222.222.222.222"] async def test_ban_active_after_update(hass): @@ -192,5 +192,5 @@ async def test_ban_active_after_update(hass): assert sensor.state == "111.111.111.111" sensor.update() assert sensor.state == "111.111.111.111" - assert sensor.state_attributes[STATE_CURRENT_BANS] == ["111.111.111.111"] - assert sensor.state_attributes[STATE_ALL_BANS] == ["111.111.111.111"] + assert sensor.extra_state_attributes[STATE_CURRENT_BANS] == ["111.111.111.111"] + assert sensor.extra_state_attributes[STATE_ALL_BANS] == ["111.111.111.111"] diff --git a/tests/components/plant/test_init.py b/tests/components/plant/test_init.py index 494206d81a3..14e0f3668b0 100644 --- a/tests/components/plant/test_init.py +++ b/tests/components/plant/test_init.py @@ -58,7 +58,7 @@ async def test_valid_data(hass): State(GOOD_CONFIG["sensors"][reading], value), ) assert sensor.state == "ok" - attrib = sensor.state_attributes + attrib = sensor.extra_state_attributes for reading, value in GOOD_DATA.items(): # battery level has a different name in # the JSON format than in hass @@ -70,13 +70,13 @@ async def test_low_battery(hass): sensor = plant.Plant("other plant", GOOD_CONFIG) sensor.entity_id = "sensor.mqtt_plant_battery" sensor.hass = hass - assert sensor.state_attributes["problem"] == "none" + assert sensor.extra_state_attributes["problem"] == "none" sensor.state_changed( "sensor.mqtt_plant_battery", State("sensor.mqtt_plant_battery", 10), ) assert sensor.state == "problem" - assert sensor.state_attributes["problem"] == "battery low" + assert sensor.extra_state_attributes["problem"] == "battery low" async def test_initial_states(hass):