diff --git a/custom_components/daikin_onecta/water_heater.py b/custom_components/daikin_onecta/water_heater.py index 1660f46..2acb58f 100644 --- a/custom_components/daikin_onecta/water_heater.py +++ b/custom_components/daikin_onecta/water_heater.py @@ -250,6 +250,10 @@ async def async_set_operation_mode(self, operation_mode): # Only set the on/off to Daikin when we need to change it if on_off_mode != "": result &= await self._device.patch(self._device.id, self._embedded_id, "onOffMode", "", on_off_mode) + if result is True: + hwtd = self.hotwatertank_data + hwtd["onOffMode"]["value"] = on_off_mode + # Only set powerfulMode when it is set and supported by the device if (powerful_mode != "") and (STATE_PERFORMANCE in self.operation_list): result &= await self._device.patch( @@ -259,6 +263,12 @@ async def async_set_operation_mode(self, operation_mode): "", powerful_mode, ) + if result is True: + hwtd = self.hotwatertank_data + pwf = hwtd.get("powerfulMode") + if pwf is not None: + if pwf["settable"] is True: + pwf["value"] = powerful_mode if result is False: _LOGGER.warning("Device '%s' invalid tank state: %s", self._device.name, operation_mode) @@ -268,3 +278,45 @@ async def async_set_operation_mode(self, operation_mode): self.async_write_ha_state() return result + + async def async_turn_on(self): + """Turn water heater on.""" + _LOGGER.debug("Device '%s' request to turn on", self._device.name) + result = True + if self.current_operation == STATE_OFF: + result &= await self._device.patch(self._device.id, self._embedded_id, "onOffMode", "", "on") + if result is False: + _LOGGER.error("Device '%s' problem setting onOffMode to on", self._device.name) + else: + hwtd = self.hotwatertank_data + hwtd["onOffMode"]["value"] = "on" + self._attr_current_operation = self.get_current_operation() + self.async_write_ha_state() + else: + _LOGGER.debug( + "Device '%s' request to turn on ignored because device is already on", + self._device.name, + ) + + return result + + async def async_turn_off(self): + """Turn water heater off.""" + _LOGGER.debug("Device '%s' request to turn off", self._device.name) + result = True + if self.current_operation != STATE_OFF: + result &= await self._device.patch(self._device.id, self._embedded_id, "onOffMode", "", "off") + if result is False: + _LOGGER.error("Device '%s' problem setting onOffMode to off", self._device.name) + else: + hwtd = self.hotwatertank_data + hwtd["onOffMode"]["value"] = "off" + self._attr_current_operation = self.get_current_operation() + self.async_write_ha_state() + else: + _LOGGER.debug( + "Device '%s' request to turn off ignored because device is already off", + self._device.name, + ) + + return result diff --git a/tests/test_init.py b/tests/test_init.py index 4de57fc..5961cfa 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -364,6 +364,54 @@ async def test_water_heater( assert responses.calls[6].request.body == '{"value": "on"}' assert hass.states.get("water_heater.altherma").attributes["operation_mode"] == STATE_HEAT_PUMP + # Turn the tank again off using turn_off + await hass.services.async_call( + WATER_HEATER_DOMAIN, + SERVICE_TURN_OFF, + {ATTR_ENTITY_ID: "water_heater.altherma"}, + blocking=True, + ) + await hass.async_block_till_done() + + assert len(responses.calls) == 8 + assert responses.calls[7].request.body == '{"value": "off"}' + assert hass.states.get("water_heater.altherma").attributes["operation_mode"] == STATE_OFF + + # Turn the tank again off using turn_off, will be a noop + await hass.services.async_call( + WATER_HEATER_DOMAIN, + SERVICE_TURN_OFF, + {ATTR_ENTITY_ID: "water_heater.altherma"}, + blocking=True, + ) + await hass.async_block_till_done() + + assert len(responses.calls) == 8 + + # Turn the tank again on using turn_on + await hass.services.async_call( + WATER_HEATER_DOMAIN, + SERVICE_TURN_ON, + {ATTR_ENTITY_ID: "water_heater.altherma"}, + blocking=True, + ) + await hass.async_block_till_done() + + assert len(responses.calls) == 9 + assert responses.calls[8].request.body == '{"value": "on"}' + assert hass.states.get("water_heater.altherma").attributes["operation_mode"] == STATE_HEAT_PUMP + + # Turn the tank again on using turn_on, will be a noop + await hass.services.async_call( + WATER_HEATER_DOMAIN, + SERVICE_TURN_ON, + {ATTR_ENTITY_ID: "water_heater.altherma"}, + blocking=True, + ) + await hass.async_block_till_done() + + assert len(responses.calls) == 9 + @responses.activate async def test_climate(