Add mqtt temp_low/high_template in SCHEMA_BASE (#28257)

* fix missing temp_low/high_template in SCHEMA_BASE

* temperature_high/low_state_template test

* Update test_climate.py

* paste error

* Update test_climate.py

* Update test_climate.py

* Update test_climate.py

* Update test_climate.py
This commit is contained in:
Kevin Köck 2019-11-06 13:50:54 +01:00 committed by Charles Garwood
parent 2e1d05560f
commit b7153ca207
2 changed files with 35 additions and 0 deletions

View file

@ -214,7 +214,9 @@ PLATFORM_SCHEMA = (
vol.Optional(CONF_TEMP_COMMAND_TOPIC): mqtt.valid_publish_topic,
vol.Optional(CONF_TEMP_HIGH_COMMAND_TOPIC): mqtt.valid_publish_topic,
vol.Optional(CONF_TEMP_HIGH_STATE_TOPIC): mqtt.valid_subscribe_topic,
vol.Optional(CONF_TEMP_HIGH_STATE_TEMPLATE): cv.template,
vol.Optional(CONF_TEMP_LOW_COMMAND_TOPIC): mqtt.valid_publish_topic,
vol.Optional(CONF_TEMP_LOW_STATE_TEMPLATE): cv.template,
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,

View file

@ -568,6 +568,39 @@ async def test_custom_availability_payload(hass, mqtt_mock):
assert state.state == STATE_UNAVAILABLE
async def test_set_target_temperature_low_high_with_templates(hass, mqtt_mock, caplog):
"""Test setting of temperature high/low templates."""
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["temperature_low_state_topic"] = "temperature-state"
config["climate"]["temperature_high_state_topic"] = "temperature-state"
config["climate"]["temperature_low_state_template"] = "{{ value_json.temp_low }}"
config["climate"]["temperature_high_state_template"] = "{{ value_json.temp_high }}"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
state = hass.states.get(ENTITY_CLIMATE)
# Temperature - with valid value
assert state.attributes.get("target_temp_low") is None
assert state.attributes.get("target_temp_high") is None
async_fire_mqtt_message(
hass, "temperature-state", '{"temp_low": "1031", "temp_high": "1032"}'
)
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("target_temp_low") == 1031
assert state.attributes.get("target_temp_high") == 1032
# Temperature - with invalid value
async_fire_mqtt_message(hass, "temperature-state", '"-INVALID-"')
state = hass.states.get(ENTITY_CLIMATE)
# make sure, the invalid value gets logged...
assert "Could not parse temperature from" in caplog.text
# ... but the actual value stays unchanged.
assert state.attributes.get("target_temp_low") == 1031
assert state.attributes.get("target_temp_high") == 1032
async def test_set_with_templates(hass, mqtt_mock, caplog):
"""Test setting of new fan mode in pessimistic mode."""
config = copy.deepcopy(DEFAULT_CONFIG)