Skip to content

Commit

Permalink
Send target temp to Shelly TRV in F when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
jra3 committed Jan 16, 2024
1 parent e8b962e commit de8c7c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions homeassistant/components/shelly/climate.py
Expand Up @@ -316,6 +316,21 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
"""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:
Expand Down
23 changes: 23 additions & 0 deletions tests/components/shelly/test_climate.py
Expand Up @@ -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(
Expand Down

0 comments on commit de8c7c4

Please sign in to comment.