[Draft] Use user's preferred temperature unit instead of hardcoding celsius (#460)
* Use user's preferred temperature unit instead of hardcoding celsius * Fix warnings about using is instead of == in tests
This commit is contained in:
@@ -283,7 +283,7 @@ class CentralConfigTemperatureNumber(
|
|||||||
self.entity_id = f"{NUMBER_DOMAIN}.{slugify(name)}_preset_{preset_name}"
|
self.entity_id = f"{NUMBER_DOMAIN}.{slugify(name)}_preset_{preset_name}"
|
||||||
self._attr_unique_id = f"central_configuration_preset_{preset_name}"
|
self._attr_unique_id = f"central_configuration_preset_{preset_name}"
|
||||||
self._attr_device_class = NumberDeviceClass.TEMPERATURE
|
self._attr_device_class = NumberDeviceClass.TEMPERATURE
|
||||||
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
self._attr_native_unit_of_measurement = hass.config.units.temperature_unit
|
||||||
|
|
||||||
self._attr_native_step = entry_infos.get(CONF_STEP_TEMPERATURE, 0.5)
|
self._attr_native_step = entry_infos.get(CONF_STEP_TEMPERATURE, 0.5)
|
||||||
self._attr_native_min_value = entry_infos.get(CONF_TEMP_MIN)
|
self._attr_native_min_value = entry_infos.get(CONF_TEMP_MIN)
|
||||||
@@ -371,7 +371,7 @@ class CentralConfigTemperatureNumber(
|
|||||||
# TODO Kelvin ? It seems not because all internal values are stored in
|
# TODO Kelvin ? It seems not because all internal values are stored in
|
||||||
# ° Celsius but only the render in front can be in °K depending on the
|
# ° Celsius but only the render in front can be in °K depending on the
|
||||||
# user configuration.
|
# user configuration.
|
||||||
return UnitOfTemperature.CELSIUS
|
return self.hass.config.units.temperature_unit
|
||||||
|
|
||||||
|
|
||||||
class TemperatureNumber( # pylint: disable=abstract-method
|
class TemperatureNumber( # pylint: disable=abstract-method
|
||||||
@@ -400,7 +400,7 @@ class TemperatureNumber( # pylint: disable=abstract-method
|
|||||||
|
|
||||||
self._attr_unique_id = f"{self._device_name}_preset_{preset_name}"
|
self._attr_unique_id = f"{self._device_name}_preset_{preset_name}"
|
||||||
self._attr_device_class = NumberDeviceClass.TEMPERATURE
|
self._attr_device_class = NumberDeviceClass.TEMPERATURE
|
||||||
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
self._attr_native_unit_of_measurement = hass.config.units.temperature_unit
|
||||||
|
|
||||||
self._has_central_main_attributes = entry_infos.get(
|
self._has_central_main_attributes = entry_infos.get(
|
||||||
CONF_USE_MAIN_CENTRAL_CONFIG, False
|
CONF_USE_MAIN_CENTRAL_CONFIG, False
|
||||||
@@ -498,7 +498,7 @@ class TemperatureNumber( # pylint: disable=abstract-method
|
|||||||
def native_unit_of_measurement(self) -> str | None:
|
def native_unit_of_measurement(self) -> str | None:
|
||||||
"""The unit of measurement"""
|
"""The unit of measurement"""
|
||||||
if not self.my_climate:
|
if not self.my_climate:
|
||||||
return UnitOfTemperature.CELSIUS
|
return self.hass.config.units.temperature_unit
|
||||||
return self.my_climate.temperature_unit
|
return self.my_climate.temperature_unit
|
||||||
|
|
||||||
def init_min_max_step(self, entry_infos=None):
|
def init_min_max_step(self, entry_infos=None):
|
||||||
|
|||||||
@@ -570,7 +570,7 @@ class RegulatedTemperatureSensor(VersatileThermostatBaseEntity, SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self) -> str | None:
|
def native_unit_of_measurement(self) -> str | None:
|
||||||
if not self.my_climate:
|
if not self.my_climate:
|
||||||
return UnitOfTemperature.CELSIUS
|
return self.hass.config.units.temperature_unit
|
||||||
return self.my_climate.temperature_unit
|
return self.my_climate.temperature_unit
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -621,7 +621,7 @@ class EMATemperatureSensor(VersatileThermostatBaseEntity, SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def native_unit_of_measurement(self) -> str | None:
|
def native_unit_of_measurement(self) -> str | None:
|
||||||
if not self.my_climate:
|
if not self.my_climate:
|
||||||
return UnitOfTemperature.CELSIUS
|
return self.hass.config.units.temperature_unit
|
||||||
return self.my_climate.temperature_unit
|
return self.my_climate.temperature_unit
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -663,7 +663,7 @@ class UnderlyingClimate(UnderlyingEntity):
|
|||||||
def temperature_unit(self) -> str:
|
def temperature_unit(self) -> str:
|
||||||
"""Get the temperature_unit"""
|
"""Get the temperature_unit"""
|
||||||
if not self.is_initialized:
|
if not self.is_initialized:
|
||||||
return UnitOfTemperature.CELSIUS
|
return self._hass.config.units.temperature_unit
|
||||||
return self._underlying_climate.temperature_unit
|
return self._underlying_climate.temperature_unit
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ async def test_add_a_central_config_with_boiler(
|
|||||||
assert api.nb_active_device_for_boiler == 0
|
assert api.nb_active_device_for_boiler == 0
|
||||||
|
|
||||||
assert api.nb_active_device_for_boiler_threshold_entity is not None
|
assert api.nb_active_device_for_boiler_threshold_entity is not None
|
||||||
assert api.nb_active_device_for_boiler_threshold is 1 # the default value is 1
|
assert api.nb_active_device_for_boiler_threshold == 1 # the default value is 1
|
||||||
|
|
||||||
|
|
||||||
async def test_update_central_boiler_state_simple(
|
async def test_update_central_boiler_state_simple(
|
||||||
|
|||||||
@@ -514,4 +514,4 @@ async def test_migration_of_central_config(
|
|||||||
assert api.nb_active_device_for_boiler == 0
|
assert api.nb_active_device_for_boiler == 0
|
||||||
|
|
||||||
assert api.nb_active_device_for_boiler_threshold_entity is not None
|
assert api.nb_active_device_for_boiler_threshold_entity is not None
|
||||||
assert api.nb_active_device_for_boiler_threshold is 1 # the default value is 1
|
assert api.nb_active_device_for_boiler_threshold == 1 # the default value is 1
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ async def test_movement_management_time_not_enough(
|
|||||||
await send_ext_temperature_change_event(entity, 10, event_timestamp)
|
await send_ext_temperature_change_event(entity, 10, event_timestamp)
|
||||||
|
|
||||||
await send_presence_change_event(entity, True, False, event_timestamp)
|
await send_presence_change_event(entity, True, False, event_timestamp)
|
||||||
assert entity.presence_state is "on"
|
assert entity.presence_state == "on"
|
||||||
|
|
||||||
# starts detecting motion with time not enough
|
# starts detecting motion with time not enough
|
||||||
with patch(
|
with patch(
|
||||||
@@ -110,7 +110,7 @@ async def test_movement_management_time_not_enough(
|
|||||||
assert entity.target_temperature == 18
|
assert entity.target_temperature == 18
|
||||||
# state is not changed if time is not enough
|
# state is not changed if time is not enough
|
||||||
assert entity.motion_state is None
|
assert entity.motion_state is None
|
||||||
assert entity.presence_state is "on"
|
assert entity.presence_state == "on"
|
||||||
|
|
||||||
assert mock_send_event.call_count == 0
|
assert mock_send_event.call_count == 0
|
||||||
# Change is not confirmed
|
# Change is not confirmed
|
||||||
@@ -141,8 +141,8 @@ async def test_movement_management_time_not_enough(
|
|||||||
assert entity.preset_mode is PRESET_ACTIVITY
|
assert entity.preset_mode is PRESET_ACTIVITY
|
||||||
# because motion is detected yet
|
# because motion is detected yet
|
||||||
assert entity.target_temperature == 19
|
assert entity.target_temperature == 19
|
||||||
assert entity.motion_state is "on"
|
assert entity.motion_state == "on"
|
||||||
assert entity.presence_state is "on"
|
assert entity.presence_state == "on"
|
||||||
|
|
||||||
# stop detecting motion with off delay too low
|
# stop detecting motion with off delay too low
|
||||||
with patch(
|
with patch(
|
||||||
@@ -167,8 +167,8 @@ async def test_movement_management_time_not_enough(
|
|||||||
assert entity.preset_mode is PRESET_ACTIVITY
|
assert entity.preset_mode is PRESET_ACTIVITY
|
||||||
# because no motion is detected yet
|
# because no motion is detected yet
|
||||||
assert entity.target_temperature == 19
|
assert entity.target_temperature == 19
|
||||||
assert entity.motion_state is "on"
|
assert entity.motion_state == "on"
|
||||||
assert entity.presence_state is "on"
|
assert entity.presence_state == "on"
|
||||||
|
|
||||||
assert mock_send_event.call_count == 0
|
assert mock_send_event.call_count == 0
|
||||||
# The heater must heat now
|
# The heater must heat now
|
||||||
@@ -199,8 +199,8 @@ async def test_movement_management_time_not_enough(
|
|||||||
assert entity.preset_mode is PRESET_ACTIVITY
|
assert entity.preset_mode is PRESET_ACTIVITY
|
||||||
# because no motion is detected yet
|
# because no motion is detected yet
|
||||||
assert entity.target_temperature == 18
|
assert entity.target_temperature == 18
|
||||||
assert entity.motion_state is "off"
|
assert entity.motion_state == "off"
|
||||||
assert entity.presence_state is "on"
|
assert entity.presence_state == "on"
|
||||||
|
|
||||||
assert mock_send_event.call_count == 0
|
assert mock_send_event.call_count == 0
|
||||||
# The heater must stop heating now
|
# The heater must stop heating now
|
||||||
@@ -280,7 +280,7 @@ async def test_movement_management_time_enough_and_presence(
|
|||||||
await send_ext_temperature_change_event(entity, 10, event_timestamp)
|
await send_ext_temperature_change_event(entity, 10, event_timestamp)
|
||||||
|
|
||||||
await send_presence_change_event(entity, True, False, event_timestamp)
|
await send_presence_change_event(entity, True, False, event_timestamp)
|
||||||
assert entity.presence_state is "on"
|
assert entity.presence_state == "on"
|
||||||
|
|
||||||
# starts detecting motion
|
# starts detecting motion
|
||||||
with patch(
|
with patch(
|
||||||
@@ -302,8 +302,8 @@ async def test_movement_management_time_enough_and_presence(
|
|||||||
assert entity.preset_mode is PRESET_ACTIVITY
|
assert entity.preset_mode is PRESET_ACTIVITY
|
||||||
# because motion is detected yet -> switch to Boost mode
|
# because motion is detected yet -> switch to Boost mode
|
||||||
assert entity.target_temperature == 19
|
assert entity.target_temperature == 19
|
||||||
assert entity.motion_state is "on"
|
assert entity.motion_state == "on"
|
||||||
assert entity.presence_state is "on"
|
assert entity.presence_state == "on"
|
||||||
|
|
||||||
assert mock_send_event.call_count == 0
|
assert mock_send_event.call_count == 0
|
||||||
# Change is confirmed. Heater should be started
|
# Change is confirmed. Heater should be started
|
||||||
@@ -331,8 +331,8 @@ async def test_movement_management_time_enough_and_presence(
|
|||||||
assert entity.preset_mode is PRESET_ACTIVITY
|
assert entity.preset_mode is PRESET_ACTIVITY
|
||||||
# because no motion is detected yet
|
# because no motion is detected yet
|
||||||
assert entity.target_temperature == 18
|
assert entity.target_temperature == 18
|
||||||
assert entity.motion_state is "off"
|
assert entity.motion_state == "off"
|
||||||
assert entity.presence_state is "on"
|
assert entity.presence_state == "on"
|
||||||
|
|
||||||
assert mock_send_event.call_count == 0
|
assert mock_send_event.call_count == 0
|
||||||
assert mock_heater_on.call_count == 0
|
assert mock_heater_on.call_count == 0
|
||||||
@@ -412,7 +412,7 @@ async def test_movement_management_time_enoughand_not_presence(
|
|||||||
await send_ext_temperature_change_event(entity, 10, event_timestamp)
|
await send_ext_temperature_change_event(entity, 10, event_timestamp)
|
||||||
|
|
||||||
await send_presence_change_event(entity, False, True, event_timestamp)
|
await send_presence_change_event(entity, False, True, event_timestamp)
|
||||||
assert entity.presence_state is "off"
|
assert entity.presence_state == "off"
|
||||||
|
|
||||||
# starts detecting motion
|
# starts detecting motion
|
||||||
with patch(
|
with patch(
|
||||||
@@ -434,8 +434,8 @@ async def test_movement_management_time_enoughand_not_presence(
|
|||||||
assert entity.preset_mode is PRESET_ACTIVITY
|
assert entity.preset_mode is PRESET_ACTIVITY
|
||||||
# because motion is detected yet -> switch to Boost away mode
|
# because motion is detected yet -> switch to Boost away mode
|
||||||
assert entity.target_temperature == 19.1
|
assert entity.target_temperature == 19.1
|
||||||
assert entity.motion_state is "on"
|
assert entity.motion_state == "on"
|
||||||
assert entity.presence_state is "off"
|
assert entity.presence_state == "off"
|
||||||
|
|
||||||
assert mock_send_event.call_count == 0
|
assert mock_send_event.call_count == 0
|
||||||
# Change is confirmed. Heater should be started
|
# Change is confirmed. Heater should be started
|
||||||
@@ -463,8 +463,8 @@ async def test_movement_management_time_enoughand_not_presence(
|
|||||||
assert entity.preset_mode is PRESET_ACTIVITY
|
assert entity.preset_mode is PRESET_ACTIVITY
|
||||||
# because no motion is detected yet
|
# because no motion is detected yet
|
||||||
assert entity.target_temperature == 18.1
|
assert entity.target_temperature == 18.1
|
||||||
assert entity.motion_state is "off"
|
assert entity.motion_state == "off"
|
||||||
assert entity.presence_state is "off"
|
assert entity.presence_state == "off"
|
||||||
|
|
||||||
assert mock_send_event.call_count == 0
|
assert mock_send_event.call_count == 0
|
||||||
# 18.1 starts heating with a low on_percent
|
# 18.1 starts heating with a low on_percent
|
||||||
@@ -546,7 +546,7 @@ async def test_movement_management_with_stop_during_condition(
|
|||||||
await send_ext_temperature_change_event(entity, 10, event_timestamp)
|
await send_ext_temperature_change_event(entity, 10, event_timestamp)
|
||||||
|
|
||||||
await send_presence_change_event(entity, False, True, event_timestamp)
|
await send_presence_change_event(entity, False, True, event_timestamp)
|
||||||
assert entity.presence_state is "off"
|
assert entity.presence_state == "off"
|
||||||
|
|
||||||
# starts detecting motion
|
# starts detecting motion
|
||||||
with patch(
|
with patch(
|
||||||
@@ -569,7 +569,7 @@ async def test_movement_management_with_stop_during_condition(
|
|||||||
# because motion is detected yet -> switch to Boost mode
|
# because motion is detected yet -> switch to Boost mode
|
||||||
assert entity.target_temperature == 18
|
assert entity.target_temperature == 18
|
||||||
assert entity.motion_state is None
|
assert entity.motion_state is None
|
||||||
assert entity.presence_state is "off"
|
assert entity.presence_state == "off"
|
||||||
|
|
||||||
# Send a stop detection
|
# Send a stop detection
|
||||||
event_timestamp = now - timedelta(minutes=4)
|
event_timestamp = now - timedelta(minutes=4)
|
||||||
@@ -580,7 +580,7 @@ async def test_movement_management_with_stop_during_condition(
|
|||||||
assert entity.preset_mode is PRESET_ACTIVITY
|
assert entity.preset_mode is PRESET_ACTIVITY
|
||||||
assert entity.target_temperature == 18
|
assert entity.target_temperature == 18
|
||||||
assert entity.motion_state is None
|
assert entity.motion_state is None
|
||||||
assert entity.presence_state is "off"
|
assert entity.presence_state == "off"
|
||||||
|
|
||||||
# Resend a start detection
|
# Resend a start detection
|
||||||
event_timestamp = now - timedelta(minutes=3)
|
event_timestamp = now - timedelta(minutes=3)
|
||||||
@@ -592,10 +592,10 @@ async def test_movement_management_with_stop_during_condition(
|
|||||||
# still no motion detected
|
# still no motion detected
|
||||||
assert entity.target_temperature == 18
|
assert entity.target_temperature == 18
|
||||||
assert entity.motion_state is None
|
assert entity.motion_state is None
|
||||||
assert entity.presence_state is "off"
|
assert entity.presence_state == "off"
|
||||||
|
|
||||||
await try_condition1(None)
|
await try_condition1(None)
|
||||||
# We should have switch this time
|
# We should have switch this time
|
||||||
assert entity.target_temperature == 19 # Boost
|
assert entity.target_temperature == 19 # Boost
|
||||||
assert entity.motion_state is "on" # switch to movement on
|
assert entity.motion_state == "on" # switch to movement on
|
||||||
assert entity.presence_state is "off" # Non change
|
assert entity.presence_state == "off" # Non change
|
||||||
|
|||||||
Reference in New Issue
Block a user