From aa75abe085f9ce340b8dc5fa837de5ac1ff1d878 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Mon, 30 Oct 2023 14:16:53 +0100 Subject: [PATCH] Updates to use the json as provided by Daikin, not do some preprocessing on the data, see #86 * custom_components/daikin_residential_altherma/device.py: * custom_components/daikin_residential_altherma/water_heater.py: --- .../daikin_residential_altherma/device.py | 3 + .../water_heater.py | 85 +++++++++++++------ 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/custom_components/daikin_residential_altherma/device.py b/custom_components/daikin_residential_altherma/device.py index 560228a2..fc3c79b6 100644 --- a/custom_components/daikin_residential_altherma/device.py +++ b/custom_components/daikin_residential_altherma/device.py @@ -23,6 +23,7 @@ def __init__(self, jsonData, apiInstance): self.setJsonData(jsonData) self.name = self.getName() self._available = True + self.daikin_data = jsonData _LOGGER.info("Initialized Daikin Residential Device '%s' (id %s)", self.name, self.getId()) @@ -132,6 +133,8 @@ def setJsonData(self, desc): #_LOGGER.warning('MPS FOUND: [{}]'.format(self.managementPoints)) #_LOGGER.warning('MPS FOUND: [{}]'.format(self.managementPoints.keys())) + def daikin_data(self): + return self.daikin_data def getId(self): """Get Daikin Device UUID.""" diff --git a/custom_components/daikin_residential_altherma/water_heater.py b/custom_components/daikin_residential_altherma/water_heater.py index e5e476de..6faea06e 100644 --- a/custom_components/daikin_residential_altherma/water_heater.py +++ b/custom_components/daikin_residential_altherma/water_heater.py @@ -55,17 +55,18 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= config. But even in that case it would have been ignored. """ - async def async_setup_entry(hass, entry, async_add_entities): """Set up Daikin water tank entities.""" for dev_id, device in hass.data[DAIKIN_DOMAIN][DAIKIN_DEVICES].items(): device_model = device.desc["deviceModel"] - """ When the device has a tank temperature we add a water heater """ - if device.get_data(MP_DOMESTIC_HWT) is not None: - _LOGGER.info("'%s' has a tank management point, adding Water Heater", device_model) - async_add_entities([DaikinWaterTank(device)], update_before_add=True) - else: - _LOGGER.info("'%s' has not a tank management point, ignoring", device.name) + """ When the device has a domesticHotWaterTank we add a water heater """ + if device.daikin_data["managementPoints"] is not None: + for management_point in device.daikin_data["managementPoints"]: + management_point_type = management_point["managementPointType"] + if management_point_type == "domesticHotWaterTank": + async_add_entities([DaikinWaterTank(device)], update_before_add=True) + else: + _LOGGER.info("'%s' has not a tank management point, ignoring as water heater", management_point_type) class DaikinWaterTank(WaterHeaterEntity): """Representation of a Daikin Water Tank.""" @@ -77,13 +78,6 @@ def __init__(self, device): self._list = { ATTR_TANK_MODE: list(HA_TANK_MODE_TO_DAIKIN), } - self._supported_features = SUPPORT_OPERATION_MODE - - # Only when we have a fixed setpointMode we can control the target - # temperature of the tank - if self._device.getData(ATTR_TANK_TARGET_TEMPERATURE)["settable"]: - self._supported_features |= SUPPORT_TARGET_TEMPERATURE - _LOGGER.debug("Tank temperature is settable") async def _set(self, settings): """Set device settings using API.""" @@ -109,6 +103,25 @@ async def _set(self, settings): if values: await self._device.set(values) + @property + def hotwatertank_data(self): + # Find the management point for the hot water tank + for management_point in self._device.daikin_data["managementPoints"]: + management_point_type = management_point["managementPointType"] + if management_point_type == "domesticHotWaterTank": + return management_point + return None + + @property + def domestic_hotwater_temperature(self): + # Find the json dictionary for controlling the hot water temperature + temp_control = self.hotwatertank_data["temperatureControl"]["value"] + if temp_control: + heating_mode = temp_control["operationModes"]["heating"] + if heating_mode is not None: + return heating_mode["setpoints"]["domesticHotWaterTemperature"] + return None + @property def available(self): """Return the availability of the underlying device.""" @@ -116,8 +129,16 @@ def available(self): @property def supported_features(self): + sf = SUPPORT_OPERATION_MODE + # Only when we have a fixed setpointMode we can control the target + # temperature of the tank + dht = self.domestic_hotwater_temperature + if dht: + if dht["settable"] == True: + sf |= SUPPORT_TARGET_TEMPERATURE + _LOGGER.debug("Tank temperature is settable") """Return the list of supported features.""" - return self._supported_features + return sf @property def name(self): @@ -137,11 +158,12 @@ def temperature_unit(self): @property def current_temperature(self): - if self._device.getData(ATTR_TANK_TEMPERATURE) is not None: + ret = None + dht = self.domestic_hotwater_temperature + if dht is not None: """Return tank temperature.""" - return float(self._device.getValue(ATTR_TANK_TEMPERATURE)) - else: - return None + ret = float(domestic_hotwater_temperature["value"]) + return ret @property def target_temperature(self): @@ -150,21 +172,30 @@ def target_temperature(self): @property def extra_state_attributes(self): - """Return the optional device state attributes.""" - data = {"target_temp_step": float(self._device.getData(ATTR_TANK_TARGET_TEMPERATURE)["stepValue"])} + data = {} + dht = self.domestic_hotwater_temperature + if dht is not None: + """Return the optional device state attributes.""" + data = {"target_temp_step": float(dht["stepValue"])} return data @property def min_temp(self): - """Return the supported step of target temperature.""" - stepVal = float(self._device.getData(ATTR_TANK_TARGET_TEMPERATURE)["minValue"]) - return stepVal + """Return the supported minimum value target temperature.""" + ret = None + dht = self.domestic_hotwater_temperature + if dht is not None: + ret = float(dht["minValue"]) + return ret @property def max_temp(self): - """Return the supported step of target temperature.""" - stepVal = float(self._device.getData(ATTR_TANK_TARGET_TEMPERATURE)["maxValue"]) - return stepVal + """Return the supported maximum value of target temperature.""" + ret = None + dht = self.domestic_hotwater_temperature + if dht is not None: + ret = float(self.domestic_hotwater_temperature["maxValue"]) + return ret async def async_set_tank_temperature(self, value): """Set new target temperature."""