Skip to content

Commit 6bfa853

Browse files
committed
Add zone detail to sensor names.
1 parent bb8f4da commit 6bfa853

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

custom_components/magiqtouch/climate.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ def __init__(
116116
# https://developers.home-assistant.io/blog/2024/01/24/climate-climateentityfeatures-expanded/
117117
self._enable_turn_on_off_backwards_compatibility = False
118118

119+
@property
120+
def name(self):
121+
"""Return the name of the device."""
122+
if not self.master_zone:
123+
return f"MagiQtouch - {self.controller.get_zone_name(self.zone)}"
124+
return "MagiQtouch"
125+
126+
@property
127+
def unique_id(self) -> str:
128+
"""Return the unique ID for this sensor."""
129+
uid = self.controller.current_state.device
130+
if not self.master_zone:
131+
zone_name = self.controller.get_zone_name(self.zone).replace(" ", "-")
132+
uid += f"-zone-{zone_name}"
133+
return uid
134+
119135
def _init_units(self):
120136
if not self.available:
121137
raise ValueError("Not available yet")
@@ -177,22 +193,6 @@ def inactive_units(self):
177193
else:
178194
return []
179195

180-
@property
181-
def name(self):
182-
"""Return the name of the device."""
183-
if not self.master_zone:
184-
return f"MagiQtouch - {self.controller.get_zone_name(self.zone)}"
185-
return "MagiQtouch"
186-
187-
@property
188-
def unique_id(self) -> str:
189-
"""Return the unique ID for this sensor."""
190-
uid = self.controller.current_state.device
191-
if not self.master_zone:
192-
zone_name = self.controller.get_zone_name(self.zone).replace(" ", "-")
193-
uid += f"-zone-{zone_name}"
194-
return uid
195-
196196
@property
197197
def temperature_unit(self):
198198
"""Return the unit of measurement that is used."""

custom_components/magiqtouch/sensor.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from . import MagiQtouchCoordinator
44
from .magiqtouch import MagiQtouch_Driver
5-
from .const import ZONE_TYPE_NONE
65
from typing import Callable, List
76

87

@@ -29,6 +28,8 @@
2928
# ATTR_MODEL,
3029
# ATTR_TARGET_TEMPERATURE,
3130
DOMAIN,
31+
ZONE_TYPE_COMMON,
32+
ZONE_TYPE_NONE,
3233
)
3334

3435
_LOGGER = logging.getLogger("magiqtouch")
@@ -81,16 +82,24 @@ def __init__(
8182
super().__init__(coordinator)
8283
self.label = label
8384
self.controller = controller
84-
self._attr_name = "MagiQtouch " + label
8585
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
8686
self._attr_device_class = SensorDeviceClass.TEMPERATURE
8787
self._attr_state_class = SensorStateClass.MEASUREMENT
8888
self.data_callback = data_callback
8989
self.zone = zone
90+
self.master_zone = (not self.zone) or self.zone in (ZONE_TYPE_NONE, ZONE_TYPE_COMMON)
9091

9192
self._attr_native_value = 0
9293
self._attr_available = False
9394

95+
@property
96+
def name(self):
97+
"""Return the name of the device."""
98+
if not self.master_zone:
99+
zone_name = self.controller.get_zone_name(self.zone)
100+
return f"MagiQtouch - {zone_name} - {self.label}"
101+
return f"MagiQtouch - {self.label}"
102+
94103
@callback
95104
def _handle_coordinator_update(self) -> None:
96105
"""Handle updated data from the coordinator."""

0 commit comments

Comments
 (0)