From f9c3746e6ac194f0fa6f9fd51c47375f2eaec28b Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Sun, 24 Oct 2021 10:03:50 -0400 Subject: [PATCH 1/4] Use DeviceInfo Class S --- .../components/samsungtv/media_player.py | 37 +++++++++++-------- .../components/screenlogic/__init__.py | 33 ++++++++--------- homeassistant/components/sharkiq/vacuum.py | 14 +++---- homeassistant/components/shelly/entity.py | 30 ++++++--------- homeassistant/components/sma/sensor.py | 16 ++++---- .../components/smappee/binary_sensor.py | 33 +++++++++-------- homeassistant/components/smappee/sensor.py | 17 +++++---- homeassistant/components/smappee/switch.py | 17 +++++---- .../components/smartthings/__init__.py | 18 ++++----- homeassistant/components/smarttub/entity.py | 14 +++---- homeassistant/components/sms/sensor.py | 9 +++-- homeassistant/components/solarlog/sensor.py | 12 +++--- homeassistant/components/soma/__init__.py | 19 +++------- .../components/somfy_mylink/cover.py | 15 +++----- .../components/songpal/media_player.py | 19 +++++----- .../components/speedtestdotnet/sensor.py | 4 +- homeassistant/components/spider/climate.py | 17 ++++----- homeassistant/components/spider/sensor.py | 32 ++++++---------- homeassistant/components/spider/switch.py | 17 ++++----- .../components/spotify/media_player.py | 23 ++++-------- homeassistant/components/starline/account.py | 14 +++---- .../components/stookalert/binary_sensor.py | 6 +-- homeassistant/components/subaru/entity.py | 15 +++----- homeassistant/components/switchbot/entity.py | 12 +++--- .../components/switcher_kis/switch.py | 7 ++-- homeassistant/components/syncthing/sensor.py | 17 +++++---- .../components/syncthru/binary_sensor.py | 9 ++--- homeassistant/components/syncthru/sensor.py | 9 ++--- .../components/synology_dsm/__init__.py | 8 ++-- .../components/system_bridge/__init__.py | 14 +++---- 30 files changed, 233 insertions(+), 274 deletions(-) diff --git a/homeassistant/components/samsungtv/media_player.py b/homeassistant/components/samsungtv/media_player.py index cab6435af95d6..f9356e39b9907 100644 --- a/homeassistant/components/samsungtv/media_player.py +++ b/homeassistant/components/samsungtv/media_player.py @@ -27,7 +27,15 @@ SamsungTVWSBridge, ) from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry -from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, STATE_OFF, STATE_ON +from homeassistant.const import ( + ATTR_CONNECTIONS, + ATTR_IDENTIFIERS, + CONF_HOST, + CONF_MAC, + CONF_NAME, + STATE_OFF, + STATE_ON, +) from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_component import homeassistant.helpers.config_validation as cv @@ -115,6 +123,19 @@ def __init__( self._bridge = bridge self._auth_failed = False self._bridge.register_reauth_callback(self.access_denied) + self._attr_device_info = DeviceInfo( + name=self.name, + manufacturer=self._manufacturer, + model=self._model, + ) + if self._mac: + self._attr_device_info[ATTR_CONNECTIONS] = { + (CONNECTION_NETWORK_MAC, self._mac) + } + if config_entry.unique_id: + self._attr_device_info[ATTR_IDENTIFIERS] = { + (DOMAIN, config_entry.unique_id) + } def access_denied(self) -> None: """Access denied callback.""" @@ -180,20 +201,6 @@ def available(self) -> bool: or self._power_off_in_progress() ) - @property - def device_info(self) -> DeviceInfo | None: - """Return device specific attributes.""" - info: DeviceInfo = { - "name": self.name, - "manufacturer": self._manufacturer, - "model": self._model, - } - if self.unique_id: - info["identifiers"] = {(DOMAIN, self.unique_id)} - if self._mac: - info["connections"] = {(CONNECTION_NETWORK_MAC, self._mac)} - return info - @property def is_volume_muted(self) -> bool: """Boolean if volume is currently muted.""" diff --git a/homeassistant/components/screenlogic/__init__.py b/homeassistant/components/screenlogic/__init__.py index 2178cf7ec2cce..37fc20b8ab0de 100644 --- a/homeassistant/components/screenlogic/__init__.py +++ b/homeassistant/components/screenlogic/__init__.py @@ -19,6 +19,7 @@ from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import device_registry as dr from homeassistant.helpers.debounce import Debouncer +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, @@ -183,6 +184,20 @@ def __init__(self, coordinator, data_key, enabled=True): super().__init__(coordinator) self._data_key = data_key self._enabled_default = enabled + controller_type = self.config_data["controller_type"] + hardware_type = self.config_data["hardware_type"] + try: + equipment_model = EQUIPMENT.CONTROLLER_HARDWARE[controller_type][ + hardware_type + ] + except KeyError: + equipment_model = f"Unknown Model C:{controller_type} H:{hardware_type}" + self._attr_device_info = DeviceInfo( + connections={(dr.CONNECTION_NETWORK_MAC, self.mac)}, + manufacturer="Pentair", + model=equipment_model, + name=self.gateway_name, + ) @property def entity_registry_enabled_default(self): @@ -214,24 +229,6 @@ def gateway_name(self): """Return the configured name of the gateway.""" return self.gateway.name - @property - def device_info(self): - """Return device information for the controller.""" - controller_type = self.config_data["controller_type"] - hardware_type = self.config_data["hardware_type"] - try: - equipment_model = EQUIPMENT.CONTROLLER_HARDWARE[controller_type][ - hardware_type - ] - except KeyError: - equipment_model = f"Unknown Model C:{controller_type} H:{hardware_type}" - return { - "connections": {(dr.CONNECTION_NETWORK_MAC, self.mac)}, - "name": self.gateway_name, - "manufacturer": "Pentair", - "model": equipment_model, - } - class ScreenLogicCircuitEntity(ScreenlogicEntity): """ScreenLogic circuit entity.""" diff --git a/homeassistant/components/sharkiq/vacuum.py b/homeassistant/components/sharkiq/vacuum.py index 4ecdf217abc0c..3851dab7303ea 100644 --- a/homeassistant/components/sharkiq/vacuum.py +++ b/homeassistant/components/sharkiq/vacuum.py @@ -123,15 +123,15 @@ def model(self) -> str: @property def device_info(self) -> DeviceInfo: """Device info dictionary.""" - return { - "identifiers": {(DOMAIN, self.serial_number)}, - "name": self.name, - "manufacturer": SHARK, - "model": self.model, - "sw_version": self.sharkiq.get_property_value( + return DeviceInfo( + identifiers={(DOMAIN, self.serial_number)}, + manufacturer=SHARK, + model=self.model, + name=self.name, + sw_version=self.sharkiq.get_property_value( Properties.ROBOT_FIRMWARE_VERSION ), - } + ) @property def supported_features(self) -> int: diff --git a/homeassistant/components/shelly/entity.py b/homeassistant/components/shelly/entity.py index 0a610545180f3..28a2c1bf9c398 100644 --- a/homeassistant/components/shelly/entity.py +++ b/homeassistant/components/shelly/entity.py @@ -282,6 +282,9 @@ def __init__(self, wrapper: BlockDeviceWrapper, block: Block) -> None: self.wrapper = wrapper self.block = block self._name = get_block_entity_name(wrapper.device, block) + self._attr_device_info = DeviceInfo( + connections={(device_registry.CONNECTION_NETWORK_MAC, wrapper.mac)} + ) @property def name(self) -> str: @@ -293,13 +296,6 @@ def should_poll(self) -> bool: """If device should be polled.""" return False - @property - def device_info(self) -> DeviceInfo: - """Device info.""" - return { - "connections": {(device_registry.CONNECTION_NETWORK_MAC, self.wrapper.mac)} - } - @property def available(self) -> bool: """Available.""" @@ -348,16 +344,16 @@ def __init__(self, wrapper: RpcDeviceWrapper, key: str) -> None: self.wrapper = wrapper self.key = key self._attr_should_poll = False - self._attr_device_info = { - "connections": {(device_registry.CONNECTION_NETWORK_MAC, wrapper.mac)} - } + self._attr_device_info = DeviceInfo( + connections={(device_registry.CONNECTION_NETWORK_MAC, wrapper.mac)} + ) self._attr_unique_id = f"{wrapper.mac}-{key}" self._attr_name = get_rpc_entity_name(wrapper.device, key) @property def available(self) -> bool: """Available.""" - return self.wrapper.device.connected + return cast(bool, self.wrapper.device.connected) async def async_added_to_hass(self) -> None: """When entity is added to HASS.""" @@ -494,19 +490,15 @@ def __init__( self.description = description self._name = get_block_entity_name(wrapper.device, None, self.description.name) self._last_value = None + self._attr_device_info = DeviceInfo( + connections={(device_registry.CONNECTION_NETWORK_MAC, wrapper.mac)} + ) @property def name(self) -> str: """Name of sensor.""" return self._name - @property - def device_info(self) -> DeviceInfo: - """Device info.""" - return { - "connections": {(device_registry.CONNECTION_NETWORK_MAC, self.wrapper.mac)} - } - @property def entity_registry_enabled_default(self) -> bool: """Return if it should be enabled by default.""" @@ -639,7 +631,7 @@ def __init__( self.last_state: StateType = None self.wrapper = wrapper self.attribute = attribute - self.block: Block | None = block # type: ignore[assignment] + self.block: Block | None = block self.description = description self._unit = self.description.unit diff --git a/homeassistant/components/sma/sensor.py b/homeassistant/components/sma/sensor.py index 922ec9f92121c..853edee823cf4 100644 --- a/homeassistant/components/sma/sensor.py +++ b/homeassistant/components/sma/sensor.py @@ -200,18 +200,18 @@ def unique_id(self) -> str: ) @property - def device_info(self) -> DeviceInfo: + def device_info(self) -> DeviceInfo | None: """Return the device information.""" if not self._device_info: return None - return { - "identifiers": {(DOMAIN, self._config_entry_unique_id)}, - "name": self._device_info["name"], - "manufacturer": self._device_info["manufacturer"], - "model": self._device_info["type"], - "sw_version": self._device_info["sw_version"], - } + return DeviceInfo( + identifiers={(DOMAIN, self._config_entry_unique_id)}, + manufacturer=self._device_info["manufacturer"], + model=self._device_info["type"], + name=self._device_info["name"], + sw_version=self._device_info["sw_version"], + ) @property def entity_registry_enabled_default(self) -> bool: diff --git a/homeassistant/components/smappee/binary_sensor.py b/homeassistant/components/smappee/binary_sensor.py index 4cc5cca9a23aa..7e46a1021e515 100644 --- a/homeassistant/components/smappee/binary_sensor.py +++ b/homeassistant/components/smappee/binary_sensor.py @@ -3,6 +3,7 @@ DEVICE_CLASS_PRESENCE, BinarySensorEntity, ) +from homeassistant.helpers.entity import DeviceInfo from .const import DOMAIN @@ -71,15 +72,15 @@ def unique_id( ) @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info for this binary sensor.""" - return { - "identifiers": {(DOMAIN, self._service_location.device_serial_number)}, - "name": self._service_location.service_location_name, - "manufacturer": "Smappee", - "model": self._service_location.device_model, - "sw_version": self._service_location.firmware_version, - } + return DeviceInfo( + identifiers={(DOMAIN, self._service_location.device_serial_number)}, + manufacturer="Smappee", + model=self._service_location.device_model, + name=self._service_location.service_location_name, + sw_version=self._service_location.firmware_version, + ) async def async_update(self): """Get the latest data from Smappee and update the state.""" @@ -154,15 +155,15 @@ def unique_id( ) @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info for this binary sensor.""" - return { - "identifiers": {(DOMAIN, self._service_location.device_serial_number)}, - "name": self._service_location.service_location_name, - "manufacturer": "Smappee", - "model": self._service_location.device_model, - "sw_version": self._service_location.firmware_version, - } + return DeviceInfo( + identifiers={(DOMAIN, self._service_location.device_serial_number)}, + manufacturer="Smappee", + model=self._service_location.device_model, + name=self._service_location.service_location_name, + sw_version=self._service_location.firmware_version, + ) async def async_update(self): """Get the latest data from Smappee and update the state.""" diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index af66b788a4131..276248fd6ae75 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -18,6 +18,7 @@ ENERGY_WATT_HOUR, POWER_WATT, ) +from homeassistant.helpers.entity import DeviceInfo from .const import DOMAIN @@ -372,15 +373,15 @@ def unique_id(self): ) @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info for this sensor.""" - return { - "identifiers": {(DOMAIN, self._service_location.device_serial_number)}, - "name": self._service_location.service_location_name, - "manufacturer": "Smappee", - "model": self._service_location.device_model, - "sw_version": self._service_location.firmware_version, - } + return DeviceInfo( + identifiers={(DOMAIN, self._service_location.device_serial_number)}, + manufacturer="Smappee", + model=self._service_location.device_model, + name=self._service_location.service_location_name, + sw_version=self._service_location.firmware_version, + ) async def async_update(self): """Get the latest data from Smappee and update the state.""" diff --git a/homeassistant/components/smappee/switch.py b/homeassistant/components/smappee/switch.py index ded898f9f104e..3376523598b79 100644 --- a/homeassistant/components/smappee/switch.py +++ b/homeassistant/components/smappee/switch.py @@ -1,5 +1,6 @@ """Support for interacting with Smappee Comport Plugs, Switches and Output Modules.""" from homeassistant.components.switch import SwitchEntity +from homeassistant.helpers.entity import DeviceInfo from .const import DOMAIN @@ -148,15 +149,15 @@ def unique_id( ) @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info for this switch.""" - return { - "identifiers": {(DOMAIN, self._service_location.device_serial_number)}, - "name": self._service_location.service_location_name, - "manufacturer": "Smappee", - "model": self._service_location.device_model, - "sw_version": self._service_location.firmware_version, - } + return DeviceInfo( + identifiers={(DOMAIN, self._service_location.device_serial_number)}, + name=self._service_location.service_location_name, + manufacturer="Smappee", + model=self._service_location.device_model, + sw_version=self._service_location.firmware_version, + ) async def async_update(self): """Get the latest data from Smappee and update the state.""" diff --git a/homeassistant/components/smartthings/__init__.py b/homeassistant/components/smartthings/__init__.py index eb3aa9cb0f0ef..96eb70fa23afc 100644 --- a/homeassistant/components/smartthings/__init__.py +++ b/homeassistant/components/smartthings/__init__.py @@ -21,7 +21,7 @@ async_dispatcher_connect, async_dispatcher_send, ) -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.typing import ConfigType @@ -409,6 +409,12 @@ def __init__(self, device: DeviceEntity) -> None: """Initialize the instance.""" self._device = device self._dispatcher_remove = None + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, device.device_id)}, + manufacturer="Unavailable", + model=device.device_type_name, + name=device.label, + ) async def async_added_to_hass(self): """Device added to hass.""" @@ -427,16 +433,6 @@ async def async_will_remove_from_hass(self) -> None: if self._dispatcher_remove: self._dispatcher_remove() - @property - def device_info(self): - """Get attributes about the device.""" - return { - "identifiers": {(DOMAIN, self._device.device_id)}, - "name": self._device.label, - "model": self._device.device_type_name, - "manufacturer": "Unavailable", - } - @property def name(self) -> str: """Return the name of the device.""" diff --git a/homeassistant/components/smarttub/entity.py b/homeassistant/components/smarttub/entity.py index 49d5e94d76e55..bcaaeb7db8684 100644 --- a/homeassistant/components/smarttub/entity.py +++ b/homeassistant/components/smarttub/entity.py @@ -26,21 +26,17 @@ def __init__( super().__init__(coordinator) self.spa = spa self._entity_name = entity_name + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, spa.id)}, + manufacturer=spa.brand, + model=spa.model, + ) @property def unique_id(self) -> str: """Return a unique id for the entity.""" return f"{self.spa.id}-{self._entity_name}" - @property - def device_info(self) -> DeviceInfo: - """Return device info.""" - return { - "identifiers": {(DOMAIN, self.spa.id)}, - "manufacturer": self.spa.brand, - "model": self.spa.model, - } - @property def name(self) -> str: """Return the name of the entity.""" diff --git a/homeassistant/components/sms/sensor.py b/homeassistant/components/sms/sensor.py index d405c8176566c..f5152ac74625d 100644 --- a/homeassistant/components/sms/sensor.py +++ b/homeassistant/components/sms/sensor.py @@ -5,6 +5,7 @@ from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.const import DEVICE_CLASS_SIGNAL_STRENGTH, SIGNAL_STRENGTH_DECIBELS +from homeassistant.helpers.entity import DeviceInfo from .const import DOMAIN, SMS_GATEWAY @@ -39,10 +40,10 @@ class GSMSignalSensor(SensorEntity): def __init__(self, hass, gateway, imei, description): """Initialize the GSM Signal sensor.""" - self._attr_device_info = { - "identifiers": {(DOMAIN, str(imei))}, - "name": "SMS Gateway", - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, str(imei))}, + name="SMS Gateway", + ) self._attr_unique_id = str(imei) self._hass = hass self._gateway = gateway diff --git a/homeassistant/components/solarlog/sensor.py b/homeassistant/components/solarlog/sensor.py index 5918c397a7b4d..d54845f8027f6 100644 --- a/homeassistant/components/solarlog/sensor.py +++ b/homeassistant/components/solarlog/sensor.py @@ -1,7 +1,7 @@ """Platform for solarlog sensors.""" from homeassistant.components.sensor import SensorEntity from homeassistant.helpers import update_coordinator -from homeassistant.helpers.entity import StateType +from homeassistant.helpers.entity import DeviceInfo, StateType from . import SolarlogData from .const import DOMAIN, SENSOR_TYPES, SolarLogSensorEntityDescription @@ -30,11 +30,11 @@ def __init__( self.entity_description = description self._attr_name = f"{coordinator.name} {description.name}" self._attr_unique_id = f"{coordinator.unique_id}_{description.key}" - self._attr_device_info = { - "identifiers": {(DOMAIN, coordinator.unique_id)}, - "name": coordinator.name, - "manufacturer": "Solar-Log", - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, coordinator.unique_id)}, + manufacturer="Solar-Log", + name=coordinator.name, + ) @property def native_value(self) -> StateType: diff --git a/homeassistant/components/soma/__init__.py b/homeassistant/components/soma/__init__.py index 77ecd3af96bfe..b8ec17519745a 100644 --- a/homeassistant/components/soma/__init__.py +++ b/homeassistant/components/soma/__init__.py @@ -8,7 +8,7 @@ from homeassistant.const import CONF_HOST, CONF_PORT from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import DeviceInfo, Entity from .const import API, DOMAIN, HOST, PORT @@ -72,6 +72,11 @@ def __init__(self, device, api): self.current_position = 50 self.battery_state = 0 self.is_available = True + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, self.unique_id)}, + manufacturer="Wazombi Labs", + name=self.name, + ) @property def available(self): @@ -87,15 +92,3 @@ def unique_id(self): def name(self): """Return the name of the device.""" return self.device["name"] - - @property - def device_info(self): - """Return device specific attributes. - - Implemented by platform classes. - """ - return { - "identifiers": {(DOMAIN, self.unique_id)}, - "name": self.name, - "manufacturer": "Wazombi Labs", - } diff --git a/homeassistant/components/somfy_mylink/cover.py b/homeassistant/components/somfy_mylink/cover.py index 2725e2da9c7a6..4f7ba17d3a102 100644 --- a/homeassistant/components/somfy_mylink/cover.py +++ b/homeassistant/components/somfy_mylink/cover.py @@ -8,6 +8,7 @@ CoverEntity, ) from homeassistant.const import STATE_CLOSED, STATE_OPEN +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.restore_state import RestoreEntity from .const import ( @@ -73,6 +74,11 @@ def __init__( self._is_opening = None self._is_closing = None self._device_class = device_class + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, target_id)}, + manufacturer=MANUFACTURER, + name=name, + ) @property def should_poll(self): @@ -114,15 +120,6 @@ def is_closed(self) -> bool: """Return if the cover is closed.""" return self._closed - @property - def device_info(self): - """Return the device_info of the device.""" - return { - "identifiers": {(DOMAIN, self._target_id)}, - "name": self._name, - "manufacturer": MANUFACTURER, - } - async def async_close_cover(self, **kwargs): """Close the cover.""" self._is_closing = True diff --git a/homeassistant/components/songpal/media_player.py b/homeassistant/components/songpal/media_player.py index 1746d5ece0dd4..b13ca99cd5b0f 100644 --- a/homeassistant/components/songpal/media_player.py +++ b/homeassistant/components/songpal/media_player.py @@ -32,6 +32,7 @@ device_registry as dr, entity_platform, ) +from homeassistant.helpers.entity import DeviceInfo from .const import CONF_ENDPOINT, DOMAIN, SET_SOUND_SETTING @@ -205,16 +206,16 @@ def unique_id(self): return self._sysinfo.macAddr @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info.""" - return { - "connections": {(dr.CONNECTION_NETWORK_MAC, self._sysinfo.macAddr)}, - "identifiers": {(DOMAIN, self.unique_id)}, - "manufacturer": "Sony Corporation", - "name": self.name, - "sw_version": self._sysinfo.version, - "model": self._model, - } + return DeviceInfo( + connections={(dr.CONNECTION_NETWORK_MAC, self._sysinfo.macAddr)}, + identifiers={(DOMAIN, self.unique_id)}, + manufacturer="Sony Corporation", + model=self._model, + name=self.name, + sw_version=self._sysinfo.version, + ) @property def available(self): diff --git a/homeassistant/components/speedtestdotnet/sensor.py b/homeassistant/components/speedtestdotnet/sensor.py index 06f180a570f17..1c4bdc51f3c35 100644 --- a/homeassistant/components/speedtestdotnet/sensor.py +++ b/homeassistant/components/speedtestdotnet/sensor.py @@ -62,10 +62,10 @@ def __init__( self._state: StateType = None self._attrs = {ATTR_ATTRIBUTION: ATTRIBUTION} self._attr_device_info = DeviceInfo( + configuration_url="https://www.speedtest.net/", + entry_type="service", identifiers={(DOMAIN, self.coordinator.config_entry.entry_id)}, name=DEFAULT_NAME, - entry_type="service", - configuration_url="https://www.speedtest.net/", ) @property diff --git a/homeassistant/components/spider/climate.py b/homeassistant/components/spider/climate.py index 52146518ee359..8e90ccb741bbe 100644 --- a/homeassistant/components/spider/climate.py +++ b/homeassistant/components/spider/climate.py @@ -8,6 +8,7 @@ SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.helpers.entity import DeviceInfo from .const import DOMAIN @@ -43,16 +44,12 @@ def __init__(self, api, thermostat): """Initialize the thermostat.""" self.api = api self.thermostat = thermostat - - @property - def device_info(self): - """Return the device_info of the device.""" - return { - "identifiers": {(DOMAIN, self.thermostat.id)}, - "name": self.thermostat.name, - "manufacturer": self.thermostat.manufacturer, - "model": self.thermostat.model, - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, self.thermostat.id)}, + manufacturer=self.thermostat.manufacturer, + model=self.thermostat.model, + name=self.thermostat.name, + ) @property def supported_features(self): diff --git a/homeassistant/components/spider/sensor.py b/homeassistant/components/spider/sensor.py index 8b38fdbe6f689..2b52d9232baba 100644 --- a/homeassistant/components/spider/sensor.py +++ b/homeassistant/components/spider/sensor.py @@ -38,16 +38,12 @@ def __init__(self, api, power_plug) -> None: """Initialize the Spider Power Plug.""" self.api = api self.power_plug = power_plug - - @property - def device_info(self) -> DeviceInfo: - """Return the device_info of the device.""" - return { - "identifiers": {(DOMAIN, self.power_plug.id)}, - "name": self.power_plug.name, - "manufacturer": self.power_plug.manufacturer, - "model": self.power_plug.model, - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, self.power_plug.id)}, + manufacturer=self.power_plug.manufacturer, + model=self.power_plug.model, + name=self.power_plug.name, + ) @property def unique_id(self) -> str: @@ -80,16 +76,12 @@ def __init__(self, api, power_plug) -> None: """Initialize the Spider Power Plug.""" self.api = api self.power_plug = power_plug - - @property - def device_info(self) -> DeviceInfo: - """Return the device_info of the device.""" - return { - "identifiers": {(DOMAIN, self.power_plug.id)}, - "name": self.power_plug.name, - "manufacturer": self.power_plug.manufacturer, - "model": self.power_plug.model, - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, power_plug.id)}, + manufacturer=power_plug.manufacturer, + model=power_plug.model, + name=power_plug.name, + ) @property def unique_id(self) -> str: diff --git a/homeassistant/components/spider/switch.py b/homeassistant/components/spider/switch.py index ceb814b234a37..e3fec17c68faf 100644 --- a/homeassistant/components/spider/switch.py +++ b/homeassistant/components/spider/switch.py @@ -1,5 +1,6 @@ """Support for Spider switches.""" from homeassistant.components.switch import SwitchEntity +from homeassistant.helpers.entity import DeviceInfo from .const import DOMAIN @@ -22,16 +23,12 @@ def __init__(self, api, power_plug): """Initialize the Spider Power Plug.""" self.api = api self.power_plug = power_plug - - @property - def device_info(self): - """Return the device_info of the device.""" - return { - "identifiers": {(DOMAIN, self.power_plug.id)}, - "name": self.power_plug.name, - "manufacturer": self.power_plug.manufacturer, - "model": self.power_plug.model, - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, self.power_plug.id)}, + manufacturer=self.power_plug.manufacturer, + model=self.power_plug.model, + name=self.power_plug.name, + ) @property def unique_id(self): diff --git a/homeassistant/components/spotify/media_player.py b/homeassistant/components/spotify/media_player.py index 029f7dc9e8b05..ac0bd4704a041 100644 --- a/homeassistant/components/spotify/media_player.py +++ b/homeassistant/components/spotify/media_player.py @@ -238,9 +238,7 @@ def __init__( name: str, ) -> None: """Initialize.""" - self._id = user_id self._me = me - self._name = f"Spotify {name}" self._session = session self._spotify = spotify self._scope_ok = set(session.token["scope"].split(" ")).issuperset( @@ -251,24 +249,19 @@ def __init__( self._devices: list[dict] | None = [] self._playlist: dict | None = None - self._attr_name = self._name + self._attr_name = f"Spotify {name}" self._attr_unique_id = user_id - - @property - def device_info(self) -> DeviceInfo: - """Return device information about this entity.""" model = "Spotify Free" - if self._me is not None: - product = self._me["product"] + if me is not None: + product = me["product"] model = f"Spotify {product}" - - return DeviceInfo( - identifiers={(DOMAIN, self._id)}, + self._attr_device_info = DeviceInfo( + configuration_url="https://open.spotify.com", + entry_type="service", + identifiers={(DOMAIN, user_id)}, manufacturer="Spotify AB", model=model, - name=self._name, - entry_type="service", - configuration_url="https://open.spotify.com", + name=f"Spotify {name}", ) @property diff --git a/homeassistant/components/starline/account.py b/homeassistant/components/starline/account.py index 9033375ce907b..920c9214aeca5 100644 --- a/homeassistant/components/starline/account.py +++ b/homeassistant/components/starline/account.py @@ -129,13 +129,13 @@ def unload(self): @staticmethod def device_info(device: StarlineDevice) -> DeviceInfo: """Device information for entities.""" - return { - "identifiers": {(DOMAIN, device.device_id)}, - "manufacturer": "StarLine", - "name": device.name, - "sw_version": device.fw_version, - "model": device.typename, - } + return DeviceInfo( + identifiers={(DOMAIN, device.device_id)}, + manufacturer="StarLine", + model=device.typename, + name=device.name, + sw_version=device.fw_version, + ) @staticmethod def gps_attrs(device: StarlineDevice) -> dict[str, Any]: diff --git a/homeassistant/components/stookalert/binary_sensor.py b/homeassistant/components/stookalert/binary_sensor.py index b75790cef8af3..54fac6cc633d0 100644 --- a/homeassistant/components/stookalert/binary_sensor.py +++ b/homeassistant/components/stookalert/binary_sensor.py @@ -79,12 +79,12 @@ def __init__(self, client: stookalert.stookalert, entry: ConfigEntry) -> None: self._attr_name = f"Stookalert {entry.data[CONF_PROVINCE]}" self._attr_unique_id = entry.unique_id self._attr_device_info = DeviceInfo( + entry_type=ENTRY_TYPE_SERVICE, + configuration_url="https://www.rivm.nl/stookalert", identifiers={(DOMAIN, f"{entry.entry_id}")}, - name=entry.data[CONF_PROVINCE], manufacturer="RIVM", model="Stookalert", - entry_type=ENTRY_TYPE_SERVICE, - configuration_url="https://www.rivm.nl/stookalert", + name=entry.data[CONF_PROVINCE], ) def update(self) -> None: diff --git a/homeassistant/components/subaru/entity.py b/homeassistant/components/subaru/entity.py index 559feeea303ca..f7f18d5bf57f6 100644 --- a/homeassistant/components/subaru/entity.py +++ b/homeassistant/components/subaru/entity.py @@ -1,4 +1,5 @@ """Base class for all Subaru Entities.""" +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN, MANUFACTURER, VEHICLE_NAME, VEHICLE_VIN @@ -13,6 +14,11 @@ def __init__(self, vehicle_info, coordinator): self.car_name = vehicle_info[VEHICLE_NAME] self.vin = vehicle_info[VEHICLE_VIN] self.entity_type = "entity" + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, vehicle_info[VEHICLE_VIN])}, + manufacturer=MANUFACTURER, + name=vehicle_info[VEHICLE_NAME], + ) @property def name(self): @@ -23,12 +29,3 @@ def name(self): def unique_id(self) -> str: """Return a unique ID.""" return f"{self.vin}_{self.entity_type}" - - @property - def device_info(self): - """Return the device_info of the device.""" - return { - "identifiers": {(DOMAIN, self.vin)}, - "name": self.car_name, - "manufacturer": MANUFACTURER, - } diff --git a/homeassistant/components/switchbot/entity.py b/homeassistant/components/switchbot/entity.py index d6e88174d793b..688cfea6a8620 100644 --- a/homeassistant/components/switchbot/entity.py +++ b/homeassistant/components/switchbot/entity.py @@ -28,12 +28,12 @@ def __init__( self._idx = idx self._mac = mac self._attr_name = name - self._attr_device_info: DeviceInfo = { - "connections": {(dr.CONNECTION_NETWORK_MAC, self._mac)}, - "name": name, - "model": self.data["modelName"], - "manufacturer": MANUFACTURER, - } + self._attr_device_info = DeviceInfo( + connections={(dr.CONNECTION_NETWORK_MAC, self._mac)}, + manufacturer=MANUFACTURER, + model=self.data["modelName"], + name=name, + ) @property def data(self) -> dict[str, Any]: diff --git a/homeassistant/components/switcher_kis/switch.py b/homeassistant/components/switcher_kis/switch.py index 8b93e422e2a20..620a742f4e37a 100644 --- a/homeassistant/components/switcher_kis/switch.py +++ b/homeassistant/components/switcher_kis/switch.py @@ -23,6 +23,7 @@ entity_platform, ) from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -92,11 +93,11 @@ def __init__(self, coordinator: SwitcherDataUpdateCoordinator) -> None: # Entity class attributes self._attr_name = coordinator.name self._attr_unique_id = f"{coordinator.device_id}-{coordinator.mac_address}" - self._attr_device_info = { - "connections": { + self._attr_device_info = DeviceInfo( + connections={ (device_registry.CONNECTION_NETWORK_MAC, coordinator.mac_address) } - } + ) @callback def _handle_coordinator_update(self) -> None: diff --git a/homeassistant/components/syncthing/sensor.py b/homeassistant/components/syncthing/sensor.py index e88636b814bb2..192b4c5c39546 100644 --- a/homeassistant/components/syncthing/sensor.py +++ b/homeassistant/components/syncthing/sensor.py @@ -6,6 +6,7 @@ from homeassistant.core import callback from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.event import async_track_time_interval from .const import ( @@ -130,15 +131,15 @@ def should_poll(self): return False @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return device information.""" - return { - "identifiers": {(DOMAIN, self._server_id)}, - "name": f"Syncthing ({self._syncthing.url})", - "manufacturer": "Syncthing Team", - "sw_version": self._version, - "entry_type": "service", - } + return DeviceInfo( + entry_type="service", + identifiers={(DOMAIN, self._server_id)}, + manufacturer="Syncthing Team", + name=f"Syncthing ({self._syncthing.url})", + sw_version=self._version, + ) async def async_update_status(self): """Request folder status and update state.""" diff --git a/homeassistant/components/syncthru/binary_sensor.py b/homeassistant/components/syncthru/binary_sensor.py index 1c402fbf836bc..edc03bfee6f82 100644 --- a/homeassistant/components/syncthru/binary_sensor.py +++ b/homeassistant/components/syncthru/binary_sensor.py @@ -8,6 +8,7 @@ BinarySensorEntity, ) from homeassistant.const import CONF_NAME +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -50,6 +51,9 @@ def __init__(self, coordinator, name): self.syncthru: SyncThru = coordinator.data self._name = name self._id_suffix = "" + self._attr_device_info = DeviceInfo( + identifiers=device_identifiers(self.syncthru) + ) @property def unique_id(self): @@ -62,11 +66,6 @@ def name(self): """Return the name of the sensor.""" return self._name - @property - def device_info(self): - """Return device information.""" - return {"identifiers": device_identifiers(self.syncthru)} - class SyncThruOnlineSensor(SyncThruBinarySensor): """Implementation of a sensor that checks whether is turned on/online.""" diff --git a/homeassistant/components/syncthru/sensor.py b/homeassistant/components/syncthru/sensor.py index cc832f77f0afb..f3c699b4d4d8e 100644 --- a/homeassistant/components/syncthru/sensor.py +++ b/homeassistant/components/syncthru/sensor.py @@ -9,6 +9,7 @@ from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import CONF_NAME, CONF_RESOURCE, CONF_URL, PERCENTAGE import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -106,6 +107,9 @@ def __init__(self, coordinator, name): self._icon = "mdi:printer" self._unit_of_measurement = None self._id_suffix = "" + self._attr_device_info = DeviceInfo( + identifiers=device_identifiers(self.syncthru) + ) @property def unique_id(self): @@ -128,11 +132,6 @@ def native_unit_of_measurement(self): """Return the unit of measuremnt.""" return self._unit_of_measurement - @property - def device_info(self): - """Return device information.""" - return {"identifiers": device_identifiers(self.syncthru)} - class SyncThruMainSensor(SyncThruSensor): """ diff --git a/homeassistant/components/synology_dsm/__init__.py b/homeassistant/components/synology_dsm/__init__.py index a8e35178be4d7..932353356124c 100644 --- a/homeassistant/components/synology_dsm/__init__.py +++ b/homeassistant/components/synology_dsm/__init__.py @@ -614,12 +614,12 @@ def __init__( def device_info(self) -> DeviceInfo: """Return the device information.""" return DeviceInfo( + configuration_url=self._api.config_url, identifiers={(DOMAIN, self._api.information.serial)}, - name="Synology NAS", manufacturer="Synology", model=self._api.information.model, + name="Synology NAS", sw_version=self._api.information.version_string, - configuration_url=self._api.config_url, ) async def async_added_to_hass(self) -> None: @@ -683,11 +683,11 @@ def available(self) -> bool: def device_info(self) -> DeviceInfo: """Return the device information.""" return DeviceInfo( + configuration_url=self._api.config_url, identifiers={(DOMAIN, f"{self._api.information.serial}_{self._device_id}")}, - name=f"Synology NAS ({self._device_name} - {self._device_type})", manufacturer=self._device_manufacturer, model=self._device_model, + name=f"Synology NAS ({self._device_name} - {self._device_type})", sw_version=self._device_firmware, via_device=(DOMAIN, self._api.information.serial), - configuration_url=self._api.config_url, ) diff --git a/homeassistant/components/system_bridge/__init__.py b/homeassistant/components/system_bridge/__init__.py index d1da463816f41..faea8b8418cdd 100644 --- a/homeassistant/components/system_bridge/__init__.py +++ b/homeassistant/components/system_bridge/__init__.py @@ -262,10 +262,10 @@ class SystemBridgeDeviceEntity(SystemBridgeEntity): @property def device_info(self) -> DeviceInfo: """Return device information about this System Bridge instance.""" - return { - "connections": {(dr.CONNECTION_NETWORK_MAC, self._mac)}, - "manufacturer": self._manufacturer, - "model": self._model, - "name": self._hostname, - "sw_version": self._version, - } + return DeviceInfo( + connections={(dr.CONNECTION_NETWORK_MAC, self._mac)}, + manufacturer=self._manufacturer, + model=self._model, + name=self._hostname, + sw_version=self._version, + ) From d09e4f3518fdfefbe502578242265e00da794ba2 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Sun, 24 Oct 2021 10:58:55 -0400 Subject: [PATCH 2/4] mypy --- homeassistant/components/shelly/entity.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/shelly/entity.py b/homeassistant/components/shelly/entity.py index 28a2c1bf9c398..e33a2d8731744 100644 --- a/homeassistant/components/shelly/entity.py +++ b/homeassistant/components/shelly/entity.py @@ -353,7 +353,7 @@ def __init__(self, wrapper: RpcDeviceWrapper, key: str) -> None: @property def available(self) -> bool: """Available.""" - return cast(bool, self.wrapper.device.connected) + return self.wrapper.device.connected async def async_added_to_hass(self) -> None: """When entity is added to HASS.""" @@ -631,7 +631,7 @@ def __init__( self.last_state: StateType = None self.wrapper = wrapper self.attribute = attribute - self.block: Block | None = block + self.block: Block | None = block # type: ignore[assignment] self.description = description self._unit = self.description.unit From 3180f756ffc7ca751f4cfd9ff6615ba69d7d379f Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Mon, 25 Oct 2021 18:40:03 -0400 Subject: [PATCH 3/4] revert some changes --- .../components/samsungtv/media_player.py | 37 ++++++++----------- .../components/screenlogic/__init__.py | 18 +++++++++ homeassistant/components/soma/__init__.py | 17 ++++++--- .../components/somfy_mylink/cover.py | 14 ++++--- homeassistant/components/spider/climate.py | 6 ++- homeassistant/components/spider/sensor.py | 6 ++- homeassistant/components/spider/switch.py | 6 ++- .../components/spotify/media_player.py | 15 +++++--- homeassistant/components/subaru/entity.py | 14 ++++--- 9 files changed, 88 insertions(+), 45 deletions(-) diff --git a/homeassistant/components/samsungtv/media_player.py b/homeassistant/components/samsungtv/media_player.py index f9356e39b9907..cab6435af95d6 100644 --- a/homeassistant/components/samsungtv/media_player.py +++ b/homeassistant/components/samsungtv/media_player.py @@ -27,15 +27,7 @@ SamsungTVWSBridge, ) from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry -from homeassistant.const import ( - ATTR_CONNECTIONS, - ATTR_IDENTIFIERS, - CONF_HOST, - CONF_MAC, - CONF_NAME, - STATE_OFF, - STATE_ON, -) +from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_component import homeassistant.helpers.config_validation as cv @@ -123,19 +115,6 @@ def __init__( self._bridge = bridge self._auth_failed = False self._bridge.register_reauth_callback(self.access_denied) - self._attr_device_info = DeviceInfo( - name=self.name, - manufacturer=self._manufacturer, - model=self._model, - ) - if self._mac: - self._attr_device_info[ATTR_CONNECTIONS] = { - (CONNECTION_NETWORK_MAC, self._mac) - } - if config_entry.unique_id: - self._attr_device_info[ATTR_IDENTIFIERS] = { - (DOMAIN, config_entry.unique_id) - } def access_denied(self) -> None: """Access denied callback.""" @@ -201,6 +180,20 @@ def available(self) -> bool: or self._power_off_in_progress() ) + @property + def device_info(self) -> DeviceInfo | None: + """Return device specific attributes.""" + info: DeviceInfo = { + "name": self.name, + "manufacturer": self._manufacturer, + "model": self._model, + } + if self.unique_id: + info["identifiers"] = {(DOMAIN, self.unique_id)} + if self._mac: + info["connections"] = {(CONNECTION_NETWORK_MAC, self._mac)} + return info + @property def is_volume_muted(self) -> bool: """Boolean if volume is currently muted.""" diff --git a/homeassistant/components/screenlogic/__init__.py b/homeassistant/components/screenlogic/__init__.py index 37fc20b8ab0de..b759bfd5ba6a4 100644 --- a/homeassistant/components/screenlogic/__init__.py +++ b/homeassistant/components/screenlogic/__init__.py @@ -229,6 +229,24 @@ def gateway_name(self): """Return the configured name of the gateway.""" return self.gateway.name + @property + def device_info(self) -> DeviceInfo: + """Return device information for the controller.""" + controller_type = self.config_data["controller_type"] + hardware_type = self.config_data["hardware_type"] + try: + equipment_model = EQUIPMENT.CONTROLLER_HARDWARE[controller_type][ + hardware_type + ] + except KeyError: + equipment_model = f"Unknown Model C:{controller_type} H:{hardware_type}" + return DeviceInfo( + connections={(dr.CONNECTION_NETWORK_MAC, self.mac)}, + manufacturer="Pentair", + model=equipment_model, + name=self.gateway_name, + ) + class ScreenLogicCircuitEntity(ScreenlogicEntity): """ScreenLogic circuit entity.""" diff --git a/homeassistant/components/soma/__init__.py b/homeassistant/components/soma/__init__.py index b8ec17519745a..532e6204ad90c 100644 --- a/homeassistant/components/soma/__init__.py +++ b/homeassistant/components/soma/__init__.py @@ -72,11 +72,6 @@ def __init__(self, device, api): self.current_position = 50 self.battery_state = 0 self.is_available = True - self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, self.unique_id)}, - manufacturer="Wazombi Labs", - name=self.name, - ) @property def available(self): @@ -92,3 +87,15 @@ def unique_id(self): def name(self): """Return the name of the device.""" return self.device["name"] + + @property + def device_info(self) -> DeviceInfo: + """Return device specific attributes. + + Implemented by platform classes. + """ + return DeviceInfo( + identifiers={(DOMAIN, self.unique_id)}, + manufacturer="Wazombi Labs", + name=self.name, + ) diff --git a/homeassistant/components/somfy_mylink/cover.py b/homeassistant/components/somfy_mylink/cover.py index 4f7ba17d3a102..b4eb847a5e03d 100644 --- a/homeassistant/components/somfy_mylink/cover.py +++ b/homeassistant/components/somfy_mylink/cover.py @@ -74,11 +74,6 @@ def __init__( self._is_opening = None self._is_closing = None self._device_class = device_class - self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, target_id)}, - manufacturer=MANUFACTURER, - name=name, - ) @property def should_poll(self): @@ -120,6 +115,15 @@ def is_closed(self) -> bool: """Return if the cover is closed.""" return self._closed + @property + def device_info(self) -> DeviceInfo: + """Return the device_info of the device.""" + return DeviceInfo( + identifiers={(DOMAIN, self._target_id)}, + manufacturer=MANUFACTURER, + name=self._name, + ) + async def async_close_cover(self, **kwargs): """Close the cover.""" self._is_closing = True diff --git a/homeassistant/components/spider/climate.py b/homeassistant/components/spider/climate.py index 8e90ccb741bbe..9f9a3ebbbaca0 100644 --- a/homeassistant/components/spider/climate.py +++ b/homeassistant/components/spider/climate.py @@ -44,7 +44,11 @@ def __init__(self, api, thermostat): """Initialize the thermostat.""" self.api = api self.thermostat = thermostat - self._attr_device_info = DeviceInfo( + + @property + def device_info(self) -> DeviceInfo: + """Return the device_info of the device.""" + return DeviceInfo( identifiers={(DOMAIN, self.thermostat.id)}, manufacturer=self.thermostat.manufacturer, model=self.thermostat.model, diff --git a/homeassistant/components/spider/sensor.py b/homeassistant/components/spider/sensor.py index 2b52d9232baba..1e469b1097089 100644 --- a/homeassistant/components/spider/sensor.py +++ b/homeassistant/components/spider/sensor.py @@ -38,7 +38,11 @@ def __init__(self, api, power_plug) -> None: """Initialize the Spider Power Plug.""" self.api = api self.power_plug = power_plug - self._attr_device_info = DeviceInfo( + + @property + def device_info(self) -> DeviceInfo: + """Return the device_info of the device.""" + return DeviceInfo( identifiers={(DOMAIN, self.power_plug.id)}, manufacturer=self.power_plug.manufacturer, model=self.power_plug.model, diff --git a/homeassistant/components/spider/switch.py b/homeassistant/components/spider/switch.py index e3fec17c68faf..4569105b8f4c0 100644 --- a/homeassistant/components/spider/switch.py +++ b/homeassistant/components/spider/switch.py @@ -23,7 +23,11 @@ def __init__(self, api, power_plug): """Initialize the Spider Power Plug.""" self.api = api self.power_plug = power_plug - self._attr_device_info = DeviceInfo( + + @property + def device_info(self) -> DeviceInfo: + """Return the device_info of the device.""" + return DeviceInfo( identifiers={(DOMAIN, self.power_plug.id)}, manufacturer=self.power_plug.manufacturer, model=self.power_plug.model, diff --git a/homeassistant/components/spotify/media_player.py b/homeassistant/components/spotify/media_player.py index ac0bd4704a041..4359c20ba5f1e 100644 --- a/homeassistant/components/spotify/media_player.py +++ b/homeassistant/components/spotify/media_player.py @@ -251,17 +251,22 @@ def __init__( self._attr_name = f"Spotify {name}" self._attr_unique_id = user_id + + @property + def device_info(self) -> DeviceInfo: + """Return device information about this entity.""" model = "Spotify Free" - if me is not None: - product = me["product"] + if self._me is not None: + product = self._me["product"] model = f"Spotify {product}" - self._attr_device_info = DeviceInfo( + + return DeviceInfo( configuration_url="https://open.spotify.com", entry_type="service", - identifiers={(DOMAIN, user_id)}, + identifiers={(DOMAIN, self._attr_unique_id)}, manufacturer="Spotify AB", model=model, - name=f"Spotify {name}", + name=f"Spotify {self.name}", ) @property diff --git a/homeassistant/components/subaru/entity.py b/homeassistant/components/subaru/entity.py index f7f18d5bf57f6..2bdb1425b2d64 100644 --- a/homeassistant/components/subaru/entity.py +++ b/homeassistant/components/subaru/entity.py @@ -14,11 +14,6 @@ def __init__(self, vehicle_info, coordinator): self.car_name = vehicle_info[VEHICLE_NAME] self.vin = vehicle_info[VEHICLE_VIN] self.entity_type = "entity" - self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, vehicle_info[VEHICLE_VIN])}, - manufacturer=MANUFACTURER, - name=vehicle_info[VEHICLE_NAME], - ) @property def name(self): @@ -29,3 +24,12 @@ def name(self): def unique_id(self) -> str: """Return a unique ID.""" return f"{self.vin}_{self.entity_type}" + + @property + def device_info(self) -> DeviceInfo: + """Return the device_info of the device.""" + return DeviceInfo( + identifiers={(DOMAIN, self.vin)}, + manufacturer=MANUFACTURER, + name=self.car_name, + ) From 0c7869309e6b488b6d03ae279e1f374dd8238d26 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Tue, 26 Oct 2021 08:14:04 -0400 Subject: [PATCH 4/4] forgot to undo screenlogic --- homeassistant/components/screenlogic/__init__.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/homeassistant/components/screenlogic/__init__.py b/homeassistant/components/screenlogic/__init__.py index b759bfd5ba6a4..894a8a5e52769 100644 --- a/homeassistant/components/screenlogic/__init__.py +++ b/homeassistant/components/screenlogic/__init__.py @@ -184,20 +184,6 @@ def __init__(self, coordinator, data_key, enabled=True): super().__init__(coordinator) self._data_key = data_key self._enabled_default = enabled - controller_type = self.config_data["controller_type"] - hardware_type = self.config_data["hardware_type"] - try: - equipment_model = EQUIPMENT.CONTROLLER_HARDWARE[controller_type][ - hardware_type - ] - except KeyError: - equipment_model = f"Unknown Model C:{controller_type} H:{hardware_type}" - self._attr_device_info = DeviceInfo( - connections={(dr.CONNECTION_NETWORK_MAC, self.mac)}, - manufacturer="Pentair", - model=equipment_model, - name=self.gateway_name, - ) @property def entity_registry_enabled_default(self):