Skip to content

Commit f5ea175

Browse files
Link sensors together in devices, solves #23
Link sensors together in devices, solves #23
1 parent d5b1a82 commit f5ea175

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

custom_components/uhomeuponor/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
from homeassistant.const import Platform
1010
from homeassistant.config_entries import ConfigEntry
1111
from homeassistant.helpers import device_registry, entity_registry
12+
from .uponor_api.const import DOMAIN
1213

1314
_LOGGER = getLogger(__name__)
14-
DOMAIN = "uhomeuponor"
15+
1516
PLATFORMS = [Platform.SENSOR, Platform.CLIMATE]
1617

1718
async def async_setup(hass: HomeAssistant, config: dict):
@@ -50,4 +51,3 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
5051
return unload_ok
5152
#if unload_ok:
5253
# hass.data[DOMAIN].pop(config_entry.entry_id)
53-

custom_components/uhomeuponor/climate.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from homeassistant.exceptions import PlatformNotReady
1212
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
1313
from homeassistant.components.climate.const import (
14-
DOMAIN,
1514
HVAC_MODE_AUTO, HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL,
1615
PRESET_COMFORT, PRESET_ECO,
1716
CURRENT_HVAC_HEAT, CURRENT_HVAC_COOL, CURRENT_HVAC_IDLE,
@@ -25,7 +24,7 @@
2524
from logging import getLogger
2625

2726
from .uponor_api import UponorClient
28-
from .uponor_api.const import (UHOME_MODE_HEAT, UHOME_MODE_COOL, UHOME_MODE_ECO, UHOME_MODE_COMFORT)
27+
from .uponor_api.const import (DOMAIN, UHOME_MODE_HEAT, UHOME_MODE_COOL, UHOME_MODE_ECO, UHOME_MODE_COMFORT)
2928

3029
CONF_SUPPORTS_HEATING = "supports_heating"
3130
CONF_SUPPORTS_COOLING = "supports_cooling"
@@ -78,9 +77,18 @@ def __init__(self, prefix, uponor_client, thermostat, supports_heating, supports
7877
self.thermostat = thermostat
7978
self.supports_heating = supports_heating
8079
self.supports_cooling = supports_cooling
81-
80+
self.device_name = f"{prefix or ''}{thermostat.by_name('room_name').value}"
81+
self.device_id = f"{prefix or ''}controller{str(thermostat.controller_index)}_thermostat{str(thermostat.thermostat_index)}"
8282
self.identity = f"{prefix or ''}controller{str(thermostat.controller_index)}_thermostat{str(thermostat.thermostat_index)}_thermostat"
8383

84+
@property
85+
def device_info(self) -> dict:
86+
"""Return info for device registry."""
87+
return {
88+
"identifiers": {(DOMAIN, self.device_id)},
89+
"name": self.device_name,
90+
}
91+
8492
# ** Generic **
8593
@property
8694
def name(self):

custom_components/uhomeuponor/config_flow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import logging
77
import voluptuous as vol
88
from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_PREFIX)
9+
from .uponor_api.const import DOMAIN
910

1011
_LOGGER = logging.getLogger(__name__)
11-
DOMAIN = "uhomeuponor"
12+
1213
CONF_SUPPORTS_HEATING = "supports_heating"
1314
CONF_SUPPORTS_COOLING = "supports_cooling"
1415

custom_components/uhomeuponor/sensor.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from homeassistant.helpers.entity import Entity
2323

2424
from .uponor_api import UponorClient
25-
from .uponor_api.const import (UNIT_BATTERY, UNIT_HUMIDITY)
25+
from .uponor_api.const import (DOMAIN, UNIT_BATTERY, UNIT_HUMIDITY)
2626

2727
_LOGGER = getLogger(__name__)
2828

@@ -77,9 +77,18 @@ def __init__(self, prefix, uponor_client, thermostat):
7777
self.prefix = prefix
7878
self.uponor_client = uponor_client
7979
self.thermostat = thermostat
80-
80+
self.device_name = f"{prefix or ''}{thermostat.by_name('room_name').value}"
81+
self.device_id = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}"
8182
self.identity = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}_temp"
8283

84+
@property
85+
def device_info(self) -> dict:
86+
"""Return info for device registry."""
87+
return {
88+
"identifiers": {(DOMAIN, self.device_id)},
89+
"name": self.device_name,
90+
}
91+
8392
# ** Generic **
8493
@property
8594
def name(self):
@@ -141,9 +150,18 @@ def __init__(self, prefix, uponor_client, thermostat):
141150
self.prefix = prefix
142151
self.uponor_client = uponor_client
143152
self.thermostat = thermostat
144-
153+
self.device_name = f"{prefix or ''}{thermostat.by_name('room_name').value}"
154+
self.device_id = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}"
145155
self.identity = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}_rh"
146156

157+
@property
158+
def device_info(self) -> dict:
159+
"""Return info for device registry."""
160+
return {
161+
"identifiers": {(DOMAIN, self.device_id)},
162+
"name": self.device_name,
163+
}
164+
147165
# ** Generic **
148166
@property
149167
def name(self):
@@ -197,9 +215,18 @@ def __init__(self, prefix, uponor_client, thermostat):
197215
self.prefix = prefix
198216
self.uponor_client = uponor_client
199217
self.thermostat = thermostat
200-
218+
self.device_name = f"{prefix or ''}{thermostat.by_name('room_name').value}"
219+
self.device_id = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}"
201220
self.identity = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}_batt"
202221

222+
@property
223+
def device_info(self) -> dict:
224+
"""Return info for device registry."""
225+
return {
226+
"identifiers": {(DOMAIN, self.device_id)},
227+
"name": self.device_name,
228+
}
229+
203230
# ** Generic **
204231
@property
205232
def name(self):

custom_components/uhomeuponor/uponor_api/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Constants."""
2+
DOMAIN = "uhomeuponor"
23
# HC_MODEs
34
UHOME_MODE_HEAT = '0'
45
UHOME_MODE_COOL = '1'

0 commit comments

Comments
 (0)