Use DeviceInfo in xiaomi-miio (#58642)

This commit is contained in:
epenet 2021-10-29 00:37:55 +02:00 committed by GitHub
parent 638bd743a5
commit 335fdf96ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 25 deletions

View File

@ -14,6 +14,7 @@ from homeassistant.const import (
STATE_ALARM_ARMING, STATE_ALARM_ARMING,
STATE_ALARM_DISARMED, STATE_ALARM_DISARMED,
) )
from homeassistant.helpers.entity import DeviceInfo
from .const import CONF_GATEWAY, DOMAIN from .const import CONF_GATEWAY, DOMAIN
@ -65,11 +66,11 @@ class XiaomiGatewayAlarm(AlarmControlPanelEntity):
return self._gateway_device_id return self._gateway_device_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device info of the gateway.""" """Return the device info of the gateway."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self._gateway_device_id)}, identifiers={(DOMAIN, self._gateway_device_id)},
} )
@property @property
def name(self): def name(self):

View File

@ -7,8 +7,9 @@ import logging
from construct.core import ChecksumError from construct.core import ChecksumError
from miio import Device, DeviceException from miio import Device, DeviceException
from homeassistant.const import ATTR_CONNECTIONS
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import CONF_MAC, CONF_MODEL, DOMAIN, AuthException, SetupException from .const import CONF_MAC, CONF_MODEL, DOMAIN, AuthException, SetupException
@ -85,17 +86,17 @@ class XiaomiMiioEntity(Entity):
return self._name return self._name
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device info.""" """Return the device info."""
device_info = { device_info = DeviceInfo(
"identifiers": {(DOMAIN, self._device_id)}, identifiers={(DOMAIN, self._device_id)},
"manufacturer": "Xiaomi", manufacturer="Xiaomi",
"name": self._name, model=self._model,
"model": self._model, name=self._name,
} )
if self._mac is not None: if self._mac is not None:
device_info["connections"] = {(dr.CONNECTION_NETWORK_MAC, self._mac)} device_info[ATTR_CONNECTIONS] = {(dr.CONNECTION_NETWORK_MAC, self._mac)}
return device_info return device_info
@ -125,17 +126,17 @@ class XiaomiCoordinatedMiioEntity(CoordinatorEntity):
return self._name return self._name
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device info.""" """Return the device info."""
device_info = { device_info = DeviceInfo(
"identifiers": {(DOMAIN, self._device_id)}, identifiers={(DOMAIN, self._device_id)},
"manufacturer": "Xiaomi", manufacturer="Xiaomi",
"name": self._device_name, model=self._model,
"model": self._model, name=self._device_name,
} )
if self._mac is not None: if self._mac is not None:
device_info["connections"] = {(dr.CONNECTION_NETWORK_MAC, self._mac)} device_info[ATTR_CONNECTIONS] = {(dr.CONNECTION_NETWORK_MAC, self._mac)}
return device_info return device_info

View File

@ -26,6 +26,7 @@ from homeassistant.components.light import (
) )
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_TOKEN from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_TOKEN
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.util import color, dt from homeassistant.util import color, dt
from .const import ( from .const import (
@ -944,11 +945,11 @@ class XiaomiGatewayLight(LightEntity):
return self._unique_id return self._unique_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device info of the gateway.""" """Return the device info of the gateway."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self._gateway_device_id)}, identifiers={(DOMAIN, self._gateway_device_id)},
} )
@property @property
def name(self): def name(self):