Add type hints to extra_state_attributes [m-z] (#163281)

This commit is contained in:
epenet
2026-02-17 16:00:42 +01:00
committed by GitHub
parent 1d41e24653
commit e7aa0ae398
34 changed files with 68 additions and 39 deletions

View File

@@ -225,7 +225,7 @@ class MaxCubeClimate(ClimateEntity):
raise ValueError(f"unsupported preset mode {preset_mode}")
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the optional state attributes."""
if not self._device.is_thermostat():
return {}

View File

@@ -1,5 +1,7 @@
"""Support for Motionblinds sensors."""
from typing import Any
from motionblinds import DEVICE_TYPES_WIFI
from motionblinds.motion_blinds import DEVICE_TYPE_TDBU
@@ -68,7 +70,7 @@ class MotionBatterySensor(MotionCoordinatorEntity, SensorEntity):
return self._blind.battery_level
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return device specific state attributes."""
return {ATTR_BATTERY_VOLTAGE: self._blind.battery_voltage}
@@ -92,7 +94,7 @@ class MotionTDBUBatterySensor(MotionBatterySensor):
return self._blind.battery_level[self._motor[0]]
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return device specific state attributes."""
attributes = {}
if self._blind.battery_voltage is not None:

View File

@@ -173,7 +173,7 @@ class MQTTRoomSensor(SensorEntity):
return self._name
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {ATTR_DISTANCE: self._distance}

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import Any
import defusedxml.ElementTree as ET
import requests
@@ -70,7 +71,7 @@ class OhmconnectSensor(SensorEntity):
return "Inactive"
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {"Address": self._data.get("address"), "ID": self._ohmid}

View File

@@ -108,6 +108,6 @@ class PencomRelay(SwitchEntity):
self._state = self._hub.get(self._board, self._addr)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return supported attributes."""
return {"board": self._board, "addr": self._addr}

View File

@@ -8,6 +8,7 @@ from collections import deque
from contextlib import suppress
from datetime import datetime, timedelta
import logging
from typing import Any
import voluptuous as vol
@@ -345,7 +346,7 @@ class Plant(Entity):
return self._state
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the attributes of the entity.
Provide the individual measurements from the

View File

@@ -500,7 +500,7 @@ class PlexMediaPlayer(MediaPlayerEntity):
) from exc
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the scene state attributes."""
attributes = {}
for attr in (

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import logging
from typing import Any
from plexapi.exceptions import NotFound
import requests.exceptions
@@ -110,7 +111,7 @@ class PlexSensor(SensorEntity):
self.async_write_ha_state()
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return self._server.sensor_attributes

View File

@@ -1,6 +1,7 @@
"""Support for Minut Point."""
import logging
from typing import Any
from pypoint import Device, PointSession
@@ -56,7 +57,7 @@ class MinutPointEntity(CoordinatorEntity[PointDataUpdateCoordinator]):
return self.client.device(self.device_id)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return status of device."""
attrs = self.device.device_status
attrs["last_heard_from"] = as_local(

View File

@@ -78,7 +78,7 @@ class ProliphixThermostat(ClimateEntity):
return self._name
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the device specific state attributes."""
return {ATTR_FAN: self._pdp.fan_state}

View File

@@ -6,7 +6,7 @@ import asyncio
from collections import deque
from datetime import timedelta
import logging
from typing import cast
from typing import Any, cast
from aiohttp import web
import voluptuous as vol
@@ -183,7 +183,7 @@ class PushCamera(Camera):
return self._current_image
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {
name: value

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import logging
from typing import Any
from pyqvrpro.client import QVRResponseError
@@ -88,7 +89,7 @@ class QVRProCamera(Camera):
return self._brand
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Get the state attributes."""
return {"qvr_guid": self.guid}

View File

@@ -72,7 +72,7 @@ class RainBirdSwitch(CoordinatorEntity[RainbirdUpdateCoordinator], SwitchEntity)
)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return state attributes."""
return {"zone": self._zone}

View File

@@ -1,5 +1,7 @@
"""Support for Melnor RainCloud sprinkler water timer."""
from typing import Any
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
@@ -58,7 +60,7 @@ class RainCloudEntity(Entity):
self.schedule_update_ha_state(True)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {"identifier": self.data.serial}

View File

@@ -98,7 +98,7 @@ class RainCloudSwitch(RainCloudEntity, SwitchEntity):
self._state = self.data.auto_watering
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {
"default_manual_timer": self._default_watering_timer,

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import Any
import praw
import voluptuous as vol
@@ -118,7 +119,7 @@ class RedditSensor(SensorEntity):
return len(self._subreddit_data)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {
ATTR_SUBREDDIT: self._subreddit,

View File

@@ -10,6 +10,7 @@ from contextlib import suppress
from datetime import datetime, timedelta
import logging
from operator import itemgetter
from typing import Any
import rjpl
import voluptuous as vol
@@ -124,7 +125,7 @@ class RejseplanenTransportSensor(SensorEntity):
return self._state
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
if not self._times:
return {ATTR_STOP_ID: self._stop_id}

View File

@@ -5,6 +5,7 @@ from __future__ import annotations
import asyncio
from datetime import timedelta
import logging
from typing import Any
from RMVtransport import RMVtransport
from RMVtransport.rmvtransport import (
@@ -166,7 +167,7 @@ class RMVDepartureSensor(SensorEntity):
return self._state
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
try:
return {

View File

@@ -1,5 +1,7 @@
"""Support for Smart Meter Texas sensors."""
from typing import Any
from smart_meter_texas import Meter
from homeassistant.components.sensor import (
@@ -58,7 +60,7 @@ class SmartMeterTexasSensor(CoordinatorEntity, RestoreEntity, SensorEntity):
self._attr_unique_id = f"{meter.esiid}_{meter.meter}"
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the device specific state attributes."""
return {
METER_NUMBER: self.meter.meter,

View File

@@ -7,6 +7,7 @@ import dataclasses
from datetime import timedelta
import logging
import statistics
from typing import Any
from requests.exceptions import ConnectTimeout, HTTPError
from solaredge_local import SolarEdge
@@ -289,7 +290,7 @@ class SolarEdgeSensor(SensorEntity):
self._attr_name = f"{platform_name} ({description.name})"
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes."""
if extra_attr := self.entity_description.extra_attribute:
try:

View File

@@ -333,9 +333,9 @@ class SoundTouchMediaPlayer(MediaPlayerEntity):
self._device.add_zone_slave([slave.device for slave in slaves])
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return entity specific state attributes."""
attributes = {}
attributes: dict[str, Any] = {}
if self._zone and "master" in self._zone:
attributes[ATTR_SOUNDTOUCH_ZONE] = self._zone

View File

@@ -2,6 +2,8 @@
from __future__ import annotations
from typing import Any
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
@@ -166,7 +168,7 @@ class StarlineSensor(StarlineEntity, SensorEntity):
return self.entity_description.native_unit_of_measurement
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes of the sensor."""
if self._key == "balance":
return self._account.balance_attrs(self._device)

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import logging
from typing import Any
import xmlrpc.client
import voluptuous as vol
@@ -76,7 +77,7 @@ class SupervisorProcessSensor(SensorEntity):
return self._available
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return {
ATTR_DESCRIPTION: self._info.get("description"),

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import Any
from swisshydrodata import SwissHydroData
import voluptuous as vol
@@ -125,9 +126,9 @@ class SwissHydrologicalDataSensor(SensorEntity):
return None
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the device state attributes."""
attrs = {}
attrs: dict[str, Any] = {}
if not self._data:
return attrs

View File

@@ -2,6 +2,7 @@
from datetime import datetime
import logging
from typing import Any
from tellduslive import BATTERY_LOW, BATTERY_OK, BATTERY_UNKNOWN
@@ -68,7 +69,7 @@ class TelldusLiveEntity(Entity):
return self._client.is_available(self.device_id)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
attrs = {}
if self._battery_level:

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import Any
from requests import HTTPError
from tmb import IBus
@@ -108,7 +109,7 @@ class TMBSensor(SensorEntity):
return self._state
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the last update."""
return {
ATTR_BUS_STOP: self._stop,

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import Any
from travispy import TravisPy
from travispy.errors import TravisError
@@ -154,9 +155,9 @@ class TravisCISensor(SensorEntity):
self._attr_name = f"{repo_name} {description.name}"
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
attrs = {}
attrs: dict[str, Any] = {}
if self._build and self._attr_native_value is not None:
if self._user and self.entity_description.key == "state":

View File

@@ -533,7 +533,7 @@ class UniversalMediaPlayer(MediaPlayerEntity):
return flags
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return device specific state attributes."""
active_child = self._child_state
return {ATTR_ACTIVE_CHILD: active_child.entity_id} if active_child else {}

View File

@@ -1,5 +1,7 @@
"""Support the UPB PIM."""
from typing import Any
from homeassistant.core import callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity import Entity
@@ -25,7 +27,7 @@ class UpbEntity(Entity):
return self._unique_id
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the default attributes of the element."""
return self._element.as_dict()

View File

@@ -702,7 +702,7 @@ class UtilityMeterSensor(RestoreSensor):
)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the sensor."""
state_attr = {
ATTR_STATUS: PAUSED if self._collecting is None else COLLECTING,

View File

@@ -2,6 +2,8 @@
from __future__ import annotations
from typing import Any
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
@@ -82,7 +84,7 @@ class VerisureDoorWindowSensor(
)
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the sensor."""
return {
ATTR_LAST_TRIP_TIME: dt_util.parse_datetime(

View File

@@ -5,6 +5,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
import time
from typing import Any
import requests
import voluptuous as vol
@@ -81,7 +82,7 @@ class WorldTidesInfoSensor(SensorEntity):
return self._name
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of this device."""
attr = {}

View File

@@ -2,6 +2,7 @@
from collections.abc import Callable
import logging
from typing import Any
from miio import (
AirQualityMonitor,
@@ -116,7 +117,7 @@ class AirMonitorB1(XiaomiMiioEntity, AirQualityEntity):
return self._humidity
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
data = {}

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import Any
import requests
import voluptuous as vol
@@ -99,7 +100,7 @@ class ZestimateDataSensor(SensorEntity):
return None
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
attributes = {}
if self.data is not None: