Skip to content

Commit

Permalink
🐛 Fix device names
Browse files Browse the repository at this point in the history
  • Loading branch information
anarion80 committed Mar 16, 2024
1 parent 4b16315 commit 2dbdab8
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 56 deletions.
23 changes: 15 additions & 8 deletions custom_components/tech/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
ATTR_TEMPERATURE,
CONF_DESCRIPTION,
CONF_ID,
CONF_MODEL,
CONF_NAME,
CONF_ZONE,
STATE_OFF,
Expand Down Expand Up @@ -81,18 +84,22 @@ def __init__(
self.model: str = model
self._temperature: float | None = None
self._humidity: int | None = None
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, self.device_name)
}, # Unique identifiers for the device
name=self.device_name, # Name of the device
model=self.model, # Model of the device
manufacturer=self.manufacturer, # Manufacturer of the device
)
self.update_properties(device)
# Remove the line below after HA 2025.1
self._enable_turn_on_off_backwards_compatibility = False

@cached_property
def device_info(self) -> DeviceInfo:
"""Return device information in a dictionary format."""
return {
ATTR_IDENTIFIERS: {
(DOMAIN, self.device_name)
}, # Unique identifiers for the device
CONF_NAME: self.device_name, # Name of the device
CONF_MODEL: self.model, # Model of the device
ATTR_MANUFACTURER: self.manufacturer, # Manufacturer of the device
}

def update_properties(self, device: dict[str, Any]) -> None:
"""Update the properties of the HVAC device based on the data from the device.
Expand Down
29 changes: 21 additions & 8 deletions custom_components/tech/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
import logging
from typing import TYPE_CHECKING, Any

from homeassistant.const import CONF_DESCRIPTION, CONF_ID, CONF_PARAMS, CONF_TYPE
from homeassistant.const import (
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
CONF_DESCRIPTION,
CONF_ID,
CONF_MODEL,
CONF_NAME,
CONF_PARAMS,
CONF_TYPE,
)
from homeassistant.core import callback
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.typing import StateType
Expand Down Expand Up @@ -48,14 +57,18 @@ def __init__(
self._name = assets.get_text(txt_id)
else:
self._name = assets.get_text_by_type(device[CONF_TYPE])
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, self._unique_id)

@cached_property
def device_info(self) -> DeviceInfo:
"""Get device info."""
return {
ATTR_IDENTIFIERS: {
(DOMAIN, self.unique_id)
}, # Unique identifiers for the device
name=self._name, # Name of the device
model=self.model, # Model of the device
manufacturer=self.manufacturer, # Manufacturer of the device
)
CONF_NAME: self.name, # Name of the device
CONF_MODEL: self.model, # Model of the device
ATTR_MANUFACTURER: self.manufacturer, # Manufacturer of the device
}

@cached_property
def unique_id(self) -> str:
Expand Down
133 changes: 93 additions & 40 deletions custom_components/tech/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
CONF_DESCRIPTION,
CONF_ID,
CONF_MODEL,
CONF_NAME,
CONF_PARAMS,
CONF_TYPE,
Expand Down Expand Up @@ -81,14 +84,6 @@ def __init__(
)
self._manufacturer: str = MANUFACTURER
self.update_properties(device)
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
name=self._device_name, # Name of the device
model=self._model, # Model of the device
manufacturer=self._manufacturer, # Manufacturer of the device
)

def update_properties(self, device: dict[str, Any]):
"""Update properties from the TechBatterySensor object.
Expand Down Expand Up @@ -119,6 +114,24 @@ def name(self) -> str:
"""Return the name of the device."""
return f"{self._name} battery"

@cached_property
def device_info(self) -> DeviceInfo:
"""Get device information.
Returns:
dict: A dictionary containing device information.
"""
# Return device information
return {
ATTR_IDENTIFIERS: {
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
CONF_NAME: self._device_name, # Name of the device
CONF_MODEL: self._model, # Model of the device
ATTR_MANUFACTURER: self._manufacturer, # Manufacturer of the device
}


class TechTemperatureSensor(CoordinatorEntity[TechCoordinator], SensorEntity):
"""Representation of a Tech temperature sensor."""
Expand Down Expand Up @@ -149,14 +162,6 @@ def __init__(
)
self._manufacturer: str = MANUFACTURER
self.update_properties(device)
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
name=self._device_name, # Name of the device
model=self._model, # Model of the device
manufacturer=self._manufacturer, # Manufacturer of the device
)

def update_properties(self, device: dict[str, Any]) -> None:
"""Update the properties of the TechTemperatureSensor object.
Expand Down Expand Up @@ -193,6 +198,24 @@ def name(self) -> str:
"""Return the name of the device."""
return f"{self._name} temperature"

@cached_property
def device_info(self) -> DeviceInfo:
"""Get device information.
Returns:
dict: A dictionary containing device information.
"""
# Return device information
return {
ATTR_IDENTIFIERS: {
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
CONF_NAME: self._device_name, # Name of the device
CONF_MODEL: self._model, # Model of the device
ATTR_MANUFACTURER: self._manufacturer, # Manufacturer of the device
}


class TechOutsideTempTile(CoordinatorEntity[TechCoordinator], SensorEntity):
"""Representation of a Tech outside temperature tile sensor."""
Expand Down Expand Up @@ -220,14 +243,6 @@ def __init__(
)
self._manufacturer: str = MANUFACTURER
self.update_properties(device)
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
name=self._device_name, # Name of the device
model=self._model, # Model of the device
manufacturer=self._manufacturer, # Manufacturer of the device
)

def update_properties(self, device: dict[str, Any]) -> None:
"""Update the properties of the TechOutsideTempTile object.
Expand Down Expand Up @@ -265,6 +280,24 @@ def name(self) -> str:
"""Return the name of the device."""
return f"{self._name} temperature"

@cached_property
def device_info(self) -> DeviceInfo:
"""Get device information.
Returns:
dict: A dictionary containing device information.
"""
# Return device information
return {
ATTR_IDENTIFIERS: {
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
CONF_NAME: self._device_name, # Name of the device
CONF_MODEL: self._model, # Model of the device
ATTR_MANUFACTURER: self._manufacturer, # Manufacturer of the device
}


class TechHumiditySensor(CoordinatorEntity[TechCoordinator], SensorEntity):
"""Representation of a Tech humidity sensor."""
Expand Down Expand Up @@ -293,14 +326,6 @@ def __init__(
)
self._manufacturer: str = MANUFACTURER
self.update_properties(device)
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
name=self._device_name, # Name of the device
model=self._model, # Model of the device
manufacturer=self._manufacturer, # Manufacturer of the device
)

def update_properties(self, device: dict[str, Any]) -> None:
"""Update the properties of the TechHumiditySensor object.
Expand Down Expand Up @@ -337,6 +362,24 @@ def name(self) -> str:
"""Return the name of the device."""
return f"{self._name} humidity"

@cached_property
def device_info(self) -> DeviceInfo:
"""Get device information.
Returns:
dict: A dictionary containing device information.
"""
# Return device information
return {
ATTR_IDENTIFIERS: {
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
CONF_NAME: self._device_name, # Name of the device
CONF_MODEL: self._model, # Model of the device
ATTR_MANUFACTURER: self._manufacturer, # Manufacturer of the device
}


class ZoneSensor(CoordinatorEntity[TechCoordinator], SensorEntity):
"""Representation of a Zone Sensor."""
Expand All @@ -363,14 +406,6 @@ def __init__(
)
self._manufacturer: str = MANUFACTURER
self.update_properties(device)
self._attr_device_info = DeviceInfo(
identifiers={
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
name=self._device_name, # Name of the device
model=self._model, # Model of the device
manufacturer=self._manufacturer, # Manufacturer of the device
)

def update_properties(self, device: dict[str, Any]) -> None:
"""Update the properties of the device based on the provided device information.
Expand Down Expand Up @@ -413,6 +448,24 @@ def name(self) -> str:
"""Return the name of the sensor."""
return self._name

@cached_property
def device_info(self) -> DeviceInfo:
"""Get device information.
Returns:
dict: A dictionary containing device information.
"""
# Return device information
return {
ATTR_IDENTIFIERS: {
(DOMAIN, self._device_name)
}, # Unique identifiers for the device
CONF_NAME: self._device_name, # Name of the device
CONF_MODEL: self._model, # Model of the device
ATTR_MANUFACTURER: self._manufacturer, # Manufacturer of the device
}


class ZoneTemperatureSensor(ZoneSensor):
"""Representation of a Zone Temperature Sensor."""
Expand Down

0 comments on commit 2dbdab8

Please sign in to comment.