mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Use DeviceInfo class (#57868)
This commit is contained in:
parent
441b0b2fb7
commit
4300f1de46
@ -14,6 +14,7 @@ from homeassistant.components.climate.const import (
|
||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
@ -83,12 +84,12 @@ class MillHeater(CoordinatorEntity, ClimateEntity):
|
||||
self._id = heater.device_id
|
||||
self._attr_unique_id = heater.device_id
|
||||
self._attr_name = heater.name
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, heater.device_id)},
|
||||
"name": self.name,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"model": f"generation {1 if heater.is_gen1 else 2}",
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, heater.device_id)},
|
||||
name=self.name,
|
||||
manufacturer=MANUFACTURER,
|
||||
model=f"generation {1 if heater.is_gen1 else 2}",
|
||||
)
|
||||
if heater.is_gen1:
|
||||
self._attr_hvac_modes = [HVAC_MODE_HEAT]
|
||||
else:
|
||||
|
@ -7,6 +7,7 @@ from homeassistant.components.sensor import (
|
||||
)
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import CONSUMPTION_TODAY, CONSUMPTION_YEAR, DOMAIN, MANUFACTURER
|
||||
@ -41,12 +42,12 @@ class MillHeaterEnergySensor(CoordinatorEntity, SensorEntity):
|
||||
|
||||
self._attr_name = f"{heater.name} {sensor_type.replace('_', ' ')}"
|
||||
self._attr_unique_id = f"{heater.device_id}_{sensor_type}"
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, heater.device_id)},
|
||||
"name": self.name,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"model": f"generation {1 if heater.is_gen1 else 2}",
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, heater.device_id)},
|
||||
name=self.name,
|
||||
manufacturer=MANUFACTURER,
|
||||
model=f"generation {1 if heater.is_gen1 else 2}",
|
||||
)
|
||||
self._update_attr(heater)
|
||||
|
||||
@callback
|
||||
|
@ -24,6 +24,7 @@ from homeassistant.const import (
|
||||
STATE_OPENING,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from .const import (
|
||||
ATTR_DISTANCE_SENSOR,
|
||||
@ -181,9 +182,9 @@ class OpenGarageCover(CoverEntity):
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device_info of the device."""
|
||||
device_info = {
|
||||
"identifiers": {(DOMAIN, self._device_id)},
|
||||
"name": self.name,
|
||||
"manufacturer": "Open Garage",
|
||||
}
|
||||
device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_id)},
|
||||
name=self.name,
|
||||
manufacturer="Open Garage",
|
||||
)
|
||||
return device_info
|
||||
|
@ -6,6 +6,7 @@ from abc import abstractmethod
|
||||
from surepy.entities import SurepyEntity
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import SurePetcareDataCoordinator
|
||||
@ -33,12 +34,12 @@ class SurePetcareEntity(CoordinatorEntity):
|
||||
self._device_name = surepy_entity.type.name.capitalize().replace("_", " ")
|
||||
|
||||
self._device_id = f"{surepy_entity.household_id}-{surepetcare_id}"
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, self._device_id)},
|
||||
"name": self._device_name,
|
||||
"manufacturer": "Sure Petcare",
|
||||
"model": surepy_entity.type.name.capitalize().replace("_", " "),
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_id)},
|
||||
name=self._device_name,
|
||||
manufacturer="Sure Petcare",
|
||||
model=surepy_entity.type.name.capitalize().replace("_", " "),
|
||||
)
|
||||
self._update_attr(coordinator.data[surepetcare_id])
|
||||
|
||||
@abstractmethod
|
||||
|
@ -34,6 +34,7 @@ from homeassistant.core import callback
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers import update_coordinator
|
||||
from homeassistant.helpers.device_registry import async_get as async_get_dev_reg
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_registry import async_get as async_get_entity_reg
|
||||
from homeassistant.util import Throttle, dt as dt_util
|
||||
|
||||
@ -264,11 +265,11 @@ class TibberSensor(SensorEntity):
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device_info of the device."""
|
||||
device_info = {
|
||||
"identifiers": {(TIBBER_DOMAIN, self._tibber_home.home_id)},
|
||||
"name": self._device_name,
|
||||
"manufacturer": MANUFACTURER,
|
||||
}
|
||||
device_info = DeviceInfo(
|
||||
identifiers={(TIBBER_DOMAIN, self._tibber_home.home_id)},
|
||||
name=self._device_name,
|
||||
manufacturer=MANUFACTURER,
|
||||
)
|
||||
if self._model is not None:
|
||||
device_info["model"] = self._model
|
||||
return device_info
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
@ -15,13 +15,13 @@ class TractiveEntity(Entity):
|
||||
self, user_id: str, trackable: dict[str, Any], tracker_details: dict[str, Any]
|
||||
) -> None:
|
||||
"""Initialize tracker entity."""
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, tracker_details["_id"])},
|
||||
"name": f"Tractive ({tracker_details['_id']})",
|
||||
"manufacturer": "Tractive GmbH",
|
||||
"sw_version": tracker_details["fw_version"],
|
||||
"model": tracker_details["model_number"],
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, tracker_details["_id"])},
|
||||
name=f"Tractive ({tracker_details['_id']})",
|
||||
manufacturer="Tractive GmbH",
|
||||
sw_version=tracker_details["fw_version"],
|
||||
model=tracker_details["model_number"],
|
||||
)
|
||||
self._user_id = user_id
|
||||
self._tracker_id = tracker_details["_id"]
|
||||
self._trackable = trackable
|
||||
|
Loading…
Reference in New Issue
Block a user