Adjust typing of _attr_extra_state_attributes (#53529)

pull/53534/head
Franck Nijhof 2021-07-27 01:25:22 +02:00 committed by GitHub
parent 8ff3b2a2f6
commit d4c4263730
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 19 deletions

View File

@ -1,7 +1,7 @@
"""The airvisual component.""" """The airvisual component."""
from __future__ import annotations from __future__ import annotations
from collections.abc import Mapping, MutableMapping from collections.abc import Mapping
from datetime import timedelta from datetime import timedelta
from math import ceil from math import ceil
from typing import Any, Dict, cast from typing import Any, Dict, cast
@ -364,9 +364,7 @@ class AirVisualEntity(CoordinatorEntity):
"""Initialize.""" """Initialize."""
super().__init__(coordinator) super().__init__(coordinator)
self._attr_extra_state_attributes: MutableMapping[str, Any] = { self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION
}
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""

View File

@ -2,8 +2,8 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from collections.abc import Awaitable, MutableMapping from collections.abc import Awaitable
from typing import Any, cast from typing import cast
from aioguardian import Client from aioguardian import Client
@ -221,9 +221,7 @@ class GuardianEntity(CoordinatorEntity):
"""Initialize.""" """Initialize."""
self._attr_device_class = device_class self._attr_device_class = device_class
self._attr_device_info = {"manufacturer": "Elexa"} self._attr_device_info = {"manufacturer": "Elexa"}
self._attr_extra_state_attributes: MutableMapping[str, Any] = { self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: "Data provided by Elexa"}
ATTR_ATTRIBUTION: "Data provided by Elexa"
}
self._attr_icon = icon self._attr_icon = icon
self._attr_name = name self._attr_name = name
self._entry = entry self._entry = entry

View File

@ -30,9 +30,7 @@ class NetatmoBase(Entity):
self._model: str = "" self._model: str = ""
self._attr_name = None self._attr_name = None
self._attr_unique_id = None self._attr_unique_id = None
self._attr_extra_state_attributes: dict = { self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION
}
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Entity created.""" """Entity created."""

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from collections.abc import MutableMapping
from typing import Any from typing import Any
from pyopenuv import Client from pyopenuv import Client
@ -169,9 +168,7 @@ class OpenUvEntity(Entity):
def __init__(self, openuv: OpenUV, sensor_type: str) -> None: def __init__(self, openuv: OpenUV, sensor_type: str) -> None:
"""Initialize.""" """Initialize."""
self._attr_extra_state_attributes: MutableMapping[str, Any] = { self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION
}
self._attr_should_poll = False self._attr_should_poll = False
self._attr_unique_id = ( self._attr_unique_id = (
f"{openuv.client.latitude}_{openuv.client.longitude}_{sensor_type}" f"{openuv.client.latitude}_{openuv.client.longitude}_{sensor_type}"

View File

@ -43,7 +43,7 @@ class SIABaseEntity(RestoreEntity):
self._cancel_availability_cb: CALLBACK_TYPE | None = None self._cancel_availability_cb: CALLBACK_TYPE | None = None
self._attr_extra_state_attributes: dict[str, Any] = {} self._attr_extra_state_attributes = {}
self._attr_should_poll = False self._attr_should_poll = False
self._attr_name = SIA_NAME_FORMAT.format( self._attr_name = SIA_NAME_FORMAT.format(
self._port, self._account, self._zone, self._attr_device_class self._port, self._account, self._zone, self._attr_device_class

View File

@ -246,7 +246,7 @@ class Entity(ABC):
_attr_device_info: DeviceInfo | None = None _attr_device_info: DeviceInfo | None = None
_attr_entity_picture: str | None = None _attr_entity_picture: str | None = None
_attr_entity_registry_enabled_default: bool _attr_entity_registry_enabled_default: bool
_attr_extra_state_attributes: MutableMapping[str, Any] | None = None _attr_extra_state_attributes: MutableMapping[str, Any]
_attr_force_update: bool _attr_force_update: bool
_attr_icon: str | None _attr_icon: str | None
_attr_name: str | None _attr_name: str | None
@ -319,7 +319,9 @@ class Entity(ABC):
Implemented by platform classes. Convention for attribute names Implemented by platform classes. Convention for attribute names
is lowercase snake_case. is lowercase snake_case.
""" """
if hasattr(self, "_attr_extra_state_attributes"):
return self._attr_extra_state_attributes return self._attr_extra_state_attributes
return None
@property @property
def device_info(self) -> DeviceInfo | None: def device_info(self) -> DeviceInfo | None: