Skip to content

Commit

Permalink
Link sensors together in devices, solves #23
Browse files Browse the repository at this point in the history
Link sensors together in devices, solves #23
  • Loading branch information
dave-code-ruiz authored Nov 24, 2022
1 parent d5b1a82 commit f5ea175
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
4 changes: 2 additions & 2 deletions custom_components/uhomeuponor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from homeassistant.const import Platform
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers import device_registry, entity_registry
from .uponor_api.const import DOMAIN

_LOGGER = getLogger(__name__)
DOMAIN = "uhomeuponor"

PLATFORMS = [Platform.SENSOR, Platform.CLIMATE]

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

14 changes: 11 additions & 3 deletions custom_components/uhomeuponor/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from homeassistant.exceptions import PlatformNotReady
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
from homeassistant.components.climate.const import (
DOMAIN,
HVAC_MODE_AUTO, HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL,
PRESET_COMFORT, PRESET_ECO,
CURRENT_HVAC_HEAT, CURRENT_HVAC_COOL, CURRENT_HVAC_IDLE,
Expand All @@ -25,7 +24,7 @@
from logging import getLogger

from .uponor_api import UponorClient
from .uponor_api.const import (UHOME_MODE_HEAT, UHOME_MODE_COOL, UHOME_MODE_ECO, UHOME_MODE_COMFORT)
from .uponor_api.const import (DOMAIN, UHOME_MODE_HEAT, UHOME_MODE_COOL, UHOME_MODE_ECO, UHOME_MODE_COMFORT)

CONF_SUPPORTS_HEATING = "supports_heating"
CONF_SUPPORTS_COOLING = "supports_cooling"
Expand Down Expand Up @@ -78,9 +77,18 @@ def __init__(self, prefix, uponor_client, thermostat, supports_heating, supports
self.thermostat = thermostat
self.supports_heating = supports_heating
self.supports_cooling = supports_cooling

self.device_name = f"{prefix or ''}{thermostat.by_name('room_name').value}"
self.device_id = f"{prefix or ''}controller{str(thermostat.controller_index)}_thermostat{str(thermostat.thermostat_index)}"
self.identity = f"{prefix or ''}controller{str(thermostat.controller_index)}_thermostat{str(thermostat.thermostat_index)}_thermostat"

@property
def device_info(self) -> dict:
"""Return info for device registry."""
return {
"identifiers": {(DOMAIN, self.device_id)},
"name": self.device_name,
}

# ** Generic **
@property
def name(self):
Expand Down
3 changes: 2 additions & 1 deletion custom_components/uhomeuponor/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import logging
import voluptuous as vol
from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_PREFIX)
from .uponor_api.const import DOMAIN

_LOGGER = logging.getLogger(__name__)
DOMAIN = "uhomeuponor"

CONF_SUPPORTS_HEATING = "supports_heating"
CONF_SUPPORTS_COOLING = "supports_cooling"

Expand Down
35 changes: 31 additions & 4 deletions custom_components/uhomeuponor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from homeassistant.helpers.entity import Entity

from .uponor_api import UponorClient
from .uponor_api.const import (UNIT_BATTERY, UNIT_HUMIDITY)
from .uponor_api.const import (DOMAIN, UNIT_BATTERY, UNIT_HUMIDITY)

_LOGGER = getLogger(__name__)

Expand Down Expand Up @@ -77,9 +77,18 @@ def __init__(self, prefix, uponor_client, thermostat):
self.prefix = prefix
self.uponor_client = uponor_client
self.thermostat = thermostat

self.device_name = f"{prefix or ''}{thermostat.by_name('room_name').value}"
self.device_id = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}"
self.identity = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}_temp"

@property
def device_info(self) -> dict:
"""Return info for device registry."""
return {
"identifiers": {(DOMAIN, self.device_id)},
"name": self.device_name,
}

# ** Generic **
@property
def name(self):
Expand Down Expand Up @@ -141,9 +150,18 @@ def __init__(self, prefix, uponor_client, thermostat):
self.prefix = prefix
self.uponor_client = uponor_client
self.thermostat = thermostat

self.device_name = f"{prefix or ''}{thermostat.by_name('room_name').value}"
self.device_id = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}"
self.identity = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}_rh"

@property
def device_info(self) -> dict:
"""Return info for device registry."""
return {
"identifiers": {(DOMAIN, self.device_id)},
"name": self.device_name,
}

# ** Generic **
@property
def name(self):
Expand Down Expand Up @@ -197,9 +215,18 @@ def __init__(self, prefix, uponor_client, thermostat):
self.prefix = prefix
self.uponor_client = uponor_client
self.thermostat = thermostat

self.device_name = f"{prefix or ''}{thermostat.by_name('room_name').value}"
self.device_id = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}"
self.identity = f"{prefix or ''}controller{thermostat.controller_index}_thermostat{thermostat.thermostat_index}_batt"

@property
def device_info(self) -> dict:
"""Return info for device registry."""
return {
"identifiers": {(DOMAIN, self.device_id)},
"name": self.device_name,
}

# ** Generic **
@property
def name(self):
Expand Down
1 change: 1 addition & 0 deletions custom_components/uhomeuponor/uponor_api/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants."""
DOMAIN = "uhomeuponor"
# HC_MODEs
UHOME_MODE_HEAT = '0'
UHOME_MODE_COOL = '1'
Expand Down

0 comments on commit f5ea175

Please sign in to comment.