Remove service helper (2) (#16863)

* alarm_control_panel

* automation

* camera

* climate

* counter

* fan

* Add legacy notes

* Fix tests
This commit is contained in:
cdce8p authored and Paulus Schoutsen committed 2018-09-26 09:49:55 +02:00
1 parent c899875abb
commit fa98a27df7
33 files changed
+766 -666

No files matched your search

+115
View File
@@ -0,0 +1,115 @@
"""Collection of helper methods.
All containing methods are legacy helpers that should not be used by new
components. Instead call the service directly.
"""
from homeassistant.components.climate import (
_LOGGER, ATTR_AUX_HEAT, ATTR_AWAY_MODE, ATTR_FAN_MODE, ATTR_HOLD_MODE,
ATTR_HUMIDITY, ATTR_OPERATION_MODE, ATTR_SWING_MODE, ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW, DOMAIN, SERVICE_SET_AWAY_MODE, SERVICE_SET_HOLD_MODE,
SERVICE_SET_AUX_HEAT, SERVICE_SET_TEMPERATURE, SERVICE_SET_HUMIDITY,
SERVICE_SET_FAN_MODE, SERVICE_SET_OPERATION_MODE, SERVICE_SET_SWING_MODE)
from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_TEMPERATURE)
from homeassistant.loader import bind_hass
@bind_hass
def set_away_mode(hass, away_mode, entity_id=None):
"""Turn all or specified climate devices away mode on."""
data = {
ATTR_AWAY_MODE: away_mode
}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_AWAY_MODE, data)
@bind_hass
def set_hold_mode(hass, hold_mode, entity_id=None):
"""Set new hold mode."""
data = {
ATTR_HOLD_MODE: hold_mode
}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_HOLD_MODE, data)
@bind_hass
def set_aux_heat(hass, aux_heat, entity_id=None):
"""Turn all or specified climate devices auxiliary heater on."""
data = {
ATTR_AUX_HEAT: aux_heat
}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_AUX_HEAT, data)
@bind_hass
def set_temperature(hass, temperature=None, entity_id=None,
target_temp_high=None, target_temp_low=None,
operation_mode=None):
"""Set new target temperature."""
kwargs = {
key: value for key, value in [
(ATTR_TEMPERATURE, temperature),
(ATTR_TARGET_TEMP_HIGH, target_temp_high),
(ATTR_TARGET_TEMP_LOW, target_temp_low),
(ATTR_ENTITY_ID, entity_id),
(ATTR_OPERATION_MODE, operation_mode)
] if value is not None
}
_LOGGER.debug("set_temperature start data=%s", kwargs)
hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, kwargs)
@bind_hass
def set_humidity(hass, humidity, entity_id=None):
"""Set new target humidity."""
data = {ATTR_HUMIDITY: humidity}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_HUMIDITY, data)
@bind_hass
def set_fan_mode(hass, fan, entity_id=None):
"""Set all or specified climate devices fan mode on."""
data = {ATTR_FAN_MODE: fan}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_FAN_MODE, data)
@bind_hass
def set_operation_mode(hass, operation_mode, entity_id=None):
"""Set new target operation mode."""
data = {ATTR_OPERATION_MODE: operation_mode}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_OPERATION_MODE, data)
@bind_hass
def set_swing_mode(hass, swing_mode, entity_id=None):
"""Set new target swing mode."""
data = {ATTR_SWING_MODE: swing_mode}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_SWING_MODE, data)
+26 -25
View File
@@ -8,6 +8,7 @@ from homeassistant.setup import setup_component
from homeassistant.components import climate
from tests.common import get_test_home_assistant
from tests.components.climate import common
ENTITY_CLIMATE = 'climate.hvac'
@@ -56,7 +57,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test setting the target temperature without required attribute."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(21, state.attributes.get('temperature'))
climate.set_temperature(self.hass, None, ENTITY_CLIMATE)
common.set_temperature(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
self.assertEqual(21, state.attributes.get('temperature'))
@@ -64,7 +65,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test the setting of the target temperature."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(21, state.attributes.get('temperature'))
climate.set_temperature(self.hass, 30, ENTITY_CLIMATE)
common.set_temperature(self.hass, 30, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(30.0, state.attributes.get('temperature'))
@@ -73,7 +74,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test the setting of the target temperature."""
state = self.hass.states.get(ENTITY_HEATPUMP)
self.assertEqual(20, state.attributes.get('temperature'))
climate.set_temperature(self.hass, 21, ENTITY_HEATPUMP)
common.set_temperature(self.hass, 21, ENTITY_HEATPUMP)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_HEATPUMP)
self.assertEqual(21.0, state.attributes.get('temperature'))
@@ -84,8 +85,8 @@ class TestDemoClimate(unittest.TestCase):
self.assertEqual(None, state.attributes.get('temperature'))
self.assertEqual(21.0, state.attributes.get('target_temp_low'))
self.assertEqual(24.0, state.attributes.get('target_temp_high'))
climate.set_temperature(self.hass, target_temp_high=25,
target_temp_low=20, entity_id=ENTITY_ECOBEE)
common.set_temperature(self.hass, target_temp_high=25,
target_temp_low=20, entity_id=ENTITY_ECOBEE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ECOBEE)
self.assertEqual(None, state.attributes.get('temperature'))
@@ -98,9 +99,9 @@ class TestDemoClimate(unittest.TestCase):
self.assertEqual(None, state.attributes.get('temperature'))
self.assertEqual(21.0, state.attributes.get('target_temp_low'))
self.assertEqual(24.0, state.attributes.get('target_temp_high'))
climate.set_temperature(self.hass, temperature=None,
entity_id=ENTITY_ECOBEE, target_temp_low=None,
target_temp_high=None)
common.set_temperature(self.hass, temperature=None,
entity_id=ENTITY_ECOBEE, target_temp_low=None,
target_temp_high=None)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ECOBEE)
self.assertEqual(None, state.attributes.get('temperature'))
@@ -111,7 +112,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test setting the target humidity without required attribute."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(67, state.attributes.get('humidity'))
climate.set_humidity(self.hass, None, ENTITY_CLIMATE)
common.set_humidity(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(67, state.attributes.get('humidity'))
@@ -120,7 +121,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test the setting of the target humidity."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(67, state.attributes.get('humidity'))
climate.set_humidity(self.hass, 64, ENTITY_CLIMATE)
common.set_humidity(self.hass, 64, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(64.0, state.attributes.get('humidity'))
@@ -129,7 +130,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test setting fan mode without required attribute."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("On High", state.attributes.get('fan_mode'))
climate.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("On High", state.attributes.get('fan_mode'))
@@ -138,7 +139,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test setting of new fan mode."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("On High", state.attributes.get('fan_mode'))
climate.set_fan_mode(self.hass, "On Low", ENTITY_CLIMATE)
common.set_fan_mode(self.hass, "On Low", ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("On Low", state.attributes.get('fan_mode'))
@@ -147,7 +148,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test setting swing mode without required attribute."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("Off", state.attributes.get('swing_mode'))
climate.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("Off", state.attributes.get('swing_mode'))
@@ -156,7 +157,7 @@ class TestDemoClimate(unittest.TestCase):
"""Test setting of new swing mode."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("Off", state.attributes.get('swing_mode'))
climate.set_swing_mode(self.hass, "Auto", ENTITY_CLIMATE)
common.set_swing_mode(self.hass, "Auto", ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("Auto", state.attributes.get('swing_mode'))
@@ -169,7 +170,7 @@ class TestDemoClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("cool", state.attributes.get('operation_mode'))
self.assertEqual("cool", state.state)
climate.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("cool", state.attributes.get('operation_mode'))
@@ -180,7 +181,7 @@ class TestDemoClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("cool", state.attributes.get('operation_mode'))
self.assertEqual("cool", state.state)
climate.set_operation_mode(self.hass, "heat", ENTITY_CLIMATE)
common.set_operation_mode(self.hass, "heat", ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("heat", state.attributes.get('operation_mode'))
@@ -190,41 +191,41 @@ class TestDemoClimate(unittest.TestCase):
"""Test setting the away mode without required attribute."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('on', state.attributes.get('away_mode'))
climate.set_away_mode(self.hass, None, ENTITY_CLIMATE)
common.set_away_mode(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
self.assertEqual('on', state.attributes.get('away_mode'))
def test_set_away_mode_on(self):
"""Test setting the away mode on/true."""
climate.set_away_mode(self.hass, True, ENTITY_CLIMATE)
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('on', state.attributes.get('away_mode'))
def test_set_away_mode_off(self):
"""Test setting the away mode off/false."""
climate.set_away_mode(self.hass, False, ENTITY_CLIMATE)
common.set_away_mode(self.hass, False, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('away_mode'))
def test_set_hold_mode_home(self):
"""Test setting the hold mode home."""
climate.set_hold_mode(self.hass, 'home', ENTITY_ECOBEE)
common.set_hold_mode(self.hass, 'home', ENTITY_ECOBEE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ECOBEE)
self.assertEqual('home', state.attributes.get('hold_mode'))
def test_set_hold_mode_away(self):
"""Test setting the hold mode away."""
climate.set_hold_mode(self.hass, 'away', ENTITY_ECOBEE)
common.set_hold_mode(self.hass, 'away', ENTITY_ECOBEE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ECOBEE)
self.assertEqual('away', state.attributes.get('hold_mode'))
def test_set_hold_mode_none(self):
"""Test setting the hold mode off/false."""
climate.set_hold_mode(self.hass, 'off', ENTITY_ECOBEE)
common.set_hold_mode(self.hass, 'off', ENTITY_ECOBEE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_ECOBEE)
self.assertEqual('off', state.attributes.get('hold_mode'))
@@ -233,20 +234,20 @@ class TestDemoClimate(unittest.TestCase):
"""Test setting the auxiliary heater without required attribute."""
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('aux_heat'))
climate.set_aux_heat(self.hass, None, ENTITY_CLIMATE)
common.set_aux_heat(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
self.assertEqual('off', state.attributes.get('aux_heat'))
def test_set_aux_heat_on(self):
"""Test setting the axillary heater on/true."""
climate.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('on', state.attributes.get('aux_heat'))
def test_set_aux_heat_off(self):
"""Test setting the auxiliary heater off/false."""
climate.set_aux_heat(self.hass, False, ENTITY_CLIMATE)
common.set_aux_heat(self.hass, False, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('aux_heat'))
@@ -25,6 +25,7 @@ from homeassistant.components.climate import STATE_HEAT, STATE_COOL
import homeassistant.components as comps
from tests.common import (assert_setup_component, get_test_home_assistant,
mock_restore_cache)
from tests.components.climate import common
ENTITY = 'climate.test'
@@ -108,7 +109,7 @@ class TestGenericThermostatHeaterSwitching(unittest.TestCase):
self._setup_sensor(18)
self.hass.block_till_done()
climate.set_temperature(self.hass, 23)
common.set_temperature(self.hass, 23)
self.hass.block_till_done()
self.assertEqual(STATE_ON,
@@ -135,7 +136,7 @@ class TestGenericThermostatHeaterSwitching(unittest.TestCase):
self._setup_sensor(18)
self.hass.block_till_done()
climate.set_temperature(self.hass, 23)
common.set_temperature(self.hass, 23)
self.hass.block_till_done()
self.assertEqual(STATE_ON,
@@ -186,20 +187,20 @@ class TestClimateGenericThermostat(unittest.TestCase):
def test_set_target_temp(self):
"""Test the setting of the target temperature."""
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(30.0, state.attributes.get('temperature'))
climate.set_temperature(self.hass, None)
common.set_temperature(self.hass, None)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(30.0, state.attributes.get('temperature'))
def test_set_away_mode(self):
"""Test the setting away mode."""
climate.set_temperature(self.hass, 23)
common.set_temperature(self.hass, 23)
self.hass.block_till_done()
climate.set_away_mode(self.hass, True)
common.set_away_mode(self.hass, True)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(16, state.attributes.get('temperature'))
@@ -209,13 +210,13 @@ class TestClimateGenericThermostat(unittest.TestCase):
Verify original temperature is restored.
"""
climate.set_temperature(self.hass, 23)
common.set_temperature(self.hass, 23)
self.hass.block_till_done()
climate.set_away_mode(self.hass, True)
common.set_away_mode(self.hass, True)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(16, state.attributes.get('temperature'))
climate.set_away_mode(self.hass, False)
common.set_away_mode(self.hass, False)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(23, state.attributes.get('temperature'))
@@ -236,7 +237,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
self._setup_switch(False)
self._setup_sensor(25)
self.hass.block_till_done()
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
@@ -249,7 +250,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
self._setup_switch(True)
self._setup_sensor(30)
self.hass.block_till_done()
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self.assertEqual(2, len(self.calls))
call = self.calls[0]
@@ -260,7 +261,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
def test_temp_change_heater_on_within_tolerance(self):
"""Test if temperature change doesn't turn on within tolerance."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(29)
self.hass.block_till_done()
@@ -269,7 +270,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
def test_temp_change_heater_on_outside_tolerance(self):
"""Test if temperature change turn heater on outside cold tolerance."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(27)
self.hass.block_till_done()
@@ -282,7 +283,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
def test_temp_change_heater_off_within_tolerance(self):
"""Test if temperature change doesn't turn off within tolerance."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(33)
self.hass.block_till_done()
@@ -291,7 +292,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
def test_temp_change_heater_off_outside_tolerance(self):
"""Test if temperature change turn heater off outside hot tolerance."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(35)
self.hass.block_till_done()
@@ -304,9 +305,9 @@ class TestClimateGenericThermostat(unittest.TestCase):
def test_running_when_operating_mode_is_off(self):
"""Test that the switch turns off when enabled is set False."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
climate.set_operation_mode(self.hass, STATE_OFF)
common.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
@@ -317,9 +318,9 @@ class TestClimateGenericThermostat(unittest.TestCase):
def test_no_state_change_when_operation_mode_off(self):
"""Test that the switch doesn't turn on when enabled is False."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
climate.set_operation_mode(self.hass, STATE_OFF)
common.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.block_till_done()
@@ -328,7 +329,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
@mock.patch('logging.Logger.error')
def test_invalid_operating_mode(self, log_mock):
"""Test error handling for invalid operation mode."""
climate.set_operation_mode(self.hass, 'invalid mode')
common.set_operation_mode(self.hass, 'invalid mode')
self.hass.block_till_done()
self.assertEqual(log_mock.call_count, 1)
@@ -337,12 +338,12 @@ class TestClimateGenericThermostat(unittest.TestCase):
Switch turns on when temp below setpoint and mode changes.
"""
climate.set_operation_mode(self.hass, STATE_OFF)
climate.set_temperature(self.hass, 30)
common.set_operation_mode(self.hass, STATE_OFF)
common.set_temperature(self.hass, 30)
self._setup_sensor(25)
self.hass.block_till_done()
self._setup_switch(False)
climate.set_operation_mode(self.hass, climate.STATE_HEAT)
common.set_operation_mode(self.hass, climate.STATE_HEAT)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
@@ -395,7 +396,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
self._setup_switch(True)
self._setup_sensor(25)
self.hass.block_till_done()
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self.assertEqual(2, len(self.calls))
call = self.calls[0]
@@ -407,9 +408,9 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
"""Test the setting away mode when cooling."""
self._setup_sensor(25)
self.hass.block_till_done()
climate.set_temperature(self.hass, 19)
common.set_temperature(self.hass, 19)
self.hass.block_till_done()
climate.set_away_mode(self.hass, True)
common.set_away_mode(self.hass, True)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY)
self.assertEqual(30, state.attributes.get('temperature'))
@@ -419,12 +420,12 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
Switch turns on when temp below setpoint and mode changes.
"""
climate.set_operation_mode(self.hass, STATE_OFF)
climate.set_temperature(self.hass, 25)
common.set_operation_mode(self.hass, STATE_OFF)
common.set_temperature(self.hass, 25)
self._setup_sensor(30)
self.hass.block_till_done()
self._setup_switch(False)
climate.set_operation_mode(self.hass, climate.STATE_COOL)
common.set_operation_mode(self.hass, climate.STATE_COOL)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
@@ -437,7 +438,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
self._setup_switch(False)
self._setup_sensor(30)
self.hass.block_till_done()
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
@@ -448,7 +449,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
def test_temp_change_ac_off_within_tolerance(self):
"""Test if temperature change doesn't turn ac off within tolerance."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(29.8)
self.hass.block_till_done()
@@ -457,7 +458,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
def test_set_temp_change_ac_off_outside_tolerance(self):
"""Test if temperature change turn ac off."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(27)
self.hass.block_till_done()
@@ -470,7 +471,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
def test_temp_change_ac_on_within_tolerance(self):
"""Test if temperature change doesn't turn ac on within tolerance."""
self._setup_switch(False)
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self._setup_sensor(25.2)
self.hass.block_till_done()
@@ -479,7 +480,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
def test_temp_change_ac_on_outside_tolerance(self):
"""Test if temperature change turn ac on."""
self._setup_switch(False)
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
@@ -492,9 +493,9 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
def test_running_when_operating_mode_is_off(self):
"""Test that the switch turns off when enabled is set False."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
climate.set_operation_mode(self.hass, STATE_OFF)
common.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))
call = self.calls[0]
@@ -505,9 +506,9 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
def test_no_state_change_when_operation_mode_off(self):
"""Test that the switch doesn't turn on when enabled is False."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
climate.set_operation_mode(self.hass, STATE_OFF)
common.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self._setup_sensor(35)
self.hass.block_till_done()
@@ -556,7 +557,7 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
def test_temp_change_ac_trigger_on_not_long_enough(self):
"""Test if temperature change turn ac on."""
self._setup_switch(False)
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
@@ -569,7 +570,7 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
return_value=fake_changed):
self._setup_switch(False)
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
@@ -582,7 +583,7 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
def test_temp_change_ac_trigger_off_not_long_enough(self):
"""Test if temperature change turn ac on."""
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.block_till_done()
@@ -595,7 +596,7 @@ class TestClimateGenericThermostatACModeMinCycle(unittest.TestCase):
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
return_value=fake_changed):
self._setup_switch(True)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.block_till_done()
@@ -647,7 +648,7 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
def test_temp_change_heater_trigger_off_not_long_enough(self):
"""Test if temp change doesn't turn heater off because of time."""
self._setup_switch(True)
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
@@ -656,7 +657,7 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
def test_temp_change_heater_trigger_on_not_long_enough(self):
"""Test if temp change doesn't turn heater on because of time."""
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.block_till_done()
@@ -669,7 +670,7 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
return_value=fake_changed):
self._setup_switch(False)
climate.set_temperature(self.hass, 30)
common.set_temperature(self.hass, 30)
self.hass.block_till_done()
self._setup_sensor(25)
self.hass.block_till_done()
@@ -686,7 +687,7 @@ class TestClimateGenericThermostatMinCycle(unittest.TestCase):
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
return_value=fake_changed):
self._setup_switch(True)
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
@@ -743,7 +744,7 @@ class TestClimateGenericThermostatACKeepAlive(unittest.TestCase):
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
test_time = datetime.datetime.now(pytz.UTC)
self._send_time_changed(test_time)
@@ -766,7 +767,7 @@ class TestClimateGenericThermostatACKeepAlive(unittest.TestCase):
self.hass.block_till_done()
self._setup_sensor(20)
self.hass.block_till_done()
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
test_time = datetime.datetime.now(pytz.UTC)
self._send_time_changed(test_time)
@@ -833,7 +834,7 @@ class TestClimateGenericThermostatKeepAlive(unittest.TestCase):
self.hass.block_till_done()
self._setup_sensor(20)
self.hass.block_till_done()
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
test_time = datetime.datetime.now(pytz.UTC)
self._send_time_changed(test_time)
@@ -856,7 +857,7 @@ class TestClimateGenericThermostatKeepAlive(unittest.TestCase):
self.hass.block_till_done()
self._setup_sensor(30)
self.hass.block_till_done()
climate.set_temperature(self.hass, 25)
common.set_temperature(self.hass, 25)
self.hass.block_till_done()
test_time = datetime.datetime.now(pytz.UTC)
self._send_time_changed(test_time)
@@ -926,7 +927,7 @@ class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
def test_turn_on_when_off(self):
"""Test if climate.turn_on turns on a turned off device."""
climate.set_operation_mode(self.hass, STATE_OFF)
common.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self.hass.services.call('climate', SERVICE_TURN_ON)
self.hass.block_till_done()
@@ -939,8 +940,8 @@ class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
def test_turn_on_when_on(self):
"""Test if climate.turn_on does nothing to a turned on device."""
climate.set_operation_mode(self.hass, STATE_HEAT, self.HEAT_ENTITY)
climate.set_operation_mode(self.hass, STATE_COOL, self.COOL_ENTITY)
common.set_operation_mode(self.hass, STATE_HEAT, self.HEAT_ENTITY)
common.set_operation_mode(self.hass, STATE_COOL, self.COOL_ENTITY)
self.hass.block_till_done()
self.hass.services.call('climate', SERVICE_TURN_ON)
self.hass.block_till_done()
@@ -953,8 +954,8 @@ class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
def test_turn_off_when_on(self):
"""Test if climate.turn_off turns off a turned on device."""
climate.set_operation_mode(self.hass, STATE_HEAT, self.HEAT_ENTITY)
climate.set_operation_mode(self.hass, STATE_COOL, self.COOL_ENTITY)
common.set_operation_mode(self.hass, STATE_HEAT, self.HEAT_ENTITY)
common.set_operation_mode(self.hass, STATE_COOL, self.COOL_ENTITY)
self.hass.block_till_done()
self.hass.services.call('climate', SERVICE_TURN_OFF)
self.hass.block_till_done()
@@ -967,7 +968,7 @@ class TestClimateGenericThermostatTurnOnOff(unittest.TestCase):
def test_turn_off_when_off(self):
"""Test if climate.turn_off does nothing to a turned off device."""
climate.set_operation_mode(self.hass, STATE_OFF)
common.set_operation_mode(self.hass, STATE_OFF)
self.hass.block_till_done()
self.hass.services.call('climate', SERVICE_TURN_OFF)
self.hass.block_till_done()
+30 -29
View File
@@ -16,6 +16,7 @@ from homeassistant.components.mqtt.discovery import async_start
from tests.common import (get_test_home_assistant, mock_mqtt_component,
async_fire_mqtt_message, fire_mqtt_message,
mock_component)
from tests.components.climate import common
ENTITY_CLIMATE = 'climate.test'
@@ -90,7 +91,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('operation_mode'))
self.assertEqual("off", state.state)
climate.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
common.set_operation_mode(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('operation_mode'))
@@ -103,7 +104,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('operation_mode'))
self.assertEqual("off", state.state)
climate.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("cool", state.attributes.get('operation_mode'))
@@ -121,7 +122,7 @@ class TestMQTTClimate(unittest.TestCase):
self.assertEqual("off", state.attributes.get('operation_mode'))
self.assertEqual("off", state.state)
climate.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
common.set_operation_mode(self.hass, "cool", ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('operation_mode'))
@@ -148,7 +149,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('operation_mode'))
self.assertEqual("off", state.state)
climate.set_operation_mode(self.hass, "on", ENTITY_CLIMATE)
common.set_operation_mode(self.hass, "on", ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("on", state.attributes.get('operation_mode'))
@@ -159,7 +160,7 @@ class TestMQTTClimate(unittest.TestCase):
])
self.mock_publish.async_publish.reset_mock()
climate.set_operation_mode(self.hass, "off", ENTITY_CLIMATE)
common.set_operation_mode(self.hass, "off", ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('operation_mode'))
@@ -176,7 +177,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("low", state.attributes.get('fan_mode'))
climate.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
common.set_fan_mode(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("low", state.attributes.get('fan_mode'))
@@ -190,7 +191,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("low", state.attributes.get('fan_mode'))
climate.set_fan_mode(self.hass, 'high', ENTITY_CLIMATE)
common.set_fan_mode(self.hass, 'high', ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("low", state.attributes.get('fan_mode'))
@@ -211,7 +212,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("low", state.attributes.get('fan_mode'))
climate.set_fan_mode(self.hass, 'high', ENTITY_CLIMATE)
common.set_fan_mode(self.hass, 'high', ENTITY_CLIMATE)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'fan-mode-topic', 'high', 0, False)
@@ -224,7 +225,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('swing_mode'))
climate.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
common.set_swing_mode(self.hass, None, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('swing_mode'))
@@ -238,7 +239,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('swing_mode'))
climate.set_swing_mode(self.hass, 'on', ENTITY_CLIMATE)
common.set_swing_mode(self.hass, 'on', ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('swing_mode'))
@@ -259,7 +260,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("off", state.attributes.get('swing_mode'))
climate.set_swing_mode(self.hass, 'on', ENTITY_CLIMATE)
common.set_swing_mode(self.hass, 'on', ENTITY_CLIMATE)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'swing-mode-topic', 'on', 0, False)
@@ -272,15 +273,15 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(21, state.attributes.get('temperature'))
climate.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('heat', state.attributes.get('operation_mode'))
self.mock_publish.async_publish.assert_called_once_with(
'mode-topic', 'heat', 0, False)
self.mock_publish.async_publish.reset_mock()
climate.set_temperature(self.hass, temperature=47,
entity_id=ENTITY_CLIMATE)
common.set_temperature(self.hass, temperature=47,
entity_id=ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(47, state.attributes.get('temperature'))
@@ -289,9 +290,9 @@ class TestMQTTClimate(unittest.TestCase):
# also test directly supplying the operation mode to set_temperature
self.mock_publish.async_publish.reset_mock()
climate.set_temperature(self.hass, temperature=21,
operation_mode="cool",
entity_id=ENTITY_CLIMATE)
common.set_temperature(self.hass, temperature=21,
operation_mode="cool",
entity_id=ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('cool', state.attributes.get('operation_mode'))
@@ -310,10 +311,10 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(21, state.attributes.get('temperature'))
climate.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
self.hass.block_till_done()
climate.set_temperature(self.hass, temperature=47,
entity_id=ENTITY_CLIMATE)
common.set_temperature(self.hass, temperature=47,
entity_id=ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(21, state.attributes.get('temperature'))
@@ -349,7 +350,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('away_mode'))
climate.set_away_mode(self.hass, True, ENTITY_CLIMATE)
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('away_mode'))
@@ -379,7 +380,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('away_mode'))
climate.set_away_mode(self.hass, True, ENTITY_CLIMATE)
common.set_away_mode(self.hass, True, ENTITY_CLIMATE)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'away-mode-topic', 'AN', 0, False)
@@ -387,7 +388,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('on', state.attributes.get('away_mode'))
climate.set_away_mode(self.hass, False, ENTITY_CLIMATE)
common.set_away_mode(self.hass, False, ENTITY_CLIMATE)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'away-mode-topic', 'AUS', 0, False)
@@ -403,7 +404,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(None, state.attributes.get('hold_mode'))
climate.set_hold_mode(self.hass, 'on', ENTITY_CLIMATE)
common.set_hold_mode(self.hass, 'on', ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(None, state.attributes.get('hold_mode'))
@@ -424,7 +425,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(None, state.attributes.get('hold_mode'))
climate.set_hold_mode(self.hass, 'on', ENTITY_CLIMATE)
common.set_hold_mode(self.hass, 'on', ENTITY_CLIMATE)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'hold-topic', 'on', 0, False)
@@ -432,7 +433,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('on', state.attributes.get('hold_mode'))
climate.set_hold_mode(self.hass, 'off', ENTITY_CLIMATE)
common.set_hold_mode(self.hass, 'off', ENTITY_CLIMATE)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'hold-topic', 'off', 0, False)
@@ -448,7 +449,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('aux_heat'))
climate.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
self.hass.block_till_done()
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('aux_heat'))
@@ -474,7 +475,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('off', state.attributes.get('aux_heat'))
climate.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
common.set_aux_heat(self.hass, True, ENTITY_CLIMATE)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'aux-topic', 'ON', 0, False)
@@ -482,7 +483,7 @@ class TestMQTTClimate(unittest.TestCase):
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual('on', state.attributes.get('aux_heat'))
climate.set_aux_heat(self.hass, False, ENTITY_CLIMATE)
common.set_aux_heat(self.hass, False, ENTITY_CLIMATE)
self.hass.block_till_done()
self.mock_publish.async_publish.assert_called_once_with(
'aux-topic', 'OFF', 0, False)