mirror of
https://github.com/home-assistant/core
synced 2024-10-01 05:30:36 +02:00
parent
86f09a42a2
commit
e41753556c
@ -37,6 +37,7 @@ from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_DEVICE,
|
||||
CONF_NAME,
|
||||
CONF_TEMPERATURE_UNIT,
|
||||
CONF_VALUE_TEMPLATE,
|
||||
PRECISION_HALVES,
|
||||
PRECISION_TENTHS,
|
||||
@ -223,6 +224,7 @@ PLATFORM_SCHEMA = (
|
||||
vol.Optional(CONF_TEMP_LOW_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
||||
vol.Optional(CONF_TEMP_STATE_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_TEMP_STATE_TOPIC): mqtt.valid_subscribe_topic,
|
||||
vol.Optional(CONF_TEMPERATURE_UNIT): cv.temperature_unit,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
||||
}
|
||||
@ -294,7 +296,6 @@ class MqttClimate(
|
||||
self._target_temp_high = None
|
||||
self._target_temp_low = None
|
||||
self._topic = None
|
||||
self._unit_of_measurement = hass.config.units.temperature_unit
|
||||
self._value_templates = None
|
||||
|
||||
self._setup_from_config(config)
|
||||
@ -583,7 +584,9 @@ class MqttClimate(
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit_of_measurement
|
||||
if self._config.get(CONF_TEMPERATURE_UNIT):
|
||||
return self._config.get(CONF_TEMPERATURE_UNIT)
|
||||
return self.hass.config.units.temperature_unit
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
|
@ -793,6 +793,20 @@ async def test_temp_step_custom(hass, mqtt_mock):
|
||||
assert temp_step == 0.01
|
||||
|
||||
|
||||
async def test_temperature_unit(hass, mqtt_mock):
|
||||
"""Test that setting temperature unit converts temperature values."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config["climate"]["temperature_unit"] = "F"
|
||||
config["climate"]["current_temperature_topic"] = "current_temperature"
|
||||
|
||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
||||
|
||||
async_fire_mqtt_message(hass, "current_temperature", "77")
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("current_temperature") == 25
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
|
Loading…
Reference in New Issue
Block a user