Send target temp to Shelly TRV in F when needed (#108188)

pull/108270/head
John Allen 2024-01-17 15:06:11 -05:00 committed by GitHub
parent 97956702c9
commit a385ca93bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 0 deletions

View File

@ -316,6 +316,21 @@ class BlockSleepingClimate(
"""Set new target temperature."""
if (current_temp := kwargs.get(ATTR_TEMPERATURE)) is None:
return
# Shelly TRV accepts target_t in Fahrenheit or Celsius, but you must
# send the units that the device expects
if self.block is not None and self.block.channel is not None:
therm = self.coordinator.device.settings["thermostats"][
int(self.block.channel)
]
LOGGER.debug("Themostat settings: %s", therm)
if therm.get("target_t", {}).get("units", "C") == "F":
current_temp = TemperatureConverter.convert(
cast(float, current_temp),
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
)
await self.set_state_full_path(target_t_enabled=1, target_t=f"{current_temp}")
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:

View File

@ -146,6 +146,29 @@ async def test_climate_set_temperature(
mock_block_device.http_request.assert_called_once_with(
"get", "thermostat/0", {"target_t_enabled": 1, "target_t": "23.0"}
)
mock_block_device.http_request.reset_mock()
# Test conversion from C to F
monkeypatch.setattr(
mock_block_device,
"settings",
{
"thermostats": [
{"target_t": {"units": "F"}},
]
},
)
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 20},
blocking=True,
)
mock_block_device.http_request.assert_called_once_with(
"get", "thermostat/0", {"target_t_enabled": 1, "target_t": "68.0"}
)
async def test_climate_set_preset_mode(