2017-09-30 14:29:40 +00:00
|
|
|
"""The tests for the mqtt climate component."""
|
|
|
|
import copy
|
2018-12-15 16:28:08 +00:00
|
|
|
import json
|
2021-01-01 21:31:56 +00:00
|
|
|
from unittest.mock import call, patch
|
2017-09-30 14:29:40 +00:00
|
|
|
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
import pytest
|
2019-04-25 08:14:16 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2022-01-03 08:03:47 +00:00
|
|
|
from homeassistant.components import climate
|
2019-07-31 19:25:30 +00:00
|
|
|
from homeassistant.components.climate import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP
|
2019-02-14 19:34:43 +00:00
|
|
|
from homeassistant.components.climate.const import (
|
2022-01-03 15:08:07 +00:00
|
|
|
ATTR_AUX_HEAT,
|
|
|
|
ATTR_CURRENT_TEMPERATURE,
|
|
|
|
ATTR_FAN_MODE,
|
2021-11-25 14:53:34 +00:00
|
|
|
ATTR_HVAC_ACTION,
|
2022-01-03 15:08:07 +00:00
|
|
|
ATTR_PRESET_MODE,
|
|
|
|
ATTR_SWING_MODE,
|
|
|
|
ATTR_TARGET_TEMP_HIGH,
|
|
|
|
ATTR_TARGET_TEMP_LOW,
|
2021-11-25 14:53:34 +00:00
|
|
|
CURRENT_HVAC_ACTIONS,
|
2019-02-14 19:34:43 +00:00
|
|
|
DOMAIN as CLIMATE_DOMAIN,
|
2019-07-31 19:25:30 +00:00
|
|
|
HVAC_MODE_AUTO,
|
|
|
|
HVAC_MODE_COOL,
|
|
|
|
HVAC_MODE_DRY,
|
|
|
|
HVAC_MODE_FAN_ONLY,
|
2019-12-08 17:15:26 +00:00
|
|
|
HVAC_MODE_HEAT,
|
2022-01-11 16:08:26 +00:00
|
|
|
PRESET_AWAY,
|
2019-11-26 04:53:37 +00:00
|
|
|
PRESET_ECO,
|
2019-12-08 17:15:26 +00:00
|
|
|
PRESET_NONE,
|
|
|
|
SUPPORT_AUX_HEAT,
|
|
|
|
SUPPORT_FAN_MODE,
|
|
|
|
SUPPORT_PRESET_MODE,
|
|
|
|
SUPPORT_SWING_MODE,
|
|
|
|
SUPPORT_TARGET_TEMPERATURE,
|
|
|
|
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2021-06-29 09:13:58 +00:00
|
|
|
from homeassistant.components.mqtt.climate import MQTT_CLIMATE_ATTRIBUTES_BLOCKED
|
2022-01-03 15:08:07 +00:00
|
|
|
from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF
|
2020-06-23 17:17:22 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2019-01-27 17:54:52 +00:00
|
|
|
|
2020-03-30 21:26:59 +00:00
|
|
|
from .test_common import (
|
2020-06-07 07:21:16 +00:00
|
|
|
help_test_availability_when_connection_lost,
|
2020-03-17 07:09:19 +00:00
|
|
|
help_test_availability_without_topic,
|
|
|
|
help_test_custom_availability_payload,
|
|
|
|
help_test_default_availability_payload,
|
2020-03-09 16:40:00 +00:00
|
|
|
help_test_discovery_broken,
|
|
|
|
help_test_discovery_removal,
|
|
|
|
help_test_discovery_update,
|
|
|
|
help_test_discovery_update_attr,
|
2020-08-06 08:43:47 +00:00
|
|
|
help_test_discovery_update_unchanged,
|
2022-01-03 15:08:07 +00:00
|
|
|
help_test_encoding_subscribable_topics,
|
2020-04-01 18:48:32 +00:00
|
|
|
help_test_entity_debug_info_message,
|
2020-03-12 01:00:47 +00:00
|
|
|
help_test_entity_device_info_remove,
|
2020-03-09 16:40:00 +00:00
|
|
|
help_test_entity_device_info_update,
|
2020-03-17 07:09:19 +00:00
|
|
|
help_test_entity_device_info_with_connection,
|
2020-03-09 16:40:00 +00:00
|
|
|
help_test_entity_device_info_with_identifier,
|
2020-03-30 21:26:59 +00:00
|
|
|
help_test_entity_id_update_discovery_update,
|
|
|
|
help_test_entity_id_update_subscriptions,
|
2022-01-03 08:03:47 +00:00
|
|
|
help_test_publishing_with_custom_encoding,
|
2022-01-03 14:14:50 +00:00
|
|
|
help_test_reloadable,
|
2022-02-10 20:09:57 +00:00
|
|
|
help_test_reloadable_late,
|
2020-03-09 16:40:00 +00:00
|
|
|
help_test_setting_attribute_via_mqtt_json_message,
|
2020-03-17 07:09:19 +00:00
|
|
|
help_test_setting_attribute_with_template,
|
2021-06-29 09:13:58 +00:00
|
|
|
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
2020-03-09 16:40:00 +00:00
|
|
|
help_test_unique_id,
|
|
|
|
help_test_update_with_json_attrs_bad_JSON,
|
|
|
|
help_test_update_with_json_attrs_not_dict,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2020-03-09 16:40:00 +00:00
|
|
|
|
2020-06-23 17:17:22 +00:00
|
|
|
from tests.common import async_fire_mqtt_message
|
2018-09-26 07:49:55 +00:00
|
|
|
from tests.components.climate import common
|
2017-09-30 14:29:40 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ENTITY_CLIMATE = "climate.test"
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
DEFAULT_CONFIG = {
|
2020-03-17 07:09:19 +00:00
|
|
|
CLIMATE_DOMAIN: {
|
2019-07-31 19:25:30 +00:00
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"mode_command_topic": "mode-topic",
|
|
|
|
"temperature_command_topic": "temperature-topic",
|
|
|
|
"temperature_low_command_topic": "temperature-low-topic",
|
|
|
|
"temperature_high_command_topic": "temperature-high-topic",
|
|
|
|
"fan_mode_command_topic": "fan-mode-topic",
|
|
|
|
"swing_mode_command_topic": "swing-mode-topic",
|
2022-02-17 12:51:35 +00:00
|
|
|
"aux_command_topic": "aux-topic",
|
|
|
|
"preset_mode_command_topic": "preset-mode-topic",
|
|
|
|
"preset_modes": [
|
|
|
|
"eco",
|
|
|
|
"away",
|
|
|
|
"boost",
|
|
|
|
"comfort",
|
|
|
|
"home",
|
|
|
|
"sleep",
|
|
|
|
"activity",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
|
|
|
DEFAULT_LEGACY_CONFIG = {
|
|
|
|
CLIMATE_DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"mode_command_topic": "mode-topic",
|
|
|
|
"temperature_command_topic": "temperature-topic",
|
|
|
|
"temperature_low_command_topic": "temperature-low-topic",
|
|
|
|
"temperature_high_command_topic": "temperature-high-topic",
|
|
|
|
"fan_mode_command_topic": "fan-mode-topic",
|
|
|
|
"swing_mode_command_topic": "swing-mode-topic",
|
|
|
|
"aux_command_topic": "aux-topic",
|
2019-07-31 19:25:30 +00:00
|
|
|
"away_mode_command_topic": "away-mode-topic",
|
|
|
|
"hold_command_topic": "hold-topic",
|
|
|
|
}
|
|
|
|
}
|
2017-09-30 14:29:40 +00:00
|
|
|
|
|
|
|
|
2019-04-19 21:08:54 +00:00
|
|
|
async def test_setup_params(hass, mqtt_mock):
|
|
|
|
"""Test the initial parameters."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 21
|
|
|
|
assert state.attributes.get("fan_mode") == "low"
|
|
|
|
assert state.attributes.get("swing_mode") == "off"
|
|
|
|
assert state.state == "off"
|
|
|
|
assert state.attributes.get("min_temp") == DEFAULT_MIN_TEMP
|
|
|
|
assert state.attributes.get("max_temp") == DEFAULT_MAX_TEMP
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
async def test_preset_none_in_preset_modes(hass, mqtt_mock, caplog):
|
|
|
|
"""Test the preset mode payload reset configuration."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG[CLIMATE_DOMAIN])
|
|
|
|
config["preset_modes"].append("none")
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, {CLIMATE_DOMAIN: config})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert "Invalid config for [climate.mqtt]: not a valid value" in caplog.text
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state is None
|
|
|
|
|
|
|
|
|
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"parameter,config_value",
|
|
|
|
[
|
|
|
|
("away_mode_command_topic", "away-mode-command-topic"),
|
|
|
|
("away_mode_state_topic", "away-mode-state-topic"),
|
|
|
|
("away_mode_state_template", "{{ value_json }}"),
|
|
|
|
("hold_mode_command_topic", "hold-mode-command-topic"),
|
|
|
|
("hold_mode_command_template", "hold-mode-command-template"),
|
|
|
|
("hold_mode_state_topic", "hold-mode-state-topic"),
|
|
|
|
("hold_mode_state_template", "{{ value_json }}"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
async def test_preset_modes_deprecation_guard(
|
|
|
|
hass, mqtt_mock, caplog, parameter, config_value
|
|
|
|
):
|
|
|
|
"""Test the configuration for invalid legacy parameters."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG[CLIMATE_DOMAIN])
|
|
|
|
config[parameter] = config_value
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, {CLIMATE_DOMAIN: config})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state is None
|
|
|
|
|
|
|
|
|
2019-04-19 21:08:54 +00:00
|
|
|
async def test_supported_features(hass, mqtt_mock):
|
|
|
|
"""Test the supported_features."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
support = (
|
|
|
|
SUPPORT_TARGET_TEMPERATURE
|
|
|
|
| SUPPORT_SWING_MODE
|
|
|
|
| SUPPORT_FAN_MODE
|
|
|
|
| SUPPORT_PRESET_MODE
|
|
|
|
| SUPPORT_AUX_HEAT
|
|
|
|
| SUPPORT_TARGET_TEMPERATURE_RANGE
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
assert state.attributes.get("supported_features") == support
|
|
|
|
|
|
|
|
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
async def test_get_hvac_modes(hass, mqtt_mock):
|
2019-04-19 21:08:54 +00:00
|
|
|
"""Test that the operation list returns the correct modes."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
modes = state.attributes.get("hvac_modes")
|
2019-04-19 21:08:54 +00:00
|
|
|
assert [
|
2019-07-31 19:25:30 +00:00
|
|
|
HVAC_MODE_AUTO,
|
|
|
|
STATE_OFF,
|
|
|
|
HVAC_MODE_COOL,
|
|
|
|
HVAC_MODE_HEAT,
|
|
|
|
HVAC_MODE_DRY,
|
|
|
|
HVAC_MODE_FAN_ONLY,
|
2019-04-19 21:08:54 +00:00
|
|
|
] == modes
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
|
|
|
|
"""Test setting operation mode without required attribute.
|
|
|
|
|
|
|
|
Also check the state.
|
|
|
|
"""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "off"
|
2019-04-25 08:14:16 +00:00
|
|
|
with pytest.raises(vol.Invalid) as excinfo:
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
await common.async_set_hvac_mode(hass, None, ENTITY_CLIMATE)
|
2020-12-07 01:49:36 +00:00
|
|
|
assert (
|
|
|
|
"value must be one of ['auto', 'cool', 'dry', 'fan_only', 'heat', 'heat_cool', 'off'] for dictionary value @ data['hvac_mode']"
|
|
|
|
) in str(excinfo.value)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "off"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_operation(hass, mqtt_mock):
|
|
|
|
"""Test setting of new operation mode."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "off"
|
|
|
|
await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "cool"
|
|
|
|
assert state.state == "cool"
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with("mode-topic", "cool", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_operation_pessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting operation mode in pessimistic mode."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["mode_state_topic"] = "mode-state"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "unknown"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "unknown"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "mode-state", "cool")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "cool"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "mode-state", "bogus mode")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "cool"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_operation_with_power_command(hass, mqtt_mock):
|
|
|
|
"""Test setting of new operation mode with power command enabled."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["power_command_topic"] = "power-command"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "off"
|
|
|
|
await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "cool"
|
|
|
|
mqtt_mock.async_publish.assert_has_calls(
|
2020-05-03 18:27:19 +00:00
|
|
|
[call("power-command", "ON", 0, False), call("mode-topic", "cool", 0, False)]
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_hvac_mode(hass, "off", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "off"
|
|
|
|
mqtt_mock.async_publish.assert_has_calls(
|
2020-05-03 18:27:19 +00:00
|
|
|
[call("power-command", "OFF", 0, False), call("mode-topic", "off", 0, False)]
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_fan_mode_bad_attr(hass, mqtt_mock, caplog):
|
|
|
|
"""Test setting fan mode without required attribute."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") == "low"
|
2019-04-25 08:14:16 +00:00
|
|
|
with pytest.raises(vol.Invalid) as excinfo:
|
|
|
|
await common.async_set_fan_mode(hass, None, ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "string value is None for dictionary value @ data['fan_mode']" in str(
|
|
|
|
excinfo.value
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") == "low"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting of new fan mode in pessimistic mode."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["fan_mode_state_topic"] = "fan-state"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "fan-state", "high")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") == "high"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "fan-state", "bogus mode")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") == "high"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_fan_mode(hass, mqtt_mock):
|
|
|
|
"""Test setting of new fan mode."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") == "low"
|
|
|
|
await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with("fan-mode-topic", "high", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") == "high"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_swing_mode_bad_attr(hass, mqtt_mock, caplog):
|
|
|
|
"""Test setting swing mode without required attribute."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") == "off"
|
2019-04-25 08:14:16 +00:00
|
|
|
with pytest.raises(vol.Invalid) as excinfo:
|
|
|
|
await common.async_set_swing_mode(hass, None, ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "string value is None for dictionary value @ data['swing_mode']" in str(
|
|
|
|
excinfo.value
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") == "off"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_swing_pessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting swing mode in pessimistic mode."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["swing_mode_state_topic"] = "swing-state"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_swing_mode(hass, "on", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "swing-state", "on")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") == "on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "swing-state", "bogus state")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") == "on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_swing(hass, mqtt_mock):
|
|
|
|
"""Test setting of new swing mode."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") == "off"
|
|
|
|
await common.async_set_swing_mode(hass, "on", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with("swing-mode-topic", "on", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") == "on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_target_temperature(hass, mqtt_mock):
|
|
|
|
"""Test setting the target temperature."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 21
|
|
|
|
await common.async_set_hvac_mode(hass, "heat", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "heat"
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with("mode-topic", "heat", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_temperature(hass, temperature=47, entity_id=ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 47
|
2020-10-26 15:46:26 +00:00
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"temperature-topic", "47.0", 0, False
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# also test directly supplying the operation mode to set_temperature
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_temperature(
|
|
|
|
hass, temperature=21, hvac_mode="cool", entity_id=ENTITY_CLIMATE
|
|
|
|
)
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.state == "cool"
|
|
|
|
assert state.attributes.get("temperature") == 21
|
|
|
|
mqtt_mock.async_publish.assert_has_calls(
|
2020-10-26 15:46:26 +00:00
|
|
|
[
|
|
|
|
call("mode-topic", "cool", 0, False),
|
|
|
|
call("temperature-topic", "21.0", 0, False),
|
|
|
|
]
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting the target temperature."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["temperature_state_topic"] = "temperature-state"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") is None
|
|
|
|
await common.async_set_hvac_mode(hass, "heat", ENTITY_CLIMATE)
|
|
|
|
await common.async_set_temperature(hass, temperature=47, entity_id=ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "temperature-state", "1701")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 1701
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "temperature-state", "not a number")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 1701
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_target_temperature_low_high(hass, mqtt_mock):
|
|
|
|
"""Test setting the low/high target temperature."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_temperature(
|
|
|
|
hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("target_temp_low") == 20
|
|
|
|
assert state.attributes.get("target_temp_high") == 23
|
2020-10-26 15:46:26 +00:00
|
|
|
mqtt_mock.async_publish.assert_any_call("temperature-low-topic", "20.0", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("temperature-high-topic", "23.0", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_target_temperature_low_highpessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting the low/high target temperature."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["temperature_low_state_topic"] = "temperature-low-state"
|
|
|
|
config["climate"]["temperature_high_state_topic"] = "temperature-high-state"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("target_temp_low") is None
|
|
|
|
assert state.attributes.get("target_temp_high") is None
|
|
|
|
await common.async_set_temperature(
|
|
|
|
hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("target_temp_low") is None
|
|
|
|
assert state.attributes.get("target_temp_high") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "temperature-low-state", "1701")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("target_temp_low") == 1701
|
|
|
|
assert state.attributes.get("target_temp_high") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "temperature-high-state", "1703")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("target_temp_low") == 1701
|
|
|
|
assert state.attributes.get("target_temp_high") == 1703
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "temperature-low-state", "not a number")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("target_temp_low") == 1701
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "temperature-high-state", "not a number")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("target_temp_high") == 1703
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_receive_mqtt_temperature(hass, mqtt_mock):
|
|
|
|
"""Test getting the current temperature via MQTT."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["current_temperature_topic"] = "current_temperature"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "current_temperature", "47")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("current_temperature") == 47
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2021-11-25 14:53:34 +00:00
|
|
|
async def test_handle_action_received(hass, mqtt_mock):
|
|
|
|
"""Test getting the action received via MQTT."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
|
|
|
config["climate"]["action_topic"] = "action"
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
# Cycle through valid modes and also check for wrong input such as "None" (str(None))
|
|
|
|
async_fire_mqtt_message(hass, "action", "None")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
hvac_action = state.attributes.get(ATTR_HVAC_ACTION)
|
|
|
|
assert hvac_action is None
|
|
|
|
# Redefine actions according to https://developers.home-assistant.io/docs/core/entity/climate/#hvac-action
|
|
|
|
actions = ["off", "heating", "cooling", "drying", "idle", "fan"]
|
|
|
|
assert all(elem in actions for elem in CURRENT_HVAC_ACTIONS)
|
|
|
|
for action in actions:
|
|
|
|
async_fire_mqtt_message(hass, "action", action)
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
hvac_action = state.attributes.get(ATTR_HVAC_ACTION)
|
|
|
|
assert hvac_action == action
|
|
|
|
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
async def test_set_preset_mode_optimistic(hass, mqtt_mock, caplog):
|
|
|
|
"""Test setting of the preset mode."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"preset-mode-topic", "away", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "away"
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "eco", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"preset-mode-topic", "eco", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "eco"
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "none", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"preset-mode-topic", "none", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "comfort", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"preset-mode-topic", "comfort", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "comfort"
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "invalid", ENTITY_CLIMATE)
|
|
|
|
assert "'invalid' is not a valid preset mode" in caplog.text
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_preset_mode_pessimistic(hass, mqtt_mock, caplog):
|
|
|
|
"""Test setting of the preset mode."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
|
|
|
config["climate"]["preset_mode_state_topic"] = "preset-mode-state"
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "preset-mode-state", "away")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "away"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "preset-mode-state", "eco")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "eco"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "preset-mode-state", "none")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "preset-mode-state", "comfort")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "comfort"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "preset-mode-state", "None")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "preset-mode-state", "home")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "home"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "preset-mode-state", "nonsense")
|
|
|
|
assert (
|
|
|
|
"'nonsense' received on topic preset-mode-state. 'nonsense' is not a valid preset mode"
|
|
|
|
in caplog.text
|
|
|
|
)
|
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "home"
|
|
|
|
|
|
|
|
|
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2019-04-19 21:08:54 +00:00
|
|
|
async def test_set_away_mode_pessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting of the away mode."""
|
2022-02-17 12:51:35 +00:00
|
|
|
config = copy.deepcopy(DEFAULT_LEGACY_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["away_mode_state_topic"] = "away-state"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "away-state", "ON")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "away"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "away-state", "OFF")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "away-state", "nonsense")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2019-04-19 21:08:54 +00:00
|
|
|
async def test_set_away_mode(hass, mqtt_mock):
|
|
|
|
"""Test setting of the away mode."""
|
2022-02-17 12:51:35 +00:00
|
|
|
config = copy.deepcopy(DEFAULT_LEGACY_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["payload_on"] = "AN"
|
|
|
|
config["climate"]["payload_off"] = "AUS"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2022-01-11 16:08:26 +00:00
|
|
|
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
Climate 1.0 (#23899)
* Climate 1.0 / part 1/2/3
* fix flake
* Lint
* Update Google Assistant
* ambiclimate to climate 1.0 (#24911)
* Fix Alexa
* Lint
* Migrate zhong_hong
* Migrate tuya
* Migrate honeywell to new climate schema (#24257)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* Fix PRESET can be None
* apply PR#23913 from dev
* remove EU component, etc.
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* apply PR#23913 from dev
* remove EU component, etc.
* ready to test now
* de-linted
* some tweaks
* de-lint
* better handling of edge cases
* delint
* fix set_mode typos
* delint, move debug code
* away preset now working
* code tidy-up
* code tidy-up 2
* code tidy-up 3
* address issues #18932, #15063
* address issues #18932, #15063 - 2/2
* refactor MODE_AUTO to MODE_HEAT_COOL and use F not C
* add low/high to set_temp
* add low/high to set_temp 2
* add low/high to set_temp - delint
* run HA scripts
* port changes from PR #24402
* manual rebase
* manual rebase 2
* delint
* minor change
* remove SUPPORT_HVAC_ACTION
* Migrate radiotherm
* Convert touchline
* Migrate flexit
* Migrate nuheat
* Migrate maxcube
* Fix names maxcube const
* Migrate proliphix
* Migrate heatmiser
* Migrate fritzbox
* Migrate opentherm_gw
* Migrate venstar
* Migrate daikin
* Migrate modbus
* Fix elif
* Migrate Homematic IP Cloud to climate-1.0 (#24913)
* hmip climate fix
* Update hvac_mode and preset_mode
* fix lint
* Fix lint
* Migrate generic_thermostat
* Migrate incomfort to new climate schema (#24915)
* initial commit
* Update climate.py
* Migrate eq3btsmart
* Lint
* cleanup PRESET_MANUAL
* Migrate ecobee
* No conditional features
* KNX: Migrate climate component to new climate platform (#24931)
* Migrate climate component
* Remove unused code
* Corrected line length
* Lint
* Lint
* fix tests
* Fix value
* Migrate geniushub to new climate schema (#24191)
* Update one
* Fix model climate v2
* Cleanup p4
* Add comfort hold mode
* Fix old code
* Update homeassistant/components/climate/__init__.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* Update homeassistant/components/climate/const.py
Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>
* First renaming
* Rename operation to hvac for paulus
* Rename hold mode to preset mode
* Cleanup & update comments
* Remove on/off
* Fix supported feature count
* Update services
* Update demo
* Fix tests & use current_hvac
* Update comment
* Fix tests & add typing
* Add more typing
* Update modes
* Fix tests
* Cleanup low/high with range
* Update homematic part 1
* Finish homematic
* Fix lint
* fix hm mapping
* Support simple devices
* convert lcn
* migrate oem
* Fix xs1
* update hive
* update mil
* Update toon
* migrate deconz
* cleanup
* update tesla
* Fix lint
* Fix vera
* Migrate zwave
* Migrate velbus
* Cleanup humity feature
* Cleanup
* Migrate wink
* migrate dyson
* Fix current hvac
* Renaming
* Fix lint
* Migrate tfiac
* migrate tado
* delinted
* delinted
* use latest client
* clean up mappings
* clean up mappings
* add duration to set_temperature
* add duration to set_temperature
* manual rebase
* tweak
* fix regression
* small fix
* fix rebase mixup
* address comments
* finish refactor
* fix regression
* tweak type hints
* delint
* manual rebase
* WIP: Fixes for honeywell migration to climate-1.0 (#24938)
* add type hints
* code tidy-up
* Fixes for incomfort migration to climate-1.0 (#24936)
* delint type hints
* no async unless await
* revert: no async unless await
* revert: no async unless await 2
* delint
* fix typo
* Fix homekit_controller on climate-1.0 (#24948)
* Fix tests on climate-1.0 branch
* As part of climate-1.0, make state return the heating-cooling.current characteristic
* Fixes from review
* lint
* Fix imports
* Migrate stibel_eltron
* Fix lint
* Migrate coolmaster to climate 1.0 (#24967)
* Migrate coolmaster to climate 1.0
* fix lint errors
* More lint fixes
* Fix demo to work with UI
* Migrate spider
* Demo update
* Updated frontend to 20190705.0
* Fix boost mode (#24980)
* Prepare Netatmo for climate 1.0 (#24973)
* Migration Netatmo
* Address comments
* Update climate.py
* Migrate ephember
* Migrate Sensibo
* Implemented review comments (#24942)
* Migrate ESPHome
* Migrate MQTT
* Migrate Nest
* Migrate melissa
* Initial/partial migration of ST
* Migrate ST
* Remove Away mode (#24995)
* Migrate evohome, cache access tokens (#24491)
* add water_heater, add storage - initial commit
* add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
* Add Broker, Water Heater & Refactor
add missing code
desiderata
* update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
* bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
* support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
* store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
add water_heater, add storage - initial commit
delint
add missing code
desiderata
update honeywell client library & CODEOWNER
add auth_tokens code, refactor & delint
refactor for broker
delint
bugfix - loc_idx may not be 0
more refactor - ensure pure async
more refactoring
appears all r/o attributes are working
tweak precsion, DHW & delint
remove unused code
remove unused code 2
remove unused code, refactor _save_auth_tokens()
support RoundThermostat
bugfix opmode, switch to util.dt, add until=1h
revert breaking change
store at_expires as naive UTC
remove debug code
delint
tidy up exception handling
delint
* update CODEOWNERS
* fix regression
* fix requirements
* migrate to climate-1.0
* tweaking
* de-lint
* TCS working? & delint
* tweaking
* TCS code finalised
* remove available() logic
* refactor _switchpoints()
* tidy up switchpoint code
* tweak
* teaking device_state_attributes
* some refactoring
* move PRESET_CUSTOM back to evohome
* move CONF_ACCESS_TOKEN_EXPIRES CONF_REFRESH_TOKEN back to evohome
* refactor SP code and dt conversion
* delinted
* delinted
* remove water_heater
* fix regression
* Migrate homekit
* Cleanup away mode
* Fix tests
* add helpers
* fix tests melissa
* Fix nehueat
* fix zwave
* add more tests
* fix deconz
* Fix climate test emulate_hue
* fix tests
* fix dyson tests
* fix demo with new layout
* fix honeywell
* Switch homekit_controller to use HVAC_MODE_HEAT_COOL instead of HVAC_MODE_AUTO (#25009)
* Lint
* PyLint
* Pylint
* fix fritzbox tests
* Fix google
* Fix all tests
* Fix lint
* Fix auto for homekit like controler
* Fix lint
* fix lint
2019-07-08 12:00:24 +00:00
|
|
|
await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE)
|
2022-01-11 16:08:26 +00:00
|
|
|
assert mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "AN", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "off", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "away"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-21 18:00:42 +00:00
|
|
|
await common.async_set_preset_mode(hass, PRESET_NONE, ENTITY_CLIMATE)
|
2022-01-11 16:08:26 +00:00
|
|
|
assert mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "AUS", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "off", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-11-26 04:53:37 +00:00
|
|
|
await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "away", ENTITY_CLIMATE)
|
2022-01-11 16:08:26 +00:00
|
|
|
assert mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "AN", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "off", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2019-11-26 04:53:37 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "away"
|
|
|
|
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2019-04-19 21:08:54 +00:00
|
|
|
async def test_set_hold_pessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting the hold mode in pessimistic mode."""
|
2022-02-17 12:51:35 +00:00
|
|
|
config = copy.deepcopy(DEFAULT_LEGACY_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["hold_state_topic"] = "hold-state"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("hold_mode") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_preset_mode(hass, "hold", ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("hold_mode") is None
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "hold-state", "on")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "hold-state", "off")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2019-04-19 21:08:54 +00:00
|
|
|
async def test_set_hold(hass, mqtt_mock):
|
|
|
|
"""Test setting the hold mode."""
|
2022-02-17 12:51:35 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_LEGACY_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE)
|
2022-01-11 16:08:26 +00:00
|
|
|
mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "hold-on", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "hold-on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-11-26 04:53:37 +00:00
|
|
|
await common.async_set_preset_mode(hass, PRESET_ECO, ENTITY_CLIMATE)
|
2022-01-11 16:08:26 +00:00
|
|
|
mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "eco", 0, False)
|
2019-11-26 04:53:37 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_ECO
|
|
|
|
|
2019-07-21 18:00:42 +00:00
|
|
|
await common.async_set_preset_mode(hass, PRESET_NONE, ENTITY_CLIMATE)
|
2022-01-11 16:08:26 +00:00
|
|
|
mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "off", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2022-01-11 16:08:26 +00:00
|
|
|
async def test_set_preset_away(hass, mqtt_mock):
|
|
|
|
"""Test setting the hold mode and away mode."""
|
2022-02-17 12:51:35 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_LEGACY_CONFIG)
|
2022-01-11 16:08:26 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_NONE
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "hold-on", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "hold-on"
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, PRESET_AWAY, ENTITY_CLIMATE)
|
|
|
|
assert mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "ON", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "off", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_AWAY
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "hold-on-again", ENTITY_CLIMATE)
|
|
|
|
assert mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "hold-on-again", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "hold-on-again"
|
|
|
|
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2022-01-11 16:08:26 +00:00
|
|
|
async def test_set_preset_away_pessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting the hold mode and away mode in pessimistic mode."""
|
2022-02-17 12:51:35 +00:00
|
|
|
config = copy.deepcopy(DEFAULT_LEGACY_CONFIG)
|
2022-01-11 16:08:26 +00:00
|
|
|
config["climate"]["hold_state_topic"] = "hold-state"
|
|
|
|
config["climate"]["away_mode_state_topic"] = "away-state"
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_NONE
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "hold-on", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_NONE
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "hold-state", "hold-on")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "hold-on"
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, PRESET_AWAY, ENTITY_CLIMATE)
|
|
|
|
assert mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "ON", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "off", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "hold-on"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "away-state", "ON")
|
|
|
|
async_fire_mqtt_message(hass, "hold-state", "off")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_AWAY
|
|
|
|
|
|
|
|
await common.async_set_preset_mode(hass, "hold-on-again", ENTITY_CLIMATE)
|
|
|
|
assert mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "hold-on-again", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_AWAY
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "hold-state", "hold-on-again")
|
|
|
|
async_fire_mqtt_message(hass, "away-state", "OFF")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "hold-on-again"
|
|
|
|
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2020-04-03 16:05:58 +00:00
|
|
|
async def test_set_preset_mode_twice(hass, mqtt_mock):
|
|
|
|
"""Test setting of the same mode twice only publishes once."""
|
2022-02-17 12:51:35 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_LEGACY_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-04-03 16:05:58 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2020-04-03 16:05:58 +00:00
|
|
|
await common.async_set_preset_mode(hass, "hold-on", ENTITY_CLIMATE)
|
2022-01-11 16:08:26 +00:00
|
|
|
mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "hold-on", 0, False)
|
2020-04-03 16:05:58 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "hold-on"
|
|
|
|
|
|
|
|
|
2019-04-19 21:08:54 +00:00
|
|
|
async def test_set_aux_pessimistic(hass, mqtt_mock):
|
|
|
|
"""Test setting of the aux heating in pessimistic mode."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["aux_state_topic"] = "aux-state"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "off"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
await common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "off"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "aux-state", "ON")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "aux-state", "OFF")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "off"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "aux-state", "nonsense")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "off"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_set_aux(hass, mqtt_mock):
|
|
|
|
"""Test setting of the aux heating."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "off"
|
2019-04-25 08:14:16 +00:00
|
|
|
await common.async_set_aux_heat(hass, True, ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
mqtt_mock.async_publish.assert_called_once_with("aux-topic", "ON", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
await common.async_set_aux_heat(hass, False, ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
mqtt_mock.async_publish.assert_called_once_with("aux-topic", "OFF", 0, False)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "off"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2020-06-07 07:21:16 +00:00
|
|
|
async def test_availability_when_connection_lost(hass, mqtt_mock):
|
|
|
|
"""Test availability after MQTT disconnection."""
|
|
|
|
await help_test_availability_when_connection_lost(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-03-17 07:09:19 +00:00
|
|
|
async def test_availability_without_topic(hass, mqtt_mock):
|
|
|
|
"""Test availability without defined availability topic."""
|
|
|
|
await help_test_availability_without_topic(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2020-03-17 07:09:19 +00:00
|
|
|
async def test_default_availability_payload(hass, mqtt_mock):
|
|
|
|
"""Test availability by default payload with defined topic."""
|
|
|
|
await help_test_default_availability_payload(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2020-03-17 07:09:19 +00:00
|
|
|
async def test_custom_availability_payload(hass, mqtt_mock):
|
|
|
|
"""Test availability by custom payload with defined topic."""
|
|
|
|
await help_test_custom_availability_payload(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
2021-01-26 15:12:33 +00:00
|
|
|
async def test_get_target_temperature_low_high_with_templates(hass, mqtt_mock, caplog):
|
|
|
|
"""Test getting temperature high/low with templates."""
|
2019-11-06 12:50:54 +00:00
|
|
|
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)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-11-06 12:50:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2021-01-26 15:12:33 +00:00
|
|
|
async def test_get_with_templates(hass, mqtt_mock, caplog):
|
|
|
|
"""Test getting various attributes with templates."""
|
2019-04-19 21:08:54 +00:00
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
|
|
|
# By default, just unquote the JSON-strings
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["value_template"] = "{{ value_json }}"
|
|
|
|
config["climate"]["action_template"] = "{{ value_json }}"
|
2019-04-19 21:08:54 +00:00
|
|
|
# Rendering to a bool for aux heat
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["aux_state_template"] = "{{ value == 'switchmeon' }}"
|
2022-02-17 12:51:35 +00:00
|
|
|
# Rendering preset_mode
|
|
|
|
config["climate"]["preset_mode_value_template"] = "{{ value_json.attribute }}"
|
2019-07-31 19:25:30 +00:00
|
|
|
|
|
|
|
config["climate"]["action_topic"] = "action"
|
|
|
|
config["climate"]["mode_state_topic"] = "mode-state"
|
|
|
|
config["climate"]["fan_mode_state_topic"] = "fan-state"
|
|
|
|
config["climate"]["swing_mode_state_topic"] = "swing-state"
|
|
|
|
config["climate"]["temperature_state_topic"] = "temperature-state"
|
|
|
|
config["climate"]["aux_state_topic"] = "aux-state"
|
|
|
|
config["climate"]["current_temperature_topic"] = "current-temperature"
|
2022-02-17 12:51:35 +00:00
|
|
|
config["climate"]["preset_mode_state_topic"] = "current-preset-mode"
|
2019-04-19 21:08:54 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# Operation Mode
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "mode-state", '"cool"')
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.state == "cool"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# Fan Mode
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") is None
|
|
|
|
async_fire_mqtt_message(hass, "fan-state", '"high"')
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("fan_mode") == "high"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# Swing Mode
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") is None
|
|
|
|
async_fire_mqtt_message(hass, "swing-state", '"on"')
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("swing_mode") == "on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# Temperature - with valid value
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") is None
|
|
|
|
async_fire_mqtt_message(hass, "temperature-state", '"1031"')
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 1031
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# Temperature - with invalid value
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "temperature-state", '"-INVALID-"')
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
# make sure, the invalid value gets logged...
|
|
|
|
assert "Could not parse temperature from -INVALID-" in caplog.text
|
|
|
|
# ... but the actual value stays unchanged.
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 1031
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# Preset Mode
|
2020-11-16 19:10:55 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
2022-02-17 12:51:35 +00:00
|
|
|
async_fire_mqtt_message(hass, "current-preset-mode", '{"attribute": "eco"}')
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2022-02-17 12:51:35 +00:00
|
|
|
assert state.attributes.get("preset_mode") == "eco"
|
|
|
|
# Test with an empty json
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(
|
2022-02-17 12:51:35 +00:00
|
|
|
hass, "current-preset-mode", '{"other_attribute": "some_value"}'
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2022-02-17 12:51:35 +00:00
|
|
|
assert "Ignoring empty preset_mode from 'current-preset-mode'"
|
|
|
|
assert state.attributes.get("preset_mode") == "eco"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# Aux mode
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "off"
|
|
|
|
async_fire_mqtt_message(hass, "aux-state", "switchmeon")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "on"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# anything other than 'switchmeon' should turn Aux mode off
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "aux-state", "somerandomstring")
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("aux_heat") == "off"
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
# Current temperature
|
2019-07-31 19:25:30 +00:00
|
|
|
async_fire_mqtt_message(hass, "current-temperature", '"74656"')
|
2019-04-19 21:08:54 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("current_temperature") == 74656
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2019-07-18 17:17:26 +00:00
|
|
|
# Action
|
2021-11-25 14:53:34 +00:00
|
|
|
async_fire_mqtt_message(hass, "action", '"cooling"')
|
2019-07-18 17:17:26 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2021-11-25 14:53:34 +00:00
|
|
|
assert state.attributes.get("hvac_action") == "cooling"
|
2019-07-18 17:17:26 +00:00
|
|
|
|
2022-01-27 07:41:27 +00:00
|
|
|
# Test ignoring null values
|
|
|
|
async_fire_mqtt_message(hass, "action", "null")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("hvac_action") == "cooling"
|
|
|
|
assert (
|
|
|
|
"Invalid ['off', 'heating', 'cooling', 'drying', 'idle', 'fan'] action: None, ignoring"
|
|
|
|
in caplog.text
|
|
|
|
)
|
|
|
|
|
2019-04-19 21:08:54 +00:00
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
|
|
|
async def test_get_with_hold_and_away_mode_and_templates(hass, mqtt_mock, caplog):
|
|
|
|
"""Test getting various for hold and away mode attributes with templates."""
|
|
|
|
config = copy.deepcopy(DEFAULT_LEGACY_CONFIG)
|
|
|
|
config["climate"]["mode_state_topic"] = "mode-state"
|
|
|
|
# By default, just unquote the JSON-strings
|
|
|
|
config["climate"]["value_template"] = "{{ value_json }}"
|
|
|
|
# Something more complicated for hold mode
|
|
|
|
config["climate"]["hold_state_template"] = "{{ value_json.attribute }}"
|
|
|
|
config["climate"]["away_mode_state_topic"] = "away-state"
|
|
|
|
config["climate"]["hold_state_topic"] = "hold-state"
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
# Operation Mode
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
async_fire_mqtt_message(hass, "mode-state", '"cool"')
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.state == "cool"
|
|
|
|
|
|
|
|
# Away Mode
|
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
|
|
|
async_fire_mqtt_message(hass, "away-state", '"ON"')
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "away"
|
|
|
|
|
|
|
|
# Away Mode with JSON values
|
|
|
|
async_fire_mqtt_message(hass, "away-state", "false")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "none"
|
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "away-state", "true")
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "away"
|
|
|
|
|
|
|
|
# Hold Mode
|
|
|
|
async_fire_mqtt_message(
|
|
|
|
hass,
|
|
|
|
"hold-state",
|
|
|
|
"""
|
|
|
|
{ "attribute": "somemode" }
|
|
|
|
""",
|
|
|
|
)
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == "somemode"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_and_templates(hass, mqtt_mock, caplog):
|
2021-01-26 15:12:33 +00:00
|
|
|
"""Test setting various attributes with templates."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
|
|
|
# Create simple templates
|
|
|
|
config["climate"]["fan_mode_command_template"] = "fan_mode: {{ value }}"
|
2022-02-17 12:51:35 +00:00
|
|
|
config["climate"]["preset_mode_command_template"] = "preset_mode: {{ value }}"
|
2021-01-26 15:12:33 +00:00
|
|
|
config["climate"]["mode_command_template"] = "mode: {{ value }}"
|
|
|
|
config["climate"]["swing_mode_command_template"] = "swing_mode: {{ value }}"
|
|
|
|
config["climate"]["temperature_command_template"] = "temp: {{ value }}"
|
|
|
|
config["climate"]["temperature_high_command_template"] = "temp_hi: {{ value }}"
|
|
|
|
config["climate"]["temperature_low_command_template"] = "temp_lo: {{ value }}"
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
# Fan Mode
|
|
|
|
await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"fan-mode-topic", "fan_mode: high", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("fan_mode") == "high"
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# Preset Mode
|
2021-01-26 15:12:33 +00:00
|
|
|
await common.async_set_preset_mode(hass, PRESET_ECO, ENTITY_CLIMATE)
|
2022-02-17 12:51:35 +00:00
|
|
|
mqtt_mock.async_publish.call_count == 1
|
|
|
|
mqtt_mock.async_publish.assert_any_call(
|
|
|
|
"preset-mode-topic", "preset_mode: eco", 0, False
|
|
|
|
)
|
2021-01-26 15:12:33 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_ECO
|
|
|
|
|
|
|
|
# Mode
|
|
|
|
await common.async_set_hvac_mode(hass, "cool", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"mode-topic", "mode: cool", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.state == "cool"
|
|
|
|
|
|
|
|
# Swing Mode
|
|
|
|
await common.async_set_swing_mode(hass, "on", ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"swing-mode-topic", "swing_mode: on", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("swing_mode") == "on"
|
|
|
|
|
|
|
|
# Temperature
|
|
|
|
await common.async_set_temperature(hass, temperature=47, entity_id=ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.assert_called_once_with(
|
|
|
|
"temperature-topic", "temp: 47.0", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("temperature") == 47
|
|
|
|
|
|
|
|
# Temperature Low/High
|
|
|
|
await common.async_set_temperature(
|
|
|
|
hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.assert_any_call(
|
|
|
|
"temperature-low-topic", "temp_lo: 20.0", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.assert_any_call(
|
|
|
|
"temperature-high-topic", "temp_hi: 23.0", 0, False
|
|
|
|
)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("target_temp_low") == 20
|
|
|
|
assert state.attributes.get("target_temp_high") == 23
|
|
|
|
|
|
|
|
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
|
|
|
async def test_set_with_away_and_hold_modes_and_templates(hass, mqtt_mock, caplog):
|
|
|
|
"""Test setting various attributes on hold and away mode with templates."""
|
|
|
|
config = copy.deepcopy(DEFAULT_LEGACY_CONFIG)
|
|
|
|
# Create simple templates
|
|
|
|
config["climate"]["hold_command_template"] = "hold: {{ value }}"
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
# Hold Mode
|
|
|
|
await common.async_set_preset_mode(hass, PRESET_ECO, ENTITY_CLIMATE)
|
|
|
|
mqtt_mock.async_publish.call_count == 2
|
|
|
|
mqtt_mock.async_publish.assert_any_call("away-mode-topic", "OFF", 0, False)
|
|
|
|
mqtt_mock.async_publish.assert_any_call("hold-topic", "hold: eco", 0, False)
|
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("preset_mode") == PRESET_ECO
|
|
|
|
|
|
|
|
|
2019-04-19 21:08:54 +00:00
|
|
|
async def test_min_temp_custom(hass, mqtt_mock):
|
|
|
|
"""Test a custom min temp."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["min_temp"] = 26
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
min_temp = state.attributes.get("min_temp")
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
assert isinstance(min_temp, float)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("min_temp") == 26
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_max_temp_custom(hass, mqtt_mock):
|
|
|
|
"""Test a custom max temp."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["max_temp"] = 60
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
max_temp = state.attributes.get("max_temp")
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
assert isinstance(max_temp, float)
|
2019-04-22 12:48:50 +00:00
|
|
|
assert max_temp == 60
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_temp_step_custom(hass, mqtt_mock):
|
|
|
|
"""Test a custom temp step."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["temp_step"] = 0.01
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
temp_step = state.attributes.get("target_temp_step")
|
2019-04-19 21:08:54 +00:00
|
|
|
|
|
|
|
assert isinstance(temp_step, float)
|
2019-04-22 12:48:50 +00:00
|
|
|
assert temp_step == 0.01
|
2018-10-08 18:24:25 +00:00
|
|
|
|
2018-09-25 15:15:39 +00:00
|
|
|
|
2020-04-15 18:11:04 +00:00
|
|
|
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)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-04-15 18:11:04 +00:00
|
|
|
|
|
|
|
async_fire_mqtt_message(hass, "current_temperature", "77")
|
|
|
|
|
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
|
|
|
assert state.attributes.get("current_temperature") == 25
|
|
|
|
|
|
|
|
|
2019-01-21 00:42:35 +00:00
|
|
|
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
|
|
|
"""Test the setting of attribute via MQTT with JSON payload."""
|
2020-03-09 16:40:00 +00:00
|
|
|
await help_test_setting_attribute_via_mqtt_json_message(
|
2020-03-17 07:09:19 +00:00
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-06-29 09:13:58 +00:00
|
|
|
async def test_setting_blocked_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
|
|
|
"""Test the setting of attribute via MQTT with JSON payload."""
|
|
|
|
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG, MQTT_CLIMATE_ATTRIBUTES_BLOCKED
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-03-17 07:09:19 +00:00
|
|
|
async def test_setting_attribute_with_template(hass, mqtt_mock):
|
|
|
|
"""Test the setting of attribute via MQTT with JSON payload."""
|
|
|
|
await help_test_setting_attribute_with_template(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-01-21 00:42:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
|
|
|
"""Test attributes get extracted from a JSON result."""
|
2020-03-09 16:40:00 +00:00
|
|
|
await help_test_update_with_json_attrs_not_dict(
|
2020-03-17 07:09:19 +00:00
|
|
|
hass, mqtt_mock, caplog, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-01-21 00:42:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog):
|
|
|
|
"""Test attributes get extracted from a JSON result."""
|
2020-03-09 16:40:00 +00:00
|
|
|
await help_test_update_with_json_attrs_bad_JSON(
|
2020-03-17 07:09:19 +00:00
|
|
|
hass, mqtt_mock, caplog, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-01-21 00:42:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
|
|
|
"""Test update of discovered MQTTAttributes."""
|
2020-03-09 16:40:00 +00:00
|
|
|
await help_test_discovery_update_attr(
|
2020-03-17 07:09:19 +00:00
|
|
|
hass, mqtt_mock, caplog, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
2020-03-09 16:40:00 +00:00
|
|
|
)
|
2019-01-21 00:42:35 +00:00
|
|
|
|
|
|
|
|
2020-06-22 21:59:50 +00:00
|
|
|
async def test_unique_id(hass, mqtt_mock):
|
2018-12-15 16:28:08 +00:00
|
|
|
"""Test unique id option only creates one climate per unique_id."""
|
2020-03-09 16:40:00 +00:00
|
|
|
config = {
|
|
|
|
CLIMATE_DOMAIN: [
|
|
|
|
{
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "Test 1",
|
|
|
|
"power_state_topic": "test-topic",
|
|
|
|
"power_command_topic": "test_topic",
|
|
|
|
"unique_id": "TOTALLY_UNIQUE",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "Test 2",
|
|
|
|
"power_state_topic": "test-topic",
|
|
|
|
"power_command_topic": "test_topic",
|
|
|
|
"unique_id": "TOTALLY_UNIQUE",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
2020-06-22 21:59:50 +00:00
|
|
|
await help_test_unique_id(hass, mqtt_mock, CLIMATE_DOMAIN, config)
|
2018-12-15 16:28:08 +00:00
|
|
|
|
|
|
|
|
2022-01-03 15:08:07 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"topic,value,attribute,attribute_value",
|
|
|
|
[
|
|
|
|
("action_topic", "heating", ATTR_HVAC_ACTION, "heating"),
|
|
|
|
("action_topic", "cooling", ATTR_HVAC_ACTION, "cooling"),
|
|
|
|
("aux_state_topic", "ON", ATTR_AUX_HEAT, "on"),
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2022-01-03 15:08:07 +00:00
|
|
|
("away_mode_state_topic", "ON", ATTR_PRESET_MODE, "away"),
|
|
|
|
("current_temperature_topic", "22.1", ATTR_CURRENT_TEMPERATURE, 22.1),
|
|
|
|
("fan_mode_state_topic", "low", ATTR_FAN_MODE, "low"),
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
2022-01-03 15:08:07 +00:00
|
|
|
("hold_state_topic", "mode1", ATTR_PRESET_MODE, "mode1"),
|
|
|
|
("mode_state_topic", "cool", None, None),
|
|
|
|
("mode_state_topic", "fan_only", None, None),
|
|
|
|
("swing_mode_state_topic", "on", ATTR_SWING_MODE, "on"),
|
|
|
|
("temperature_low_state_topic", "19.1", ATTR_TARGET_TEMP_LOW, 19.1),
|
|
|
|
("temperature_high_state_topic", "22.9", ATTR_TARGET_TEMP_HIGH, 22.9),
|
|
|
|
("temperature_state_topic", "19.9", ATTR_TEMPERATURE, 19.9),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
async def test_encoding_subscribable_topics(
|
|
|
|
hass, mqtt_mock, caplog, topic, value, attribute, attribute_value
|
|
|
|
):
|
|
|
|
"""Test handling of incoming encoded payload."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG[CLIMATE_DOMAIN])
|
2022-02-17 12:51:35 +00:00
|
|
|
# AWAY and HOLD mode topics and templates are deprecated, support will be removed with release 2022.9
|
|
|
|
if topic in ["hold_state_topic", "away_mode_state_topic"]:
|
|
|
|
config["hold_modes"] = ["mode1", "mode2"]
|
|
|
|
del config["preset_modes"]
|
|
|
|
del config["preset_mode_command_topic"]
|
2022-01-03 15:08:07 +00:00
|
|
|
await help_test_encoding_subscribable_topics(
|
|
|
|
hass,
|
|
|
|
mqtt_mock,
|
|
|
|
caplog,
|
|
|
|
CLIMATE_DOMAIN,
|
|
|
|
config,
|
|
|
|
topic,
|
|
|
|
value,
|
|
|
|
attribute,
|
|
|
|
attribute_value,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-25 15:15:39 +00:00
|
|
|
async def test_discovery_removal_climate(hass, mqtt_mock, caplog):
|
|
|
|
"""Test removal of discovered climate."""
|
2020-03-11 16:34:19 +00:00
|
|
|
data = json.dumps(DEFAULT_CONFIG[CLIMATE_DOMAIN])
|
2020-03-09 16:40:00 +00:00
|
|
|
await help_test_discovery_removal(hass, mqtt_mock, caplog, CLIMATE_DOMAIN, data)
|
2018-11-24 09:40:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_discovery_update_climate(hass, mqtt_mock, caplog):
|
2019-01-08 15:53:02 +00:00
|
|
|
"""Test update of discovered climate."""
|
2021-10-25 11:47:06 +00:00
|
|
|
config1 = {"name": "Beer"}
|
|
|
|
config2 = {"name": "Milk"}
|
2020-03-09 16:40:00 +00:00
|
|
|
await help_test_discovery_update(
|
2021-10-25 11:47:06 +00:00
|
|
|
hass, mqtt_mock, caplog, CLIMATE_DOMAIN, config1, config2
|
2020-03-09 16:40:00 +00:00
|
|
|
)
|
2018-12-15 16:28:08 +00:00
|
|
|
|
|
|
|
|
2020-08-06 08:43:47 +00:00
|
|
|
async def test_discovery_update_unchanged_climate(hass, mqtt_mock, caplog):
|
|
|
|
"""Test update of discovered climate."""
|
|
|
|
data1 = '{ "name": "Beer" }'
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.mqtt.climate.MqttClimate.discovery_update"
|
|
|
|
) as discovery_update:
|
|
|
|
await help_test_discovery_update_unchanged(
|
|
|
|
hass, mqtt_mock, caplog, CLIMATE_DOMAIN, data1, discovery_update
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-05-06 21:14:57 +00:00
|
|
|
@pytest.mark.no_fail_on_log_exception
|
2019-01-08 15:53:02 +00:00
|
|
|
async def test_discovery_broken(hass, mqtt_mock, caplog):
|
|
|
|
"""Test handling of bad discovery message."""
|
2020-08-06 08:43:47 +00:00
|
|
|
data1 = '{ "name": "Beer", "power_command_topic": "test_topic#" }'
|
|
|
|
data2 = '{ "name": "Milk", "power_command_topic": "test_topic" }'
|
2020-03-09 16:40:00 +00:00
|
|
|
await help_test_discovery_broken(
|
|
|
|
hass, mqtt_mock, caplog, CLIMATE_DOMAIN, data1, data2
|
|
|
|
)
|
2019-01-08 15:53:02 +00:00
|
|
|
|
|
|
|
|
2020-03-17 07:09:19 +00:00
|
|
|
async def test_entity_device_info_with_connection(hass, mqtt_mock):
|
|
|
|
"""Test MQTT climate device registry integration."""
|
|
|
|
await help_test_entity_device_info_with_connection(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-12-15 16:28:08 +00:00
|
|
|
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
|
|
|
|
"""Test MQTT climate device registry integration."""
|
2020-03-09 16:40:00 +00:00
|
|
|
await help_test_entity_device_info_with_identifier(
|
2020-03-17 07:09:19 +00:00
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
2020-03-09 16:40:00 +00:00
|
|
|
)
|
2018-12-19 13:31:42 +00:00
|
|
|
|
|
|
|
|
2019-01-01 10:12:40 +00:00
|
|
|
async def test_entity_device_info_update(hass, mqtt_mock):
|
|
|
|
"""Test device registry update."""
|
2020-03-11 16:34:19 +00:00
|
|
|
await help_test_entity_device_info_update(
|
2020-03-17 07:09:19 +00:00
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
2020-03-11 16:34:19 +00:00
|
|
|
)
|
2019-01-01 10:12:40 +00:00
|
|
|
|
|
|
|
|
2020-03-12 01:00:47 +00:00
|
|
|
async def test_entity_device_info_remove(hass, mqtt_mock):
|
|
|
|
"""Test device registry remove."""
|
2020-03-17 07:09:19 +00:00
|
|
|
await help_test_entity_device_info_remove(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
|
|
|
)
|
2020-03-12 01:00:47 +00:00
|
|
|
|
|
|
|
|
2020-03-30 21:26:59 +00:00
|
|
|
async def test_entity_id_update_subscriptions(hass, mqtt_mock):
|
2018-12-19 13:31:42 +00:00
|
|
|
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
2020-03-09 16:40:00 +00:00
|
|
|
config = {
|
2020-03-17 07:09:19 +00:00
|
|
|
CLIMATE_DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
|
|
|
"mode_state_topic": "test-topic",
|
|
|
|
"availability_topic": "avty-topic",
|
|
|
|
}
|
2020-03-09 16:40:00 +00:00
|
|
|
}
|
2020-03-30 21:26:59 +00:00
|
|
|
await help_test_entity_id_update_subscriptions(
|
2020-03-17 07:09:19 +00:00
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, config, ["test-topic", "avty-topic"]
|
|
|
|
)
|
2019-07-18 22:21:50 +00:00
|
|
|
|
|
|
|
|
2020-03-30 21:26:59 +00:00
|
|
|
async def test_entity_id_update_discovery_update(hass, mqtt_mock):
|
|
|
|
"""Test MQTT discovery update when entity_id is updated."""
|
|
|
|
await help_test_entity_id_update_discovery_update(
|
|
|
|
hass, mqtt_mock, CLIMATE_DOMAIN, DEFAULT_CONFIG
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-04-01 18:48:32 +00:00
|
|
|
async def test_entity_debug_info_message(hass, mqtt_mock):
|
|
|
|
"""Test MQTT debug info."""
|
|
|
|
config = {
|
|
|
|
CLIMATE_DOMAIN: {
|
|
|
|
"platform": "mqtt",
|
|
|
|
"name": "test",
|
2022-02-04 16:35:32 +00:00
|
|
|
"mode_command_topic": "command-topic",
|
2020-04-01 18:48:32 +00:00
|
|
|
"mode_state_topic": "test-topic",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await help_test_entity_debug_info_message(
|
2022-02-04 16:35:32 +00:00
|
|
|
hass,
|
|
|
|
mqtt_mock,
|
|
|
|
CLIMATE_DOMAIN,
|
|
|
|
config,
|
|
|
|
climate.SERVICE_TURN_ON,
|
|
|
|
command_topic="command-topic",
|
|
|
|
command_payload="heat",
|
|
|
|
state_topic="test-topic",
|
2020-04-01 18:48:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-07-18 22:21:50 +00:00
|
|
|
async def test_precision_default(hass, mqtt_mock):
|
|
|
|
"""Test that setting precision to tenths works as intended."""
|
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-18 22:21:50 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_temperature(
|
|
|
|
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
|
|
|
|
)
|
2019-07-18 22:21:50 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 23.7
|
2019-07-18 22:21:50 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
|
|
|
|
|
|
|
async def test_precision_halves(hass, mqtt_mock):
|
|
|
|
"""Test that setting precision to halves works as intended."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["precision"] = 0.5
|
2019-07-18 22:21:50 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-18 22:21:50 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_temperature(
|
|
|
|
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
|
|
|
|
)
|
2019-07-18 22:21:50 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 23.5
|
2019-07-18 22:21:50 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
|
|
|
|
|
|
|
|
|
|
|
async def test_precision_whole(hass, mqtt_mock):
|
|
|
|
"""Test that setting precision to whole works as intended."""
|
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["climate"]["precision"] = 1.0
|
2019-07-18 22:21:50 +00:00
|
|
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-18 22:21:50 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await common.async_set_temperature(
|
|
|
|
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
|
|
|
|
)
|
2019-07-18 22:21:50 +00:00
|
|
|
state = hass.states.get(ENTITY_CLIMATE)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get("temperature") == 24.0
|
2019-07-18 22:21:50 +00:00
|
|
|
mqtt_mock.async_publish.reset_mock()
|
2022-01-03 08:03:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"service,topic,parameters,payload,template",
|
|
|
|
[
|
|
|
|
(
|
|
|
|
climate.SERVICE_TURN_ON,
|
|
|
|
"power_command_topic",
|
|
|
|
None,
|
|
|
|
"ON",
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_HVAC_MODE,
|
|
|
|
"mode_command_topic",
|
|
|
|
{"hvac_mode": "cool"},
|
|
|
|
"cool",
|
|
|
|
"mode_command_template",
|
|
|
|
),
|
2022-02-17 12:51:35 +00:00
|
|
|
(
|
|
|
|
climate.SERVICE_SET_PRESET_MODE,
|
|
|
|
"preset_mode_command_topic",
|
|
|
|
{"preset_mode": "sleep"},
|
|
|
|
"sleep",
|
|
|
|
"preset_mode_command_template",
|
|
|
|
),
|
2022-01-03 08:03:47 +00:00
|
|
|
(
|
|
|
|
climate.SERVICE_SET_PRESET_MODE,
|
|
|
|
"away_mode_command_topic",
|
|
|
|
{"preset_mode": "away"},
|
|
|
|
"ON",
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_PRESET_MODE,
|
|
|
|
"hold_command_topic",
|
|
|
|
{"preset_mode": "eco"},
|
|
|
|
"eco",
|
|
|
|
"hold_command_template",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_PRESET_MODE,
|
|
|
|
"hold_command_topic",
|
2022-02-17 12:51:35 +00:00
|
|
|
{"preset_mode": "comfort"},
|
|
|
|
"comfort",
|
2022-01-03 08:03:47 +00:00
|
|
|
"hold_command_template",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_FAN_MODE,
|
|
|
|
"fan_mode_command_topic",
|
|
|
|
{"fan_mode": "medium"},
|
|
|
|
"medium",
|
|
|
|
"fan_mode_command_template",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_SWING_MODE,
|
|
|
|
"swing_mode_command_topic",
|
|
|
|
{"swing_mode": "on"},
|
|
|
|
"on",
|
|
|
|
"swing_mode_command_template",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_AUX_HEAT,
|
|
|
|
"aux_command_topic",
|
|
|
|
{"aux_heat": "on"},
|
|
|
|
"ON",
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_TEMPERATURE,
|
|
|
|
"temperature_command_topic",
|
|
|
|
{"temperature": "20.1"},
|
|
|
|
20.1,
|
|
|
|
"temperature_command_template",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_TEMPERATURE,
|
|
|
|
"temperature_low_command_topic",
|
|
|
|
{
|
|
|
|
"temperature": "20.1",
|
|
|
|
"target_temp_low": "15.1",
|
|
|
|
"target_temp_high": "29.8",
|
|
|
|
},
|
|
|
|
15.1,
|
|
|
|
"temperature_low_command_template",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
climate.SERVICE_SET_TEMPERATURE,
|
|
|
|
"temperature_high_command_topic",
|
|
|
|
{
|
|
|
|
"temperature": "20.1",
|
|
|
|
"target_temp_low": "15.1",
|
|
|
|
"target_temp_high": "29.8",
|
|
|
|
},
|
|
|
|
29.8,
|
|
|
|
"temperature_high_command_template",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
async def test_publishing_with_custom_encoding(
|
|
|
|
hass,
|
|
|
|
mqtt_mock,
|
|
|
|
caplog,
|
|
|
|
service,
|
|
|
|
topic,
|
|
|
|
parameters,
|
|
|
|
payload,
|
|
|
|
template,
|
|
|
|
):
|
|
|
|
"""Test publishing MQTT payload with different encoding."""
|
|
|
|
domain = climate.DOMAIN
|
2022-02-17 12:51:35 +00:00
|
|
|
config = copy.deepcopy(DEFAULT_CONFIG[domain])
|
|
|
|
if topic != "preset_mode_command_topic":
|
|
|
|
del config["preset_mode_command_topic"]
|
|
|
|
del config["preset_modes"]
|
2022-01-03 08:03:47 +00:00
|
|
|
|
|
|
|
await help_test_publishing_with_custom_encoding(
|
|
|
|
hass,
|
|
|
|
mqtt_mock,
|
|
|
|
caplog,
|
|
|
|
domain,
|
|
|
|
config,
|
|
|
|
service,
|
|
|
|
topic,
|
|
|
|
parameters,
|
|
|
|
payload,
|
|
|
|
template,
|
|
|
|
)
|
2022-01-03 14:14:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_reloadable(hass, mqtt_mock, caplog, tmp_path):
|
|
|
|
"""Test reloading the MQTT platform."""
|
|
|
|
domain = CLIMATE_DOMAIN
|
|
|
|
config = DEFAULT_CONFIG[domain]
|
|
|
|
await help_test_reloadable(hass, mqtt_mock, caplog, tmp_path, domain, config)
|
2022-02-10 20:09:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
|
|
|
|
"""Test reloading the MQTT platform with late entry setup."""
|
|
|
|
domain = CLIMATE_DOMAIN
|
|
|
|
config = DEFAULT_CONFIG[domain]
|
|
|
|
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
|