Skip to content

Commit

Permalink
Merge pull request #213 from jwillemsen/jwi-settempopt
Browse files Browse the repository at this point in the history
Only set the target temperature to the Daikin cloud when the value we…
  • Loading branch information
jwillemsen authored Jun 13, 2024
2 parents b90f539 + 36febf8 commit 53a4ce7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
31 changes: 16 additions & 15 deletions custom_components/daikin_onecta/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,23 @@ async def async_set_temperature(self, **kwargs):
await self.async_set_hvac_mode(kwargs[ATTR_HVAC_MODE])

if ATTR_TEMPERATURE in kwargs:
operationmode = self.operation_mode()
omv = operationmode["value"]
value = kwargs[ATTR_TEMPERATURE]
res = await self._device.patch(
self._device.id,
self._embedded_id,
"temperatureControl",
f"/operationModes/{omv}/setpoints/{self._setpoint}",
value,
)
# When updating the value to the daikin cloud worked update our local cached version
if res:
setpointdict = self.setpoint()
if setpointdict is not None:
self._attr_target_temperature = value
self.async_write_ha_state()
if self._attr_target_temperature != value:
operationmode = self.operation_mode()
omv = operationmode["value"]
res = await self._device.patch(
self._device.id,
self._embedded_id,
"temperatureControl",
f"/operationModes/{omv}/setpoints/{self._setpoint}",
value,
)
# When updating the value to the daikin cloud worked update our local cached version
if res:
setpointdict = self.setpoint()
if setpointdict is not None:
self._attr_target_temperature = value
self.async_write_ha_state()

def get_hvac_mode(self):
"""Return current HVAC mode."""
Expand Down
11 changes: 11 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,17 @@ async def test_climate(
assert responses.calls[10].request.body == '{"value": 25.0, "path": "/operationModes/heating/setpoints/roomTemperature"}'
assert hass.states.get("climate.werkkamer_room_temperature").attributes["temperature"] == 25

# Set the target temperature another time to 25, should not result in a call to Daikin
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: "climate.werkkamer_room_temperature", ATTR_TEMPERATURE: 25},
blocking=True,
)
await hass.async_block_till_done()

assert len(responses.calls) == 11

# Set the hvac mode to cool and target temperature to 20 using one call
await hass.services.async_call(
CLIMATE_DOMAIN,
Expand Down

0 comments on commit 53a4ce7

Please sign in to comment.