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

View File

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

View File

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

View File

@ -2,7 +2,6 @@
from __future__ import annotations
import asyncio
from collections.abc import MutableMapping
from typing import Any
from pyopenuv import Client
@ -169,9 +168,7 @@ class OpenUvEntity(Entity):
def __init__(self, openuv: OpenUV, sensor_type: str) -> None:
"""Initialize."""
self._attr_extra_state_attributes: MutableMapping[str, Any] = {
ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION
}
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._attr_should_poll = False
self._attr_unique_id = (
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._attr_extra_state_attributes: dict[str, Any] = {}
self._attr_extra_state_attributes = {}
self._attr_should_poll = False
self._attr_name = SIA_NAME_FORMAT.format(
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_entity_picture: str | None = None
_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_icon: str | None
_attr_name: str | None
@ -319,7 +319,9 @@ class Entity(ABC):
Implemented by platform classes. Convention for attribute names
is lowercase snake_case.
"""
return self._attr_extra_state_attributes
if hasattr(self, "_attr_extra_state_attributes"):
return self._attr_extra_state_attributes
return None
@property
def device_info(self) -> DeviceInfo | None: