Skip to content

Commit d0b34df

Browse files
authored
Have Plugwise handle unavailable temperature measurements (home-assistant#173173)
1 parent 390766b commit d0b34df

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

homeassistant/components/plugwise/climate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ def extra_restore_state_data(self) -> PlugwiseClimateExtraStoredData:
155155
)
156156

157157
@property
158-
def current_temperature(self) -> float:
158+
def current_temperature(self) -> float | None:
159159
"""Return the current temperature."""
160-
return self.device["sensors"]["temperature"]
160+
return self.device["sensors"].get("temperature")
161161

162162
@property
163163
def target_temperature(self) -> float:

tests/components/plugwise/test_climate.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from syrupy.assertion import SnapshotAssertion
1010

1111
from homeassistant.components.climate import (
12+
ATTR_CURRENT_TEMPERATURE,
1213
ATTR_HVAC_ACTION,
1314
ATTR_HVAC_MODE,
1415
ATTR_HVAC_MODES,
@@ -24,7 +25,13 @@
2425
HVACMode,
2526
)
2627
from homeassistant.components.plugwise.climate import PlugwiseClimateExtraStoredData
27-
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_OFF, STATE_ON
28+
from homeassistant.const import (
29+
ATTR_ENTITY_ID,
30+
ATTR_TEMPERATURE,
31+
STATE_OFF,
32+
STATE_ON,
33+
STATE_UNAVAILABLE,
34+
)
2835
from homeassistant.core import HomeAssistant, State
2936
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
3037
from homeassistant.helpers import entity_registry as er
@@ -680,3 +687,22 @@ async def test_anna_p1_climate_snapshot(
680687
) -> None:
681688
"""Test Anna P1 climate snapshot."""
682689
await snapshot_platform(hass, entity_registry, snapshot, setup_platform.entry_id)
690+
691+
692+
@pytest.mark.parametrize("chosen_env", ["m_adam_cooling"], indirect=True)
693+
@pytest.mark.parametrize("cooling_present", [False], indirect=True)
694+
async def test_tom_without_temperature_measurement(
695+
hass: HomeAssistant,
696+
mock_config_entry: MockConfigEntry,
697+
mock_smile_adam_heat_cool: MagicMock,
698+
) -> None:
699+
"""Test Tom without temperature measurement."""
700+
data = mock_smile_adam_heat_cool.async_update.return_value
701+
del data["f871b8c4d63549319221e294e4f88074"]["sensors"]["temperature"]
702+
mock_config_entry.add_to_hass(hass)
703+
await hass.config_entries.async_setup(mock_config_entry.entry_id)
704+
await hass.async_block_till_done()
705+
706+
assert (state := hass.states.get("climate.bathroom")) is not None
707+
assert state.state != STATE_UNAVAILABLE
708+
assert state.attributes[ATTR_CURRENT_TEMPERATURE] is None

0 commit comments

Comments
 (0)