diff --git a/homeassistant/components/fritzbox/climate.py b/homeassistant/components/fritzbox/climate.py index ef1285f0ec2..0f481773778 100644 --- a/homeassistant/components/fritzbox/climate.py +++ b/homeassistant/components/fritzbox/climate.py @@ -88,6 +88,8 @@ class FritzboxThermostat(FritzBoxEntity, ClimateEntity): @property def current_temperature(self) -> float: """Return the current temperature.""" + if self.device.has_temperature_sensor and self.device.temperature is not None: + return self.device.temperature # type: ignore [no-any-return] return self.device.actual_temperature # type: ignore [no-any-return] @property diff --git a/tests/components/fritzbox/__init__.py b/tests/components/fritzbox/__init__.py index 80052125f99..05003ccdf51 100644 --- a/tests/components/fritzbox/__init__.py +++ b/tests/components/fritzbox/__init__.py @@ -68,6 +68,7 @@ class FritzDeviceClimateMock(FritzDeviceBaseMock): """Mock of a AVM Fritz!Box climate device.""" actual_temperature = 18.0 + temperature = 18.0 alert_state = "fake_state" battery_level = 23 battery_low = True @@ -79,7 +80,7 @@ class FritzDeviceClimateMock(FritzDeviceBaseMock): has_powermeter = False has_lightbulb = False has_switch = False - has_temperature_sensor = False + has_temperature_sensor = True has_thermostat = True holiday_active = "fake_holiday" lock = "fake_locked" diff --git a/tests/components/fritzbox/test_climate.py b/tests/components/fritzbox/test_climate.py index 175b67df858..fc3b15c4199 100644 --- a/tests/components/fritzbox/test_climate.py +++ b/tests/components/fritzbox/test_climate.py @@ -186,7 +186,7 @@ async def test_update(hass: HomeAssistant, fritz: Mock): assert state.attributes[ATTR_MIN_TEMP] == 8 assert state.attributes[ATTR_TEMPERATURE] == 19.5 - device.actual_temperature = 19 + device.temperature = 19 device.target_temperature = 20 next_update = dt_util.utcnow() + timedelta(seconds=200) @@ -200,6 +200,24 @@ async def test_update(hass: HomeAssistant, fritz: Mock): assert state.attributes[ATTR_TEMPERATURE] == 20 +async def test_automatic_offset(hass: HomeAssistant, fritz: Mock): + """Test when automtaic offset is configured on fritz!box device.""" + device = FritzDeviceClimateMock() + device.temperature = 18 + device.actual_temperature = 19 + device.target_temperature = 20 + assert await setup_config_entry( + hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz + ) + + state = hass.states.get(ENTITY_ID) + assert state + assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 18 + assert state.attributes[ATTR_MAX_TEMP] == 28 + assert state.attributes[ATTR_MIN_TEMP] == 8 + assert state.attributes[ATTR_TEMPERATURE] == 20 + + async def test_update_error(hass: HomeAssistant, fritz: Mock): """Test update with error.""" device = FritzDeviceClimateMock()