Skip to content

Commit

Permalink
Fix incomfort invalid setpoint if override is reported as 0.0 (home-a…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh authored and frenck committed Sep 16, 2024
1 parent 1e63b95 commit d0b6ef8
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
4 changes: 3 additions & 1 deletion homeassistant/components/incomfort/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ def target_temperature(self) -> float | None:
As we set the override, we report back the override. The actual set point is
is returned at a later time.
Some older thermostats return 0.0 as override, in that case we fallback to
the actual setpoint.
"""
return self._room.override
return self._room.override or self._room.setpoint

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set a new target temperature for this zone."""
Expand Down
70 changes: 68 additions & 2 deletions tests/components/incomfort/snapshots/test_climate.ambr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# serializer version: 1
# name: test_setup_platform[climate.thermostat_1-entry]
# name: test_setup_platform[legacy_thermostat][climate.thermostat_1-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
Expand Down Expand Up @@ -38,7 +38,73 @@
'unit_of_measurement': None,
})
# ---
# name: test_setup_platform[climate.thermostat_1-state]
# name: test_setup_platform[legacy_thermostat][climate.thermostat_1-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_temperature': 21.4,
'friendly_name': 'Thermostat 1',
'hvac_action': <HVACAction.IDLE: 'idle'>,
'hvac_modes': list([
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 30.0,
'min_temp': 5.0,
'status': dict({
'override': 0.0,
'room_temp': 21.42,
'setpoint': 18.0,
}),
'supported_features': <ClimateEntityFeature: 1>,
'temperature': 18.0,
}),
'context': <ANY>,
'entity_id': 'climate.thermostat_1',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'heat',
})
# ---
# name: test_setup_platform[new_thermostat][climate.thermostat_1-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'hvac_modes': list([
<HVACMode.HEAT: 'heat'>,
]),
'max_temp': 30.0,
'min_temp': 5.0,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'climate',
'entity_category': None,
'entity_id': 'climate.thermostat_1',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': None,
'platform': 'incomfort',
'previous_unique_id': None,
'supported_features': <ClimateEntityFeature: 1>,
'translation_key': None,
'unique_id': 'c0ffeec0ffee_1',
'unit_of_measurement': None,
})
# ---
# name: test_setup_platform[new_thermostat][climate.thermostat_1-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'current_temperature': 21.4,
Expand Down
15 changes: 14 additions & 1 deletion tests/components/incomfort/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from unittest.mock import MagicMock, patch

import pytest
from syrupy import SnapshotAssertion

from homeassistant.config_entries import ConfigEntry
Expand All @@ -13,13 +14,25 @@


@patch("homeassistant.components.incomfort.PLATFORMS", [Platform.CLIMATE])
@pytest.mark.parametrize(
"mock_room_status",
[
{"room_temp": 21.42, "setpoint": 18.0, "override": 18.0},
{"room_temp": 21.42, "setpoint": 18.0, "override": 0.0},
],
ids=["new_thermostat", "legacy_thermostat"],
)
async def test_setup_platform(
hass: HomeAssistant,
mock_incomfort: MagicMock,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
mock_config_entry: ConfigEntry,
) -> None:
"""Test the incomfort entities are set up correctly."""
"""Test the incomfort entities are set up correctly.
Legacy thermostats report 0.0 as override if no override is set,
but new thermostat sync the override with the actual setpoint instead.
"""
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)

0 comments on commit d0b6ef8

Please sign in to comment.