Skip to content

Commit

Permalink
Add zone detail to sensor names.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleech committed May 11, 2024
1 parent bb8f4da commit 6bfa853
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
32 changes: 16 additions & 16 deletions custom_components/magiqtouch/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ def __init__(
# https://developers.home-assistant.io/blog/2024/01/24/climate-climateentityfeatures-expanded/
self._enable_turn_on_off_backwards_compatibility = False

@property
def name(self):
"""Return the name of the device."""
if not self.master_zone:
return f"MagiQtouch - {self.controller.get_zone_name(self.zone)}"
return "MagiQtouch"

@property
def unique_id(self) -> str:
"""Return the unique ID for this sensor."""
uid = self.controller.current_state.device
if not self.master_zone:
zone_name = self.controller.get_zone_name(self.zone).replace(" ", "-")
uid += f"-zone-{zone_name}"
return uid

def _init_units(self):
if not self.available:
raise ValueError("Not available yet")
Expand Down Expand Up @@ -177,22 +193,6 @@ def inactive_units(self):
else:
return []

@property
def name(self):
"""Return the name of the device."""
if not self.master_zone:
return f"MagiQtouch - {self.controller.get_zone_name(self.zone)}"
return "MagiQtouch"

@property
def unique_id(self) -> str:
"""Return the unique ID for this sensor."""
uid = self.controller.current_state.device
if not self.master_zone:
zone_name = self.controller.get_zone_name(self.zone).replace(" ", "-")
uid += f"-zone-{zone_name}"
return uid

@property
def temperature_unit(self):
"""Return the unit of measurement that is used."""
Expand Down
13 changes: 11 additions & 2 deletions custom_components/magiqtouch/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from . import MagiQtouchCoordinator
from .magiqtouch import MagiQtouch_Driver
from .const import ZONE_TYPE_NONE
from typing import Callable, List


Expand All @@ -29,6 +28,8 @@
# ATTR_MODEL,
# ATTR_TARGET_TEMPERATURE,
DOMAIN,
ZONE_TYPE_COMMON,
ZONE_TYPE_NONE,
)

_LOGGER = logging.getLogger("magiqtouch")
Expand Down Expand Up @@ -81,16 +82,24 @@ def __init__(
super().__init__(coordinator)
self.label = label
self.controller = controller
self._attr_name = "MagiQtouch " + label
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
self._attr_device_class = SensorDeviceClass.TEMPERATURE
self._attr_state_class = SensorStateClass.MEASUREMENT
self.data_callback = data_callback
self.zone = zone
self.master_zone = (not self.zone) or self.zone in (ZONE_TYPE_NONE, ZONE_TYPE_COMMON)

self._attr_native_value = 0
self._attr_available = False

@property
def name(self):
"""Return the name of the device."""
if not self.master_zone:
zone_name = self.controller.get_zone_name(self.zone)
return f"MagiQtouch - {zone_name} - {self.label}"
return f"MagiQtouch - {self.label}"

@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
Expand Down

0 comments on commit 6bfa853

Please sign in to comment.