Fix rounding regulated + offset (#384)
Co-authored-by: Jean-Marc Collin <jean-marc.collin-extern@renault.com>
This commit is contained in:
@@ -216,7 +216,7 @@ class ThermostatOverClimate(BaseThermostat):
|
||||
):
|
||||
offset_temp = device_temp - self.current_temperature
|
||||
|
||||
target_temp = self.regulated_target_temp + offset_temp
|
||||
target_temp = round_to_nearest(self.regulated_target_temp + offset_temp, self._auto_regulation_dtemp)
|
||||
|
||||
_LOGGER.debug(
|
||||
"%s - The device offset temp for regulation is %.2f - internal temp is %.2f. New target is %.2f",
|
||||
@@ -491,9 +491,9 @@ class ThermostatOverClimate(BaseThermostat):
|
||||
super().update_custom_attributes()
|
||||
|
||||
self._attr_extra_state_attributes["is_over_climate"] = self.is_over_climate
|
||||
self._attr_extra_state_attributes[
|
||||
"start_hvac_action_date"
|
||||
] = self._underlying_climate_start_hvac_action_date
|
||||
self._attr_extra_state_attributes["start_hvac_action_date"] = (
|
||||
self._underlying_climate_start_hvac_action_date
|
||||
)
|
||||
self._attr_extra_state_attributes["underlying_climate_0"] = self._underlyings[
|
||||
0
|
||||
].entity_id
|
||||
@@ -509,32 +509,32 @@ class ThermostatOverClimate(BaseThermostat):
|
||||
|
||||
if self.is_regulated:
|
||||
self._attr_extra_state_attributes["is_regulated"] = self.is_regulated
|
||||
self._attr_extra_state_attributes[
|
||||
"regulated_target_temperature"
|
||||
] = self._regulated_target_temp
|
||||
self._attr_extra_state_attributes[
|
||||
"auto_regulation_mode"
|
||||
] = self.auto_regulation_mode
|
||||
self._attr_extra_state_attributes[
|
||||
"regulation_accumulated_error"
|
||||
] = self._regulation_algo.accumulated_error
|
||||
self._attr_extra_state_attributes["regulated_target_temperature"] = (
|
||||
self._regulated_target_temp
|
||||
)
|
||||
self._attr_extra_state_attributes["auto_regulation_mode"] = (
|
||||
self.auto_regulation_mode
|
||||
)
|
||||
self._attr_extra_state_attributes["regulation_accumulated_error"] = (
|
||||
self._regulation_algo.accumulated_error
|
||||
)
|
||||
|
||||
self._attr_extra_state_attributes["auto_fan_mode"] = self.auto_fan_mode
|
||||
self._attr_extra_state_attributes[
|
||||
"current_auto_fan_mode"
|
||||
] = self._current_auto_fan_mode
|
||||
self._attr_extra_state_attributes["current_auto_fan_mode"] = (
|
||||
self._current_auto_fan_mode
|
||||
)
|
||||
|
||||
self._attr_extra_state_attributes[
|
||||
"auto_activated_fan_mode"
|
||||
] = self._auto_activated_fan_mode
|
||||
self._attr_extra_state_attributes["auto_activated_fan_mode"] = (
|
||||
self._auto_activated_fan_mode
|
||||
)
|
||||
|
||||
self._attr_extra_state_attributes[
|
||||
"auto_deactivated_fan_mode"
|
||||
] = self._auto_deactivated_fan_mode
|
||||
self._attr_extra_state_attributes["auto_deactivated_fan_mode"] = (
|
||||
self._auto_deactivated_fan_mode
|
||||
)
|
||||
|
||||
self._attr_extra_state_attributes[
|
||||
"auto_regulation_use_device_temp"
|
||||
] = self.auto_regulation_use_device_temp
|
||||
self._attr_extra_state_attributes["auto_regulation_use_device_temp"] = (
|
||||
self.auto_regulation_use_device_temp
|
||||
)
|
||||
|
||||
self.async_write_ha_state()
|
||||
_LOGGER.debug(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
""" The commons const for all tests """
|
||||
|
||||
from homeassistant.components.climate.const import ( # pylint: disable=unused-import
|
||||
PRESET_BOOST,
|
||||
PRESET_COMFORT,
|
||||
@@ -52,7 +53,7 @@ MOCK_TH_OVER_CLIMATE_MAIN_CONFIG = {
|
||||
CONF_CYCLE_MIN: 5,
|
||||
CONF_DEVICE_POWER: 1,
|
||||
CONF_USE_MAIN_CENTRAL_CONFIG: False,
|
||||
CONF_USE_CENTRAL_MODE: True
|
||||
CONF_USE_CENTRAL_MODE: True,
|
||||
# Keep default values which are False
|
||||
}
|
||||
|
||||
|
||||
@@ -387,7 +387,7 @@ async def test_over_climate_regulation_use_device_temp(
|
||||
title="TheOverClimateMockName",
|
||||
unique_id="uniqueId",
|
||||
# This is include a medium regulation
|
||||
data=PARTIAL_CLIMATE_CONFIG_USE_DEVICE_TEMP,
|
||||
data=PARTIAL_CLIMATE_CONFIG_USE_DEVICE_TEMP | {CONF_AUTO_REGULATION_DTEMP: 0.5},
|
||||
)
|
||||
|
||||
tz = get_tz(hass) # pylint: disable=invalid-name
|
||||
@@ -475,7 +475,7 @@ async def test_over_climate_regulation_use_device_temp(
|
||||
# room temp is 15
|
||||
# target is 18
|
||||
# internal heater temp is 20
|
||||
fake_underlying_climate.set_current_temperature(20)
|
||||
fake_underlying_climate.set_current_temperature(20.1)
|
||||
await entity.async_set_temperature(temperature=18)
|
||||
await send_ext_temperature_change_event(entity, 9, event_timestamp)
|
||||
|
||||
@@ -488,7 +488,7 @@ async def test_over_climate_regulation_use_device_temp(
|
||||
|
||||
# the regulated temperature should be under (device offset is -2)
|
||||
assert entity.regulated_target_temp > entity.target_temperature
|
||||
assert entity.regulated_target_temp == 19.4 # 18 + 1.4
|
||||
assert entity.regulated_target_temp == 19.5 # round(18 + 1.4, 0.5)
|
||||
|
||||
mock_service_call.assert_has_calls(
|
||||
[
|
||||
@@ -497,7 +497,7 @@ async def test_over_climate_regulation_use_device_temp(
|
||||
"set_temperature",
|
||||
{
|
||||
"entity_id": "climate.mock_climate",
|
||||
"temperature": 24.4, # 19.4 + 5
|
||||
"temperature": 24.5, # round(19.5 + 5, 0.5)
|
||||
"target_temp_high": 30,
|
||||
"target_temp_low": 15,
|
||||
},
|
||||
@@ -511,7 +511,7 @@ async def test_over_climate_regulation_use_device_temp(
|
||||
# internal heater temp is 27
|
||||
await entity.async_set_hvac_mode(HVACMode.COOL)
|
||||
await entity.async_set_temperature(temperature=23)
|
||||
fake_underlying_climate.set_current_temperature(27)
|
||||
fake_underlying_climate.set_current_temperature(26.9)
|
||||
await send_ext_temperature_change_event(entity, 30, event_timestamp)
|
||||
|
||||
event_timestamp = now - timedelta(minutes=3)
|
||||
@@ -521,9 +521,9 @@ async def test_over_climate_regulation_use_device_temp(
|
||||
), patch("homeassistant.core.ServiceRegistry.async_call") as mock_service_call:
|
||||
await send_temperature_change_event(entity, 25, event_timestamp)
|
||||
|
||||
# the regulated temperature should be upper (device offset is +2)
|
||||
# the regulated temperature should be upper (device offset is +1.9)
|
||||
assert entity.regulated_target_temp < entity.target_temperature
|
||||
assert entity.regulated_target_temp == 22.4
|
||||
assert entity.regulated_target_temp == 22.5
|
||||
|
||||
mock_service_call.assert_has_calls(
|
||||
[
|
||||
@@ -532,7 +532,7 @@ async def test_over_climate_regulation_use_device_temp(
|
||||
"set_temperature",
|
||||
{
|
||||
"entity_id": "climate.mock_climate",
|
||||
"temperature": 24.4, # 22.4 + 2° of offset
|
||||
"temperature": 24.5, # round(22.5 + 1.9° of offset)
|
||||
"target_temp_high": 30,
|
||||
"target_temp_low": 15,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user