Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions homeassistant/components/tado/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def __init__(self, tado):
self.home_id = tado.home_id

@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return the device_info of the device."""
return {
"identifiers": {(DOMAIN, self.home_id)},
"name": self.home_name,
"manufacturer": DEFAULT_NAME,
"model": TADO_HOME,
}
return DeviceInfo(
identifiers={(DOMAIN, self.home_id)},
manufacturer=DEFAULT_NAME,
model=TADO_HOME,
name=self.home_name,
)


class TadoZoneEntity(Entity):
Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/tasmota/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def __init__(self, tasmota_entity: HATasmotaEntity) -> None:
"""Initialize."""
self._tasmota_entity = tasmota_entity
self._unique_id = tasmota_entity.unique_id
self._attr_device_info = DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, self._tasmota_entity.mac)}
)

async def async_added_to_hass(self) -> None:
"""Subscribe to MQTT events."""
Expand All @@ -59,11 +62,6 @@ async def _subscribe_topics(self) -> None:
"""(Re)Subscribe to topics."""
await self._tasmota_entity.subscribe_topics()

@property
def device_info(self) -> DeviceInfo:
"""Return a device description for device registry."""
return {"connections": {(CONNECTION_NETWORK_MAC, self._tasmota_entity.mac)}}

@property
def name(self) -> str | None:
"""Return the name of the binary sensor."""
Expand Down
16 changes: 7 additions & 9 deletions homeassistant/components/toon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ class ToonDisplayDeviceEntity(ToonEntity):
def device_info(self) -> DeviceInfo:
"""Return device information about this thermostat."""
agreement = self.coordinator.data.agreement
model = agreement.display_hardware_version.rpartition("/")[0]
sw_version = agreement.display_software_version.rpartition("/")[-1]
return {
"identifiers": {(DOMAIN, agreement.agreement_id)},
"name": "Toon Display",
"manufacturer": "Eneco",
"model": model,
"sw_version": sw_version,
}
return DeviceInfo(
identifiers={(DOMAIN, agreement.agreement_id)},
manufacturer="Eneco",
model=agreement.display_hardware_version.rpartition("/")[0],
name="Toon Display",
sw_version=agreement.display_software_version.rpartition("/")[-1],
)


class ToonElectricityMeterDeviceEntity(ToonEntity):
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/tplink/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def name(self) -> str:
@property
def device_info(self) -> DeviceInfo:
"""Return information about the device."""
return {
"name": self.device.alias,
"model": self.device.model,
"manufacturer": "TP-Link",
"identifiers": {(DOMAIN, str(self.device.device_id))},
"connections": {(dr.CONNECTION_NETWORK_MAC, self.device.mac)},
"sw_version": self.device.hw_info["sw_ver"],
}
return DeviceInfo(
connections={(dr.CONNECTION_NETWORK_MAC, self.device.mac)},
identifiers={(DOMAIN, str(self.device.device_id))},
manufacturer="TP-Link",
model=self.device.model,
name=self.device.alias,
sw_version=self.device.hw_info["sw_ver"],
)

@property
def is_on(self) -> bool:
Expand Down
22 changes: 6 additions & 16 deletions homeassistant/components/twentemilieu/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@

from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
ATTR_NAME,
CONF_ID,
DEVICE_CLASS_DATE,
)
from homeassistant.const import CONF_ID, DEVICE_CLASS_DATE
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.dispatcher import async_dispatcher_connect
Expand Down Expand Up @@ -99,6 +93,11 @@ def __init__(
self._waste_type = waste_type

self._state = None
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, unique_id)},
manufacturer="Twente Milieu",
name="Twente Milieu",
)

@property
def name(self) -> str:
Expand Down Expand Up @@ -149,12 +148,3 @@ async def async_update(self) -> None:
next_pickup = await self._twentemilieu.next_pickup(self._waste_type)
if next_pickup is not None:
self._state = next_pickup.date().isoformat()

@property
def device_info(self) -> DeviceInfo:
"""Return device information about Twente Milieu."""
return {
ATTR_IDENTIFIERS: {(DOMAIN, self._unique_id)},
ATTR_NAME: "Twente Milieu",
ATTR_MANUFACTURER: "Twente Milieu",
}
12 changes: 6 additions & 6 deletions homeassistant/components/twinkly/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ def icon(self) -> str:
def device_info(self) -> DeviceInfo | None:
"""Get device specific attributes."""
return (
{
"identifiers": {(DOMAIN, self._id)},
"name": self.name,
"manufacturer": "LEDWORKS",
"model": self.model,
}
DeviceInfo(
identifiers={(DOMAIN, self._id)},
manufacturer="LEDWORKS",
model=self.model,
name=self.name,
)
if self._id
else None # device_info is available only for entities configured from the UI
)
Expand Down
21 changes: 9 additions & 12 deletions homeassistant/components/unifi/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo
import homeassistant.util.dt as dt_util

from .const import ATTR_MANUFACTURER, DOMAIN as UNIFI_DOMAIN
Expand Down Expand Up @@ -402,19 +403,15 @@ def available(self) -> bool:
return not self.device.disabled and self.controller.available

@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return a device description for device registry."""
info = {
"connections": {(CONNECTION_NETWORK_MAC, self.device.mac)},
"manufacturer": ATTR_MANUFACTURER,
"model": self.device.model,
"sw_version": self.device.version,
}

if self.device.name:
info["name"] = self.device.name

return info
return DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, self.device.mac)},
manufacturer=ATTR_MANUFACTURER,
model=self.device.model,
name=self.device.name if self.device.name else None,
sw_version=self.device.version,
)

async def async_update_device_registry(self) -> None:
"""Update device registry."""
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/unifi/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ async def options_updated(self) -> None:
@property
def device_info(self) -> DeviceInfo:
"""Return a service description for device registry."""
return {
"identifiers": {(DOMAIN, f"unifi_controller_{self._item.site_id}")},
"name": "UniFi Controller",
"manufacturer": ATTR_MANUFACTURER,
"model": "UniFi Controller",
"entry_type": "service",
}
return DeviceInfo(
entry_type="service",
identifiers={(DOMAIN, f"unifi_controller_{self._item.site_id}")},
manufacturer=ATTR_MANUFACTURER,
model="UniFi Controller",
name="UniFi Controller",
)
10 changes: 5 additions & 5 deletions homeassistant/components/unifi/unifi_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def available(self) -> bool:
@property
def device_info(self) -> DeviceInfo:
"""Return a client description for device registry."""
return {
"connections": {(CONNECTION_NETWORK_MAC, self.client.mac)},
"default_name": self.name,
"default_manufacturer": self.client.oui,
}
return DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, self.client.mac)},
default_manufacturer=self.client.oui,
default_name=self.name,
)
18 changes: 9 additions & 9 deletions homeassistant/components/upb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from homeassistant.const import ATTR_COMMAND, CONF_FILE_PATH, CONF_HOST
from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity import DeviceInfo, Entity

from .const import (
ATTR_ADDRESS,
Expand Down Expand Up @@ -119,12 +119,12 @@ class UpbAttachedEntity(UpbEntity):
"""Base class for UPB attached entities."""

@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Device info for the entity."""
return {
"name": self._element.name,
"identifiers": {(DOMAIN, self._element.index)},
"sw_version": self._element.version,
"manufacturer": self._element.manufacturer,
"model": self._element.product,
}
return DeviceInfo(
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert all the changes that don't have tests and you haven't tested.

identifiers={(DOMAIN, self._element.index)},
manufacturer=self._element.manufacturer,
model=self._element.product,
name=self._element.name,
sw_version=self._element.version,
)
16 changes: 8 additions & 8 deletions homeassistant/components/velbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.const import CONF_ADDRESS, CONF_NAME, 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 (
CONF_INTERFACE,
Expand Down Expand Up @@ -178,16 +178,16 @@ async def _on_update(self):
@property
def device_info(self):
"""Return the device info."""
return {
"identifiers": {
return DeviceInfo(
identifiers={
(
DOMAIN,
self._channel.get_module_address(),
self._channel.get_module_serial(),
)
},
"name": self._channel.get_full_name(),
"manufacturer": "Velleman",
"model": self._channel.get_module_type_name(),
"sw_version": self._channel.get_module_sw_version(),
}
manufacturer="Velleman",
model=self._channel.get_module_type_name(),
name=self._channel.get_full_name(),
sw_version=self._channel.get_module_sw_version(),
)
21 changes: 11 additions & 10 deletions homeassistant/components/vizio/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

Expand Down Expand Up @@ -180,27 +181,27 @@ async def async_update(self) -> None:
is_on = await self._device.get_power_state(log_api_exception=False)

if is_on is None:
if self._attr_available:
if self.available:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a deliberate change?

_LOGGER.warning(
"Lost connection to %s", self._config_entry.data[CONF_HOST]
)
self._attr_available = False
return

if not self._attr_available:
if not self.available:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a deliberate change?

_LOGGER.info(
"Restored connection to %s", self._config_entry.data[CONF_HOST]
)
self._attr_available = True

if not self._attr_device_info:
self._attr_device_info = {
"identifiers": {(DOMAIN, self._attr_unique_id)},
"name": self._attr_name,
"manufacturer": "VIZIO",
"model": await self._device.get_model_name(log_api_exception=False),
"sw_version": await self._device.get_version(log_api_exception=False),
}
if not self.device_info:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a deliberate change?

self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._attr_unique_id)},
manufacturer="VIZIO",
model=await self._device.get_model_name(log_api_exception=False),
name=self.name,
sw_version=await self._device.get_version(log_api_exception=False),
)

if not is_on:
self._attr_state = STATE_OFF
Expand Down
13 changes: 7 additions & 6 deletions homeassistant/components/vlc_telnet/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
)
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
import homeassistant.util.dt as dt_util
Expand Down Expand Up @@ -118,12 +119,12 @@ def __init__(
self._media_title: str | None = None
config_entry_id = config_entry.entry_id
self._attr_unique_id = config_entry_id
self._attr_device_info = {
"name": name,
"identifiers": {(DOMAIN, config_entry_id)},
"manufacturer": "VideoLAN",
"entry_type": "service",
}
self._attr_device_info = DeviceInfo(
entry_type="service",
identifiers={(DOMAIN, config_entry_id)},
manufacturer="VideoLAN",
name=name,
)

async def async_update(self) -> None:
"""Get the latest details from the device."""
Expand Down
17 changes: 9 additions & 8 deletions homeassistant/components/volumio/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
STATE_PAUSED,
STATE_PLAYING,
)
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.util import Throttle

from .browse_media import browse_node, browse_top_level
Expand Down Expand Up @@ -99,15 +100,15 @@ def name(self):
return self._name

@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return device info for this device."""
return {
"identifiers": {(DOMAIN, self.unique_id)},
"name": self.name,
"manufacturer": "Volumio",
"sw_version": self._info["systemversion"],
"model": self._info["hardware"],
}
return DeviceInfo(
identifiers={(DOMAIN, self.unique_id)},
manufacturer="Volumio",
model=self._info["hardware"],
name=self.name,
sw_version=self._info["systemversion"],
)

@property
def media_content_type(self):
Expand Down