Entity.device_info typing fixes (#49974)

This commit is contained in:
Ville Skyttä 2021-05-11 08:11:51 +03:00 committed by GitHub
parent 34320ef617
commit 44a790ab47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions

View File

@ -5,12 +5,12 @@ import asyncio
import functools import functools
import logging import logging
import math import math
from typing import Any, Callable from typing import Callable
from aioesphomeapi import ( from aioesphomeapi import (
APIClient, APIClient,
APIConnectionError, APIConnectionError,
DeviceInfo, DeviceInfo as EsphomeDeviceInfo,
EntityInfo, EntityInfo,
EntityState, EntityState,
HomeassistantServiceCall, HomeassistantServiceCall,
@ -36,7 +36,7 @@ from homeassistant.helpers import template
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
import homeassistant.helpers.device_registry as dr import homeassistant.helpers.device_registry as dr
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.event import async_track_state_change_event from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.helpers.json import JSONEncoder from homeassistant.helpers.json import JSONEncoder
from homeassistant.helpers.service import async_set_service_schema from homeassistant.helpers.service import async_set_service_schema
@ -448,7 +448,7 @@ class ReconnectLogic(RecordUpdateListener):
async def _async_setup_device_registry( async def _async_setup_device_registry(
hass: HomeAssistant, entry: ConfigEntry, device_info: DeviceInfo hass: HomeAssistant, entry: ConfigEntry, device_info: EsphomeDeviceInfo
): ):
"""Set up device registry feature for a particular config entry.""" """Set up device registry feature for a particular config entry."""
sw_version = device_info.esphome_version sw_version = device_info.esphome_version
@ -769,7 +769,7 @@ class EsphomeBaseEntity(Entity):
return self._entry_data.old_info[self._component_key].get(self._key) return self._entry_data.old_info[self._component_key].get(self._key)
@property @property
def _device_info(self) -> DeviceInfo: def _device_info(self) -> EsphomeDeviceInfo:
return self._entry_data.device_info return self._entry_data.device_info
@property @property
@ -803,7 +803,7 @@ class EsphomeBaseEntity(Entity):
return self._static_info.unique_id return self._static_info.unique_id
@property @property
def device_info(self) -> dict[str, Any]: def device_info(self) -> DeviceInfo:
"""Return device registry information for this entity.""" """Return device registry information for this entity."""
return { return {
"connections": {(dr.CONNECTION_NETWORK_MAC, self._device_info.mac_address)} "connections": {(dr.CONNECTION_NETWORK_MAC, self._device_info.mac_address)}

View File

@ -16,6 +16,7 @@ from homeassistant.const import (
HTTP_OK, HTTP_OK,
) )
from homeassistant.core import Context, HomeAssistant from homeassistant.core import Context, HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.json import JSONEncoder from homeassistant.helpers.json import JSONEncoder
from .const import ( from .const import (
@ -166,12 +167,12 @@ def webhook_response(
) )
def device_info(registration: dict) -> dict: def device_info(registration: dict) -> DeviceInfo:
"""Return the device info for this registration.""" """Return the device info for this registration."""
return { return {
"identifiers": {(DOMAIN, registration[ATTR_DEVICE_ID])}, "identifiers": {(DOMAIN, registration[ATTR_DEVICE_ID])},
"manufacturer": registration[ATTR_MANUFACTURER], "manufacturer": registration[ATTR_MANUFACTURER],
"model": registration[ATTR_MODEL], "model": registration[ATTR_MODEL],
"device_name": registration[ATTR_DEVICE_NAME], "name": registration[ATTR_DEVICE_NAME],
"sw_version": registration[ATTR_OS_VERSION], "sw_version": registration[ATTR_OS_VERSION],
} }

View File

@ -28,7 +28,7 @@ class OneWireBaseEntity(Entity):
device_file, device_file,
entity_type: str, entity_type: str,
entity_name: str = None, entity_name: str = None,
device_info=None, device_info: DeviceInfo | None = None,
default_disabled: bool = False, default_disabled: bool = False,
unique_id: str = None, unique_id: str = None,
): ):
@ -82,7 +82,7 @@ class OneWireProxyEntity(OneWireBaseEntity):
self, self,
device_id: str, device_id: str,
device_name: str, device_name: str,
device_info: dict[str, Any], device_info: DeviceInfo,
entity_path: str, entity_path: str,
entity_specs: dict[str, Any], entity_specs: dict[str, Any],
owproxy: protocol._Proxy, owproxy: protocol._Proxy,

View File

@ -8,6 +8,7 @@ from starline import StarlineApi, StarlineDevice
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from .const import ( from .const import (
@ -125,7 +126,7 @@ class StarlineAccount:
self._unsubscribe_auto_obd_updater = None self._unsubscribe_auto_obd_updater = None
@staticmethod @staticmethod
def device_info(device: StarlineDevice) -> dict[str, Any]: def device_info(device: StarlineDevice) -> DeviceInfo:
"""Device information for entities.""" """Device information for entities."""
return { return {
"identifiers": {(DOMAIN, device.device_id)}, "identifiers": {(DOMAIN, device.device_id)},