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