Remove garage_door, hvac, rollershutter and thermostat components/platforms
This commit is contained in:
1 parent
4c86721e70
commit
044b9caa76
48 files changed
-6386
No files matched your search
@@ -1 +0,0 @@
|
||||
"""The tests for Garage door platforms."""
|
||||
@@ -1,50 +0,0 @@
|
||||
"""The tests for the Demo Garage door platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import setup_component
|
||||
import homeassistant.components.garage_door as gd
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
LEFT = 'garage_door.left_garage_door'
|
||||
RIGHT = 'garage_door.right_garage_door'
|
||||
|
||||
|
||||
class TestGarageDoorDemo(unittest.TestCase):
|
||||
"""Test the demo garage door."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.assertTrue(setup_component(self.hass, gd.DOMAIN, {
|
||||
'garage_door': {
|
||||
'platform': 'demo'
|
||||
}
|
||||
}))
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_is_closed(self):
|
||||
"""Test if door is closed."""
|
||||
self.assertTrue(gd.is_closed(self.hass, LEFT))
|
||||
self.hass.states.is_state(LEFT, 'close')
|
||||
|
||||
self.assertFalse(gd.is_closed(self.hass, RIGHT))
|
||||
self.hass.states.is_state(RIGHT, 'open')
|
||||
|
||||
def test_open_door(self):
|
||||
"""Test opeing of the door."""
|
||||
gd.open_door(self.hass, LEFT)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertFalse(gd.is_closed(self.hass, LEFT))
|
||||
|
||||
def test_close_door(self):
|
||||
"""Test closing ot the door."""
|
||||
gd.close_door(self.hass, RIGHT)
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertTrue(gd.is_closed(self.hass, RIGHT))
|
||||
@@ -1,138 +0,0 @@
|
||||
"""The tests for the MQTT Garge door platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import setup_component
|
||||
from homeassistant.const import STATE_OPEN, STATE_CLOSED, ATTR_ASSUMED_STATE
|
||||
|
||||
import homeassistant.components.garage_door as garage_door
|
||||
from tests.common import (
|
||||
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant,
|
||||
assert_setup_component)
|
||||
|
||||
|
||||
class TestGarageDoorMQTT(unittest.TestCase):
|
||||
"""Test the MQTT Garage door."""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mock_publish = mock_mqtt_component(self.hass)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
""""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_fail_setup_if_no_command_topic(self):
|
||||
"""Test if command fails with command topic."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
with assert_setup_component(0):
|
||||
assert setup_component(self.hass, garage_door.DOMAIN, {
|
||||
garage_door.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': '/home/garage_door/door'
|
||||
}
|
||||
})
|
||||
self.assertIsNone(self.hass.states.get('garage_door.test'))
|
||||
|
||||
def test_controlling_state_via_topic(self):
|
||||
"""Test the controlling state via topic."""
|
||||
with assert_setup_component(1):
|
||||
assert setup_component(self.hass, garage_door.DOMAIN, {
|
||||
garage_door.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'state_open': 1,
|
||||
'state_closed': 0,
|
||||
'service_open': 1,
|
||||
'service_close': 0
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_CLOSED, state.state)
|
||||
self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '1')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_OPEN, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '0')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_CLOSED, state.state)
|
||||
|
||||
def test_sending_mqtt_commands_and_optimistic(self):
|
||||
"""Test the sending MQTT commands in optimistic mode."""
|
||||
with assert_setup_component(1):
|
||||
assert setup_component(self.hass, garage_door.DOMAIN, {
|
||||
garage_door.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'command_topic': 'command-topic',
|
||||
'state_open': 'beer state open',
|
||||
'state_closed': 'beer state closed',
|
||||
'service_open': 'beer open',
|
||||
'service_close': 'beer close',
|
||||
'qos': '2'
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_CLOSED, state.state)
|
||||
self.assertTrue(state.attributes.get(ATTR_ASSUMED_STATE))
|
||||
|
||||
garage_door.open_door(self.hass, 'garage_door.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('command-topic', 'beer open', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_OPEN, state.state)
|
||||
|
||||
garage_door.close_door(self.hass, 'garage_door.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('command-topic', 'beer close', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_CLOSED, state.state)
|
||||
|
||||
def test_controlling_state_via_topic_and_json_message(self):
|
||||
"""Test the controlling state via topic and JSON message."""
|
||||
with assert_setup_component(1):
|
||||
assert setup_component(self.hass, garage_door.DOMAIN, {
|
||||
garage_door.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'state_open': 'beer open',
|
||||
'state_closed': 'beer closed',
|
||||
'service_open': 'beer service open',
|
||||
'service_close': 'beer service close',
|
||||
'value_template': '{{ value_json.val }}'
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_CLOSED, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '{"val":"beer open"}')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_OPEN, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '{"val":"beer closed"}')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('garage_door.test')
|
||||
self.assertEqual(STATE_CLOSED, state.state)
|
||||
@@ -1 +0,0 @@
|
||||
"""The tests for hvac component."""
|
||||
@@ -1,167 +0,0 @@
|
||||
"""The tests for the demo hvac."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import setup_component
|
||||
from homeassistant.components import hvac
|
||||
from homeassistant.util.unit_system import (
|
||||
METRIC_SYSTEM,
|
||||
)
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
ENTITY_HVAC = 'hvac.hvac'
|
||||
|
||||
|
||||
class TestDemoHvac(unittest.TestCase):
|
||||
"""Test the demo hvac."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.units = METRIC_SYSTEM
|
||||
self.assertTrue(setup_component(self.hass, hvac.DOMAIN, {'hvac': {
|
||||
'platform': 'demo',
|
||||
}}))
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup_params(self):
|
||||
"""Test the inititial parameters."""
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual(21, state.attributes.get('temperature'))
|
||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
||||
self.assertEqual(22, state.attributes.get('current_temperature'))
|
||||
self.assertEqual("On High", state.attributes.get('fan_mode'))
|
||||
self.assertEqual(67, state.attributes.get('humidity'))
|
||||
self.assertEqual(54, state.attributes.get('current_humidity'))
|
||||
self.assertEqual("Off", state.attributes.get('swing_mode'))
|
||||
self.assertEqual("Cool", state.attributes.get('operation_mode'))
|
||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
||||
|
||||
def test_default_setup_params(self):
|
||||
"""Test the setup with default parameters."""
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual(19, state.attributes.get('min_temp'))
|
||||
self.assertEqual(30, state.attributes.get('max_temp'))
|
||||
self.assertEqual(30, state.attributes.get('min_humidity'))
|
||||
self.assertEqual(99, state.attributes.get('max_humidity'))
|
||||
|
||||
def test_set_target_temp_bad_attr(self):
|
||||
"""Test setting the target temperature without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual(21, state.attributes.get('temperature'))
|
||||
hvac.set_temperature(self.hass, None, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(21, state.attributes.get('temperature'))
|
||||
|
||||
def test_set_target_temp(self):
|
||||
"""Test the setting of the target temperature."""
|
||||
hvac.set_temperature(self.hass, 30, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual(30.0, state.attributes.get('temperature'))
|
||||
|
||||
def test_set_target_humidity_bad_attr(self):
|
||||
"""Test setting the target humidity without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual(67, state.attributes.get('humidity'))
|
||||
hvac.set_humidity(self.hass, None, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(67, state.attributes.get('humidity'))
|
||||
|
||||
def test_set_target_humidity(self):
|
||||
"""Test the setting of the target humidity."""
|
||||
hvac.set_humidity(self.hass, 64, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual(64.0, state.attributes.get('humidity'))
|
||||
|
||||
def test_set_fan_mode_bad_attr(self):
|
||||
"""Test setting fan mode without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual("On High", state.attributes.get('fan_mode'))
|
||||
hvac.set_fan_mode(self.hass, None, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual("On High", state.attributes.get('fan_mode'))
|
||||
|
||||
def test_set_fan_mode(self):
|
||||
"""Test setting of new fan mode."""
|
||||
hvac.set_fan_mode(self.hass, "On Low", ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual("On Low", state.attributes.get('fan_mode'))
|
||||
|
||||
def test_set_swing_mode_bad_attr(self):
|
||||
"""Test setting swing mode without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual("Off", state.attributes.get('swing_mode'))
|
||||
hvac.set_swing_mode(self.hass, None, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual("Off", state.attributes.get('swing_mode'))
|
||||
|
||||
def test_set_swing(self):
|
||||
"""Test setting of new swing mode."""
|
||||
hvac.set_swing_mode(self.hass, "Auto", ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual("Auto", state.attributes.get('swing_mode'))
|
||||
|
||||
def test_set_operation_bad_attr(self):
|
||||
"""Test setting operation mode without required attribute."""
|
||||
self.assertEqual("Cool", self.hass.states.get(ENTITY_HVAC).state)
|
||||
hvac.set_operation_mode(self.hass, None, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual("Cool", self.hass.states.get(ENTITY_HVAC).state)
|
||||
|
||||
def test_set_operation(self):
|
||||
"""Test setting of new operation mode."""
|
||||
hvac.set_operation_mode(self.hass, "Heat", ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual("Heat", self.hass.states.get(ENTITY_HVAC).state)
|
||||
|
||||
def test_set_away_mode_bad_attr(self):
|
||||
"""Test setting the away mode without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
||||
hvac.set_away_mode(self.hass, None, ENTITY_HVAC)
|
||||
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."""
|
||||
hvac.set_away_mode(self.hass, True, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
||||
|
||||
def test_set_away_mode_off(self):
|
||||
"""Test setting the away mode off/false."""
|
||||
hvac.set_away_mode(self.hass, False, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
|
||||
def test_set_aux_heat_bad_attr(self):
|
||||
"""Test setting the auxillary heater without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
||||
hvac.set_aux_heat(self.hass, None, ENTITY_HVAC)
|
||||
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."""
|
||||
hvac.set_aux_heat(self.hass, True, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual('on', state.attributes.get('aux_heat'))
|
||||
|
||||
def test_set_aux_heat_off(self):
|
||||
"""Test setting the auxillary heater off/false."""
|
||||
hvac.set_aux_heat(self.hass, False, ENTITY_HVAC)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_HVAC)
|
||||
self.assertEqual('off', state.attributes.get('aux_heat'))
|
||||
@@ -1 +0,0 @@
|
||||
"""The tests for Roller shutter platforms."""
|
||||
@@ -1,88 +0,0 @@
|
||||
"""The tests the Roller shutter command line platform."""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from homeassistant.bootstrap import setup_component
|
||||
import homeassistant.components.rollershutter as rollershutter
|
||||
from homeassistant.components.rollershutter import (
|
||||
command_line as cmd_rs)
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestCommandRollerShutter(unittest.TestCase):
|
||||
"""Test the Roller shutter command line platform."""
|
||||
|
||||
def setup_method(self, method):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.latitude = 32.87336
|
||||
self.hass.config.longitude = 117.22743
|
||||
self.rs = cmd_rs.CommandRollershutter(self.hass, 'foo',
|
||||
'cmd_up', 'cmd_dn',
|
||||
'cmd_stop', 'cmd_state',
|
||||
None) # FIXME
|
||||
|
||||
def teardown_method(self, method):
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_should_poll(self):
|
||||
"""Test the setting of polling."""
|
||||
self.assertTrue(self.rs.should_poll)
|
||||
self.rs._command_state = None
|
||||
self.assertFalse(self.rs.should_poll)
|
||||
|
||||
def test_query_state_value(self):
|
||||
"""Test with state value."""
|
||||
with mock.patch('subprocess.check_output') as mock_run:
|
||||
mock_run.return_value = b' foo bar '
|
||||
result = self.rs._query_state_value('runme')
|
||||
self.assertEqual('foo bar', result)
|
||||
self.assertEqual(mock_run.call_count, 1)
|
||||
self.assertEqual(
|
||||
mock_run.call_args, mock.call('runme', shell=True)
|
||||
)
|
||||
|
||||
def test_state_value(self):
|
||||
"""Test with state value."""
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, 'rollershutter_status')
|
||||
test_rollershutter = {
|
||||
'statecmd': 'cat {}'.format(path),
|
||||
'upcmd': 'echo 1 > {}'.format(path),
|
||||
'downcmd': 'echo 1 > {}'.format(path),
|
||||
'stopcmd': 'echo 0 > {}'.format(path),
|
||||
'value_template': '{{ value }}'
|
||||
}
|
||||
self.assertTrue(setup_component(self.hass, rollershutter.DOMAIN, {
|
||||
'rollershutter': {
|
||||
'platform': 'command_line',
|
||||
'rollershutters': {
|
||||
'test': test_rollershutter
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual('unknown', state.state)
|
||||
|
||||
rollershutter.move_up(self.hass, 'rollershutter.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual('open', state.state)
|
||||
|
||||
rollershutter.move_down(self.hass, 'rollershutter.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual('open', state.state)
|
||||
|
||||
rollershutter.stop(self.hass, 'rollershutter.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual('closed', state.state)
|
||||
@@ -1,55 +0,0 @@
|
||||
"""The tests for the Demo roller shutter platform."""
|
||||
import unittest
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from homeassistant.components.rollershutter import demo
|
||||
from tests.common import fire_time_changed, get_test_home_assistant
|
||||
|
||||
|
||||
class TestRollershutterDemo(unittest.TestCase):
|
||||
"""Test the Demo roller shutter."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_move_up(self):
|
||||
"""Test moving the rollershutter up."""
|
||||
entity = demo.DemoRollershutter(self.hass, 'test', 100)
|
||||
entity.move_up()
|
||||
|
||||
fire_time_changed(self.hass, dt_util.utcnow())
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(90, entity.current_position)
|
||||
|
||||
def test_move_down(self):
|
||||
"""Test moving the rollershutter down."""
|
||||
entity = demo.DemoRollershutter(self.hass, 'test', 0)
|
||||
entity.move_down()
|
||||
|
||||
fire_time_changed(self.hass, dt_util.utcnow())
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(10, entity.current_position)
|
||||
|
||||
def test_move_position(self):
|
||||
"""Test moving the rollershutter to a specific position."""
|
||||
entity = demo.DemoRollershutter(self.hass, 'test', 0)
|
||||
entity.move_position(10)
|
||||
|
||||
fire_time_changed(self.hass, dt_util.utcnow())
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(10, entity.current_position)
|
||||
|
||||
def test_stop(self):
|
||||
"""Test stopping the rollershutter."""
|
||||
entity = demo.DemoRollershutter(self.hass, 'test', 0)
|
||||
entity.move_down()
|
||||
entity.stop()
|
||||
|
||||
fire_time_changed(self.hass, dt_util.utcnow())
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, entity.current_position)
|
||||
@@ -1,174 +0,0 @@
|
||||
"""The tests for the MQTT roller shutter platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
from homeassistant.const import STATE_OPEN, STATE_CLOSED, STATE_UNKNOWN
|
||||
import homeassistant.components.rollershutter as rollershutter
|
||||
from tests.common import mock_mqtt_component, fire_mqtt_message
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestRollershutterMQTT(unittest.TestCase):
|
||||
"""Test the MQTT roller shutter."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.mock_publish = mock_mqtt_component(self.hass)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_controlling_state_via_topic(self):
|
||||
"""Test the controlling state via topic."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, rollershutter.DOMAIN, {
|
||||
rollershutter.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'qos': 0,
|
||||
'payload_up': 'UP',
|
||||
'payload_down': 'DOWN',
|
||||
'payload_stop': 'STOP'
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '0')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_CLOSED, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '50')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_OPEN, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '100')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_OPEN, state.state)
|
||||
|
||||
def test_send_move_up_command(self):
|
||||
"""Test the sending of move_up."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, rollershutter.DOMAIN, {
|
||||
rollershutter.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'qos': 2
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
rollershutter.move_up(self.hass, 'rollershutter.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('command-topic', 'UP', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
def test_send_move_down_command(self):
|
||||
"""Test the sending of move_down."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, rollershutter.DOMAIN, {
|
||||
rollershutter.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'qos': 2
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
rollershutter.move_down(self.hass, 'rollershutter.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('command-topic', 'DOWN', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
def test_send_stop_command(self):
|
||||
"""Test the sending of stop."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, rollershutter.DOMAIN, {
|
||||
rollershutter.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'qos': 2
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
rollershutter.stop(self.hass, 'rollershutter.test')
|
||||
self.hass.block_till_done()
|
||||
|
||||
self.assertEqual(('command-topic', 'STOP', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
state = self.hass.states.get('rollershutter.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
def test_state_attributes_current_position(self):
|
||||
"""Test the current position."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, rollershutter.DOMAIN, {
|
||||
rollershutter.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'payload_up': 'UP',
|
||||
'payload_down': 'DOWN',
|
||||
'payload_stop': 'STOP'
|
||||
}
|
||||
})
|
||||
|
||||
state_attributes_dict = self.hass.states.get(
|
||||
'rollershutter.test').attributes
|
||||
self.assertFalse('current_position' in state_attributes_dict)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '0')
|
||||
self.hass.block_till_done()
|
||||
current_position = self.hass.states.get(
|
||||
'rollershutter.test').attributes['current_position']
|
||||
self.assertEqual(0, current_position)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '50')
|
||||
self.hass.block_till_done()
|
||||
current_position = self.hass.states.get(
|
||||
'rollershutter.test').attributes['current_position']
|
||||
self.assertEqual(50, current_position)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '101')
|
||||
self.hass.block_till_done()
|
||||
current_position = self.hass.states.get(
|
||||
'rollershutter.test').attributes['current_position']
|
||||
self.assertEqual(50, current_position)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', 'non-numeric')
|
||||
self.hass.block_till_done()
|
||||
current_position = self.hass.states.get(
|
||||
'rollershutter.test').attributes['current_position']
|
||||
self.assertEqual(50, current_position)
|
||||
@@ -1,219 +0,0 @@
|
||||
"""The tests for the Rfxtrx roller shutter platform."""
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
from homeassistant.components import rfxtrx as rfxtrx_core
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
@pytest.mark.skipif("os.environ.get('RFXTRX') != 'RUN'")
|
||||
class TestRollershutterRfxtrx(unittest.TestCase):
|
||||
"""Test the Rfxtrx roller shutter platform."""
|
||||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant(0)
|
||||
self.hass.config.components = ['rfxtrx']
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = []
|
||||
rfxtrx_core.RFX_DEVICES = {}
|
||||
if rfxtrx_core.RFXOBJECT:
|
||||
rfxtrx_core.RFXOBJECT.close_connection()
|
||||
self.hass.stop()
|
||||
|
||||
def test_valid_config(self):
|
||||
"""Test configuration."""
|
||||
self.assertTrue(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'0b1100cd0213c7f210010f51': {
|
||||
'name': 'Test',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
|
||||
def test_invalid_config1(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'2FF7f216': {
|
||||
'name': 'Test',
|
||||
'packetid': '0b1100cd0213c7f210010f51',
|
||||
'signal_repetitions': 3}
|
||||
}}}))
|
||||
|
||||
def test_invalid_config2(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'invalid_key': 'afda',
|
||||
'devices':
|
||||
{'213c7f216': {
|
||||
'name': 'Test',
|
||||
'packetid': '0b1100cd0213c7f210010f51',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
|
||||
def test_invalid_config3(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'213c7f216': {
|
||||
'name': 'Test',
|
||||
'packetid': 'AA1100cd0213c7f210010f51',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
|
||||
def test_invalid_config4(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'213c7f216': {
|
||||
'name': 'Test',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
|
||||
def test_default_config(self):
|
||||
"""Test with 0 roller shutter."""
|
||||
self.assertTrue(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'devices': {}}}))
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
def test_one_rollershutter(self):
|
||||
"""Test with 1 roller shutter."""
|
||||
self.assertTrue(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'devices':
|
||||
{'0b1400cd0213c7f210010f51': {
|
||||
'name': 'Test'
|
||||
}}}}))
|
||||
|
||||
import RFXtrx as rfxtrxmod
|
||||
rfxtrx_core.RFXOBJECT =\
|
||||
rfxtrxmod.Core("", transport_protocol=rfxtrxmod.DummyTransport)
|
||||
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
for id in rfxtrx_core.RFX_DEVICES:
|
||||
entity = rfxtrx_core.RFX_DEVICES[id]
|
||||
self.assertEqual(entity.signal_repetitions, 1)
|
||||
self.assertFalse(entity.should_fire_event)
|
||||
self.assertFalse(entity.should_poll)
|
||||
entity.move_up()
|
||||
entity.move_down()
|
||||
entity.stop()
|
||||
|
||||
def test_several_rollershutters(self):
|
||||
"""Test with 3 roller shutters."""
|
||||
self.assertTrue(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'signal_repetitions': 3,
|
||||
'devices':
|
||||
{'0b1100cd0213c7f230010f71': {
|
||||
'name': 'Test'},
|
||||
'0b1100100118cdea02010f70': {
|
||||
'name': 'Bath'},
|
||||
'0b1100101118cdea02010f70': {
|
||||
'name': 'Living'}
|
||||
}}}))
|
||||
|
||||
self.assertEqual(3, len(rfxtrx_core.RFX_DEVICES))
|
||||
device_num = 0
|
||||
for id in rfxtrx_core.RFX_DEVICES:
|
||||
entity = rfxtrx_core.RFX_DEVICES[id]
|
||||
self.assertEqual(entity.signal_repetitions, 3)
|
||||
if entity.name == 'Living':
|
||||
device_num = device_num + 1
|
||||
elif entity.name == 'Bath':
|
||||
device_num = device_num + 1
|
||||
elif entity.name == 'Test':
|
||||
device_num = device_num + 1
|
||||
|
||||
self.assertEqual(3, device_num)
|
||||
|
||||
def test_discover_rollershutter(self):
|
||||
"""Test with discovery of roller shutters."""
|
||||
self.assertTrue(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices': {}}}))
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0a140002f38cae010f0070')
|
||||
event.data = bytearray([0x0A, 0x14, 0x00, 0x02, 0xF3, 0x8C,
|
||||
0xAE, 0x01, 0x0F, 0x00, 0x70])
|
||||
|
||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||
evt_sub(event)
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
||||
|
||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||
evt_sub(event)
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
# Trying to add a sensor
|
||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||
evt_sub(event)
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
# Trying to add a light
|
||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||
event.data = bytearray([0x0b, 0x11, 0x11, 0x10, 0x01, 0x18,
|
||||
0xcd, 0xea, 0x01, 0x02, 0x0f, 0x70])
|
||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||
evt_sub(event)
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
def test_discover_rollershutter_noautoadd(self):
|
||||
"""Test with discovery of roller shutter when auto add is False."""
|
||||
self.assertTrue(_setup_component(self.hass, 'rollershutter', {
|
||||
'rollershutter': {'platform': 'rfxtrx',
|
||||
'automatic_add': False,
|
||||
'devices': {}}}))
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab010d0060')
|
||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||
0xAB, 0x01, 0x0D, 0x00, 0x60])
|
||||
|
||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||
evt_sub(event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0a1400adf394ab020e0060')
|
||||
event.data = bytearray([0x0A, 0x14, 0x00, 0xAD, 0xF3, 0x94,
|
||||
0xAB, 0x02, 0x0E, 0x00, 0x60])
|
||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||
evt_sub(event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
# Trying to add a sensor
|
||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||
event.data = bytearray(b'\nR\x08^\x07\x01\x00\xb3\x1b\x02y')
|
||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||
evt_sub(event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
# Trying to add a light
|
||||
event = rfxtrx_core.get_rfx_object('0b1100100118cdea02010f70')
|
||||
event.data = bytearray([0x0b, 0x11, 0x11, 0x10, 0x01,
|
||||
0x18, 0xcd, 0xea, 0x01, 0x02, 0x0f, 0x70])
|
||||
for evt_sub in rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS:
|
||||
evt_sub(event)
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
@@ -1 +0,0 @@
|
||||
"""The tests for Thermostat platforms."""
|
||||
@@ -1,101 +0,0 @@
|
||||
"""The tests for the demo thermostat."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.util.unit_system import (
|
||||
METRIC_SYSTEM,
|
||||
)
|
||||
from homeassistant.components import thermostat
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
ENTITY_NEST = 'thermostat.nest'
|
||||
|
||||
|
||||
class TestDemoThermostat(unittest.TestCase):
|
||||
"""Test the Heat Control thermostat."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.units = METRIC_SYSTEM
|
||||
self.assertTrue(thermostat.setup(self.hass, {'thermostat': {
|
||||
'platform': 'demo',
|
||||
}}))
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup_params(self):
|
||||
"""Test the inititial parameters."""
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual(21, state.attributes.get('temperature'))
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
self.assertEqual(19, state.attributes.get('current_temperature'))
|
||||
self.assertEqual('off', state.attributes.get('fan'))
|
||||
|
||||
def test_default_setup_params(self):
|
||||
"""Test the setup with default parameters."""
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual(7, state.attributes.get('min_temp'))
|
||||
self.assertEqual(35, state.attributes.get('max_temp'))
|
||||
|
||||
def test_set_target_temp_bad_attr(self):
|
||||
"""Test setting the target temperature without required attribute."""
|
||||
self.assertEqual('21.0', self.hass.states.get(ENTITY_NEST).state)
|
||||
thermostat.set_temperature(self.hass, None, ENTITY_NEST)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual('21.0', self.hass.states.get(ENTITY_NEST).state)
|
||||
|
||||
def test_set_target_temp(self):
|
||||
"""Test the setting of the target temperature."""
|
||||
thermostat.set_temperature(self.hass, 30, ENTITY_NEST)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual('30.0', self.hass.states.get(ENTITY_NEST).state)
|
||||
|
||||
def test_set_away_mode_bad_attr(self):
|
||||
"""Test setting the away mode without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
thermostat.set_away_mode(self.hass, None, ENTITY_NEST)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
|
||||
def test_set_away_mode_on(self):
|
||||
"""Test setting the away mode on/true."""
|
||||
thermostat.set_away_mode(self.hass, True, ENTITY_NEST)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
||||
|
||||
def test_set_away_mode_off(self):
|
||||
"""Test setting the away mode off/false."""
|
||||
thermostat.set_away_mode(self.hass, False, ENTITY_NEST)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
|
||||
def test_set_fan_mode_on_bad_attr(self):
|
||||
"""Test setting the fan mode on/true without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual('off', state.attributes.get('fan'))
|
||||
thermostat.set_fan_mode(self.hass, None, ENTITY_NEST)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual('off', state.attributes.get('fan'))
|
||||
|
||||
def test_set_fan_mode_on(self):
|
||||
"""Test setting the fan mode on/true."""
|
||||
thermostat.set_fan_mode(self.hass, True, ENTITY_NEST)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual('on', state.attributes.get('fan'))
|
||||
|
||||
def test_set_fan_mode_off(self):
|
||||
"""Test setting the fan mode off/false."""
|
||||
thermostat.set_fan_mode(self.hass, False, ENTITY_NEST)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_NEST)
|
||||
self.assertEqual('off', state.attributes.get('fan'))
|
||||
@@ -1,494 +0,0 @@
|
||||
"""The tests for the heat control thermostat."""
|
||||
import datetime
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
|
||||
from homeassistant.bootstrap import setup_component
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_ON,
|
||||
STATE_OFF,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
from homeassistant.components import thermostat
|
||||
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
|
||||
|
||||
ENTITY = 'thermostat.test'
|
||||
ENT_SENSOR = 'sensor.test'
|
||||
ENT_SWITCH = 'switch.test'
|
||||
MIN_TEMP = 3.0
|
||||
MAX_TEMP = 65.0
|
||||
TARGET_TEMP = 42.0
|
||||
|
||||
|
||||
class TestSetupThermostatHeatControl(unittest.TestCase):
|
||||
"""Test the Heat Control thermostat with custom config."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup_missing_conf(self):
|
||||
"""Test set up heat_control with missing config values."""
|
||||
config = {
|
||||
'name': 'test',
|
||||
'target_sensor': ENT_SENSOR
|
||||
}
|
||||
with assert_setup_component(0):
|
||||
setup_component(self.hass, 'thermostat', {
|
||||
'thermostat': config})
|
||||
|
||||
def test_valid_conf(self):
|
||||
"""Test set up heat_control with valid config values."""
|
||||
self.assertTrue(setup_component(self.hass, 'thermostat',
|
||||
{'thermostat': {
|
||||
'platform': 'heat_control',
|
||||
'name': 'test',
|
||||
'heater': ENT_SWITCH,
|
||||
'target_sensor': ENT_SENSOR}}))
|
||||
|
||||
def test_setup_with_sensor(self):
|
||||
"""Test set up heat_control with sensor to trigger update at init."""
|
||||
self.hass.states.set(ENT_SENSOR, 22.0, {
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS
|
||||
})
|
||||
thermostat.setup(self.hass, {'thermostat': {
|
||||
'platform': 'heat_control',
|
||||
'name': 'test',
|
||||
'heater': ENT_SWITCH,
|
||||
'target_sensor': ENT_SENSOR
|
||||
}})
|
||||
state = self.hass.states.get(ENTITY)
|
||||
self.assertEqual(
|
||||
TEMP_CELSIUS, state.attributes.get('unit_of_measurement'))
|
||||
self.assertEqual(22.0, state.attributes.get('current_temperature'))
|
||||
|
||||
|
||||
class TestThermostatHeatControl(unittest.TestCase):
|
||||
"""Test the Heat Control thermostat."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.units = METRIC_SYSTEM
|
||||
thermostat.setup(self.hass, {'thermostat': {
|
||||
'platform': 'heat_control',
|
||||
'name': 'test',
|
||||
'heater': ENT_SWITCH,
|
||||
'target_sensor': ENT_SENSOR
|
||||
}})
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup_defaults_to_unknown(self):
|
||||
"""Test the setting of defaults to unknown."""
|
||||
self.assertEqual('unknown', self.hass.states.get(ENTITY).state)
|
||||
|
||||
def test_default_setup_params(self):
|
||||
"""Test the setup with default parameters."""
|
||||
state = self.hass.states.get(ENTITY)
|
||||
self.assertEqual(7, state.attributes.get('min_temp'))
|
||||
self.assertEqual(35, state.attributes.get('max_temp'))
|
||||
self.assertEqual(None, state.attributes.get('temperature'))
|
||||
|
||||
def test_custom_setup_params(self):
|
||||
"""Test the setup with custom parameters."""
|
||||
thermostat.setup(self.hass, {'thermostat': {
|
||||
'platform': 'heat_control',
|
||||
'name': 'test',
|
||||
'heater': ENT_SWITCH,
|
||||
'target_sensor': ENT_SENSOR,
|
||||
'min_temp': MIN_TEMP,
|
||||
'max_temp': MAX_TEMP,
|
||||
'target_temp': TARGET_TEMP
|
||||
}})
|
||||
state = self.hass.states.get(ENTITY)
|
||||
self.assertEqual(MIN_TEMP, state.attributes.get('min_temp'))
|
||||
self.assertEqual(MAX_TEMP, state.attributes.get('max_temp'))
|
||||
self.assertEqual(TARGET_TEMP, state.attributes.get('temperature'))
|
||||
self.assertEqual(str(TARGET_TEMP), self.hass.states.get(ENTITY).state)
|
||||
|
||||
def test_set_target_temp(self):
|
||||
"""Test the setting of the target temperature."""
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual('30.0', self.hass.states.get(ENTITY).state)
|
||||
|
||||
def test_sensor_bad_unit(self):
|
||||
"""Test sensor that have bad unit."""
|
||||
state = self.hass.states.get(ENTITY)
|
||||
temp = state.attributes.get('current_temperature')
|
||||
unit = state.attributes.get('unit_of_measurement')
|
||||
|
||||
self._setup_sensor(22.0, unit='bad_unit')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get(ENTITY)
|
||||
self.assertEqual(unit, state.attributes.get('unit_of_measurement'))
|
||||
self.assertEqual(temp, state.attributes.get('current_temperature'))
|
||||
|
||||
def test_sensor_bad_value(self):
|
||||
"""Test sensor that have None as state."""
|
||||
state = self.hass.states.get(ENTITY)
|
||||
temp = state.attributes.get('current_temperature')
|
||||
unit = state.attributes.get('unit_of_measurement')
|
||||
|
||||
self._setup_sensor(None)
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get(ENTITY)
|
||||
self.assertEqual(unit, state.attributes.get('unit_of_measurement'))
|
||||
self.assertEqual(temp, state.attributes.get('current_temperature'))
|
||||
|
||||
def test_set_target_temp_heater_on(self):
|
||||
"""Test if target temperature turn heater on."""
|
||||
self._setup_switch(False)
|
||||
self._setup_sensor(25)
|
||||
self.hass.block_till_done()
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_set_target_temp_heater_off(self):
|
||||
"""Test if target temperature turn heater off."""
|
||||
self._setup_switch(True)
|
||||
self._setup_sensor(30)
|
||||
self.hass.block_till_done()
|
||||
thermostat.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_set_temp_change_heater_on(self):
|
||||
"""Test if temperature change turn heater on."""
|
||||
self._setup_switch(False)
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_temp_change_heater_off(self):
|
||||
"""Test if temperature change turn heater off."""
|
||||
self._setup_switch(True)
|
||||
thermostat.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def _setup_sensor(self, temp, unit=TEMP_CELSIUS):
|
||||
"""Setup the test sensor."""
|
||||
self.hass.states.set(ENT_SENSOR, temp, {
|
||||
ATTR_UNIT_OF_MEASUREMENT: unit
|
||||
})
|
||||
|
||||
def _setup_switch(self, is_on):
|
||||
"""Setup the test switch."""
|
||||
self.hass.states.set(ENT_SWITCH, STATE_ON if is_on else STATE_OFF)
|
||||
self.calls = []
|
||||
|
||||
def log_call(call):
|
||||
"""Log service calls."""
|
||||
self.calls.append(call)
|
||||
|
||||
self.hass.services.register('switch', SERVICE_TURN_ON, log_call)
|
||||
self.hass.services.register('switch', SERVICE_TURN_OFF, log_call)
|
||||
|
||||
|
||||
class TestThermostatHeatControlACMode(unittest.TestCase):
|
||||
"""Test the Heat Control thermostat."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.temperature_unit = TEMP_CELSIUS
|
||||
thermostat.setup(self.hass, {'thermostat': {
|
||||
'platform': 'heat_control',
|
||||
'name': 'test',
|
||||
'heater': ENT_SWITCH,
|
||||
'target_sensor': ENT_SENSOR,
|
||||
'ac_mode': True
|
||||
}})
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_set_target_temp_ac_off(self):
|
||||
"""Test if target temperature turn ac off."""
|
||||
self._setup_switch(True)
|
||||
self._setup_sensor(25)
|
||||
self.hass.block_till_done()
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_set_target_temp_ac_on(self):
|
||||
"""Test if target temperature turn ac on."""
|
||||
self._setup_switch(False)
|
||||
self._setup_sensor(30)
|
||||
self.hass.block_till_done()
|
||||
thermostat.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_set_temp_change_ac_off(self):
|
||||
"""Test if temperature change turn ac off."""
|
||||
self._setup_switch(True)
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_temp_change_ac_on(self):
|
||||
"""Test if temperature change turn ac on."""
|
||||
self._setup_switch(False)
|
||||
thermostat.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def _setup_sensor(self, temp, unit=TEMP_CELSIUS):
|
||||
"""Setup the test sensor."""
|
||||
self.hass.states.set(ENT_SENSOR, temp, {
|
||||
ATTR_UNIT_OF_MEASUREMENT: unit
|
||||
})
|
||||
|
||||
def _setup_switch(self, is_on):
|
||||
"""Setup the test switch."""
|
||||
self.hass.states.set(ENT_SWITCH, STATE_ON if is_on else STATE_OFF)
|
||||
self.calls = []
|
||||
|
||||
def log_call(call):
|
||||
"""Log service calls."""
|
||||
self.calls.append(call)
|
||||
|
||||
self.hass.services.register('switch', SERVICE_TURN_ON, log_call)
|
||||
self.hass.services.register('switch', SERVICE_TURN_OFF, log_call)
|
||||
|
||||
|
||||
class TestThermostatHeatControlACModeMinCycle(unittest.TestCase):
|
||||
"""Test the Heat Control thermostat."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.temperature_unit = TEMP_CELSIUS
|
||||
thermostat.setup(self.hass, {'thermostat': {
|
||||
'platform': 'heat_control',
|
||||
'name': 'test',
|
||||
'heater': ENT_SWITCH,
|
||||
'target_sensor': ENT_SENSOR,
|
||||
'ac_mode': True,
|
||||
'min_cycle_duration': datetime.timedelta(minutes=10)
|
||||
}})
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_temp_change_ac_trigger_on_not_long_enough(self):
|
||||
"""Test if temperature change turn ac on."""
|
||||
self._setup_switch(False)
|
||||
thermostat.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_temp_change_ac_trigger_on_long_enough(self):
|
||||
"""Test if temperature change turn ac on."""
|
||||
fake_changed = datetime.datetime(1918, 11, 11, 11, 11, 11,
|
||||
tzinfo=datetime.timezone.utc)
|
||||
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
|
||||
return_value=fake_changed):
|
||||
self._setup_switch(False)
|
||||
thermostat.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_temp_change_ac_trigger_off_not_long_enough(self):
|
||||
"""Test if temperature change turn ac on."""
|
||||
self._setup_switch(True)
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_temp_change_ac_trigger_off_long_enough(self):
|
||||
"""Test if temperature change turn ac on."""
|
||||
fake_changed = datetime.datetime(1918, 11, 11, 11, 11, 11,
|
||||
tzinfo=datetime.timezone.utc)
|
||||
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
|
||||
return_value=fake_changed):
|
||||
self._setup_switch(True)
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def _setup_sensor(self, temp, unit=TEMP_CELSIUS):
|
||||
"""Setup the test sensor."""
|
||||
self.hass.states.set(ENT_SENSOR, temp, {
|
||||
ATTR_UNIT_OF_MEASUREMENT: unit
|
||||
})
|
||||
|
||||
def _setup_switch(self, is_on):
|
||||
"""Setup the test switch."""
|
||||
self.hass.states.set(ENT_SWITCH, STATE_ON if is_on else STATE_OFF)
|
||||
self.calls = []
|
||||
|
||||
def log_call(call):
|
||||
"""Log service calls."""
|
||||
self.calls.append(call)
|
||||
|
||||
self.hass.services.register('switch', SERVICE_TURN_ON, log_call)
|
||||
self.hass.services.register('switch', SERVICE_TURN_OFF, log_call)
|
||||
|
||||
|
||||
class TestThermostatHeatControlMinCycle(unittest.TestCase):
|
||||
"""Test the Heat Control thermostat."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.temperature_unit = TEMP_CELSIUS
|
||||
thermostat.setup(self.hass, {'thermostat': {
|
||||
'platform': 'heat_control',
|
||||
'name': 'test',
|
||||
'heater': ENT_SWITCH,
|
||||
'target_sensor': ENT_SENSOR,
|
||||
'min_cycle_duration': datetime.timedelta(minutes=10)
|
||||
}})
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
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)
|
||||
thermostat.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
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)
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(0, len(self.calls))
|
||||
|
||||
def test_temp_change_heater_trigger_on_long_enough(self):
|
||||
"""Test if temperature change turn heater on after min cycle."""
|
||||
fake_changed = datetime.datetime(1918, 11, 11, 11, 11, 11,
|
||||
tzinfo=datetime.timezone.utc)
|
||||
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
|
||||
return_value=fake_changed):
|
||||
self._setup_switch(False)
|
||||
thermostat.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(25)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_ON, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_temp_change_heater_trigger_off_long_enough(self):
|
||||
"""Test if temperature change turn heater off after min cycle."""
|
||||
fake_changed = datetime.datetime(1918, 11, 11, 11, 11, 11,
|
||||
tzinfo=datetime.timezone.utc)
|
||||
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
|
||||
return_value=fake_changed):
|
||||
self._setup_switch(True)
|
||||
thermostat.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
self._setup_sensor(30)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(self.calls))
|
||||
call = self.calls[0]
|
||||
self.assertEqual('switch', call.domain)
|
||||
self.assertEqual(SERVICE_TURN_OFF, call.service)
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def _setup_sensor(self, temp, unit=TEMP_CELSIUS):
|
||||
"""Setup the test sensor."""
|
||||
self.hass.states.set(ENT_SENSOR, temp, {
|
||||
ATTR_UNIT_OF_MEASUREMENT: unit
|
||||
})
|
||||
|
||||
def _setup_switch(self, is_on):
|
||||
"""Setup the test switch."""
|
||||
self.hass.states.set(ENT_SWITCH, STATE_ON if is_on else STATE_OFF)
|
||||
self.calls = []
|
||||
|
||||
def log_call(call):
|
||||
"""Log service calls."""
|
||||
self.calls.append(call)
|
||||
|
||||
self.hass.services.register('switch', SERVICE_TURN_ON, log_call)
|
||||
self.hass.services.register('switch', SERVICE_TURN_OFF, log_call)
|
||||
@@ -1,391 +0,0 @@
|
||||
"""The test the Honeywell thermostat module."""
|
||||
import socket
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import somecomfort
|
||||
|
||||
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD,
|
||||
TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
import homeassistant.components.thermostat.honeywell as honeywell
|
||||
|
||||
|
||||
class TestHoneywell(unittest.TestCase):
|
||||
"""A test class for Honeywell themostats."""
|
||||
|
||||
@mock.patch('somecomfort.SomeComfort')
|
||||
@mock.patch('homeassistant.components.thermostat.'
|
||||
'honeywell.HoneywellUSThermostat')
|
||||
def test_setup_us(self, mock_ht, mock_sc):
|
||||
"""Test for the US setup."""
|
||||
config = {
|
||||
CONF_USERNAME: 'user',
|
||||
CONF_PASSWORD: 'pass',
|
||||
'region': 'us',
|
||||
}
|
||||
bad_pass_config = {
|
||||
CONF_USERNAME: 'user',
|
||||
'region': 'us',
|
||||
}
|
||||
bad_region_config = {
|
||||
CONF_USERNAME: 'user',
|
||||
CONF_PASSWORD: 'pass',
|
||||
'region': 'un',
|
||||
}
|
||||
hass = mock.MagicMock()
|
||||
add_devices = mock.MagicMock()
|
||||
|
||||
locations = [
|
||||
mock.MagicMock(),
|
||||
mock.MagicMock(),
|
||||
]
|
||||
devices_1 = [mock.MagicMock()]
|
||||
devices_2 = [mock.MagicMock(), mock.MagicMock]
|
||||
mock_sc.return_value.locations_by_id.values.return_value = \
|
||||
locations
|
||||
locations[0].devices_by_id.values.return_value = devices_1
|
||||
locations[1].devices_by_id.values.return_value = devices_2
|
||||
|
||||
result = honeywell.setup_platform(hass, bad_pass_config, add_devices)
|
||||
self.assertFalse(result)
|
||||
result = honeywell.setup_platform(hass, bad_region_config, add_devices)
|
||||
self.assertFalse(result)
|
||||
result = honeywell.setup_platform(hass, config, add_devices)
|
||||
self.assertTrue(result)
|
||||
self.assertEqual(mock_sc.call_count, 1)
|
||||
self.assertEqual(mock_sc.call_args, mock.call('user', 'pass'))
|
||||
mock_ht.assert_has_calls([
|
||||
mock.call(mock_sc.return_value, devices_1[0]),
|
||||
mock.call(mock_sc.return_value, devices_2[0]),
|
||||
mock.call(mock_sc.return_value, devices_2[1]),
|
||||
])
|
||||
|
||||
@mock.patch('somecomfort.SomeComfort')
|
||||
def test_setup_us_failures(self, mock_sc):
|
||||
"""Test the US setup."""
|
||||
hass = mock.MagicMock()
|
||||
add_devices = mock.MagicMock()
|
||||
config = {
|
||||
CONF_USERNAME: 'user',
|
||||
CONF_PASSWORD: 'pass',
|
||||
'region': 'us',
|
||||
}
|
||||
|
||||
mock_sc.side_effect = somecomfort.AuthError
|
||||
result = honeywell.setup_platform(hass, config, add_devices)
|
||||
self.assertFalse(result)
|
||||
self.assertFalse(add_devices.called)
|
||||
|
||||
mock_sc.side_effect = somecomfort.SomeComfortError
|
||||
result = honeywell.setup_platform(hass, config, add_devices)
|
||||
self.assertFalse(result)
|
||||
self.assertFalse(add_devices.called)
|
||||
|
||||
@mock.patch('somecomfort.SomeComfort')
|
||||
@mock.patch('homeassistant.components.thermostat.'
|
||||
'honeywell.HoneywellUSThermostat')
|
||||
def _test_us_filtered_devices(self, mock_ht, mock_sc, loc=None, dev=None):
|
||||
"""Test for US filtered thermostats."""
|
||||
config = {
|
||||
CONF_USERNAME: 'user',
|
||||
CONF_PASSWORD: 'pass',
|
||||
'region': 'us',
|
||||
'location': loc,
|
||||
'thermostat': dev,
|
||||
}
|
||||
locations = {
|
||||
1: mock.MagicMock(locationid=mock.sentinel.loc1,
|
||||
devices_by_id={
|
||||
11: mock.MagicMock(
|
||||
deviceid=mock.sentinel.loc1dev1),
|
||||
12: mock.MagicMock(
|
||||
deviceid=mock.sentinel.loc1dev2),
|
||||
}),
|
||||
2: mock.MagicMock(locationid=mock.sentinel.loc2,
|
||||
devices_by_id={
|
||||
21: mock.MagicMock(
|
||||
deviceid=mock.sentinel.loc2dev1),
|
||||
}),
|
||||
3: mock.MagicMock(locationid=mock.sentinel.loc3,
|
||||
devices_by_id={
|
||||
31: mock.MagicMock(
|
||||
deviceid=mock.sentinel.loc3dev1),
|
||||
}),
|
||||
}
|
||||
mock_sc.return_value = mock.MagicMock(locations_by_id=locations)
|
||||
hass = mock.MagicMock()
|
||||
add_devices = mock.MagicMock()
|
||||
self.assertEqual(True,
|
||||
honeywell.setup_platform(hass, config, add_devices))
|
||||
|
||||
return mock_ht.call_args_list, mock_sc
|
||||
|
||||
def test_us_filtered_thermostat_1(self):
|
||||
"""Test for US filtered thermostats."""
|
||||
result, client = self._test_us_filtered_devices(
|
||||
dev=mock.sentinel.loc1dev1)
|
||||
devices = [x[0][1].deviceid for x in result]
|
||||
self.assertEqual([mock.sentinel.loc1dev1], devices)
|
||||
|
||||
def test_us_filtered_thermostat_2(self):
|
||||
"""Test for US filtered location."""
|
||||
result, client = self._test_us_filtered_devices(
|
||||
dev=mock.sentinel.loc2dev1)
|
||||
devices = [x[0][1].deviceid for x in result]
|
||||
self.assertEqual([mock.sentinel.loc2dev1], devices)
|
||||
|
||||
def test_us_filtered_location_1(self):
|
||||
"""Test for US filtered locations."""
|
||||
result, client = self._test_us_filtered_devices(
|
||||
loc=mock.sentinel.loc1)
|
||||
devices = [x[0][1].deviceid for x in result]
|
||||
self.assertEqual([mock.sentinel.loc1dev1,
|
||||
mock.sentinel.loc1dev2], devices)
|
||||
|
||||
def test_us_filtered_location_2(self):
|
||||
"""Test for US filtered locations."""
|
||||
result, client = self._test_us_filtered_devices(
|
||||
loc=mock.sentinel.loc2)
|
||||
devices = [x[0][1].deviceid for x in result]
|
||||
self.assertEqual([mock.sentinel.loc2dev1], devices)
|
||||
|
||||
@mock.patch('evohomeclient.EvohomeClient')
|
||||
@mock.patch('homeassistant.components.thermostat.honeywell.'
|
||||
'RoundThermostat')
|
||||
def test_eu_setup_full_config(self, mock_round, mock_evo):
|
||||
"""Test the EU setup wwith complete configuration."""
|
||||
config = {
|
||||
CONF_USERNAME: 'user',
|
||||
CONF_PASSWORD: 'pass',
|
||||
honeywell.CONF_AWAY_TEMP: 20,
|
||||
'region': 'eu',
|
||||
}
|
||||
mock_evo.return_value.temperatures.return_value = [
|
||||
{'id': 'foo'}, {'id': 'bar'}]
|
||||
hass = mock.MagicMock()
|
||||
add_devices = mock.MagicMock()
|
||||
self.assertTrue(honeywell.setup_platform(hass, config, add_devices))
|
||||
self.assertEqual(mock_evo.call_count, 1)
|
||||
self.assertEqual(mock_evo.call_args, mock.call('user', 'pass'))
|
||||
self.assertEqual(mock_evo.return_value.temperatures.call_count, 1)
|
||||
self.assertEqual(
|
||||
mock_evo.return_value.temperatures.call_args,
|
||||
mock.call(force_refresh=True)
|
||||
)
|
||||
mock_round.assert_has_calls([
|
||||
mock.call(mock_evo.return_value, 'foo', True, 20),
|
||||
mock.call(mock_evo.return_value, 'bar', False, 20),
|
||||
])
|
||||
self.assertEqual(2, add_devices.call_count)
|
||||
|
||||
@mock.patch('evohomeclient.EvohomeClient')
|
||||
@mock.patch('homeassistant.components.thermostat.honeywell.'
|
||||
'RoundThermostat')
|
||||
def test_eu_setup_partial_config(self, mock_round, mock_evo):
|
||||
"""Test the EU setup with partial configuration."""
|
||||
config = {
|
||||
CONF_USERNAME: 'user',
|
||||
CONF_PASSWORD: 'pass',
|
||||
'region': 'eu',
|
||||
}
|
||||
mock_evo.return_value.temperatures.return_value = [
|
||||
{'id': 'foo'}, {'id': 'bar'}]
|
||||
hass = mock.MagicMock()
|
||||
add_devices = mock.MagicMock()
|
||||
self.assertTrue(honeywell.setup_platform(hass, config, add_devices))
|
||||
default = honeywell.DEFAULT_AWAY_TEMP
|
||||
mock_round.assert_has_calls([
|
||||
mock.call(mock_evo.return_value, 'foo', True, default),
|
||||
mock.call(mock_evo.return_value, 'bar', False, default),
|
||||
])
|
||||
|
||||
@mock.patch('evohomeclient.EvohomeClient')
|
||||
@mock.patch('homeassistant.components.thermostat.honeywell.'
|
||||
'RoundThermostat')
|
||||
def test_eu_setup_bad_temp(self, mock_round, mock_evo):
|
||||
"""Test the EU setup with invalid temperature."""
|
||||
config = {
|
||||
CONF_USERNAME: 'user',
|
||||
CONF_PASSWORD: 'pass',
|
||||
honeywell.CONF_AWAY_TEMP: 'ponies',
|
||||
'region': 'eu',
|
||||
}
|
||||
self.assertFalse(honeywell.setup_platform(None, config, None))
|
||||
|
||||
@mock.patch('evohomeclient.EvohomeClient')
|
||||
@mock.patch('homeassistant.components.thermostat.honeywell.'
|
||||
'RoundThermostat')
|
||||
def test_eu_setup_error(self, mock_round, mock_evo):
|
||||
"""Test the EU setup with errors."""
|
||||
config = {
|
||||
CONF_USERNAME: 'user',
|
||||
CONF_PASSWORD: 'pass',
|
||||
honeywell.CONF_AWAY_TEMP: 20,
|
||||
'region': 'eu',
|
||||
}
|
||||
mock_evo.return_value.temperatures.side_effect = socket.error
|
||||
add_devices = mock.MagicMock()
|
||||
hass = mock.MagicMock()
|
||||
self.assertFalse(honeywell.setup_platform(hass, config, add_devices))
|
||||
|
||||
|
||||
class TestHoneywellRound(unittest.TestCase):
|
||||
"""A test class for Honeywell Round thermostats."""
|
||||
|
||||
def setup_method(self, method):
|
||||
"""Test the setup method."""
|
||||
def fake_temperatures(force_refresh=None):
|
||||
"""Create fake temperatures."""
|
||||
temps = [
|
||||
{'id': '1', 'temp': 20, 'setpoint': 21,
|
||||
'thermostat': 'main', 'name': 'House'},
|
||||
{'id': '2', 'temp': 21, 'setpoint': 22,
|
||||
'thermostat': 'DOMESTIC_HOT_WATER'},
|
||||
]
|
||||
return temps
|
||||
|
||||
self.device = mock.MagicMock()
|
||||
self.device.temperatures.side_effect = fake_temperatures
|
||||
self.round1 = honeywell.RoundThermostat(self.device, '1',
|
||||
True, 16)
|
||||
self.round2 = honeywell.RoundThermostat(self.device, '2',
|
||||
False, 17)
|
||||
|
||||
def test_attributes(self):
|
||||
"""Test the attributes."""
|
||||
self.assertEqual('House', self.round1.name)
|
||||
self.assertEqual(TEMP_CELSIUS, self.round1.unit_of_measurement)
|
||||
self.assertEqual(20, self.round1.current_temperature)
|
||||
self.assertEqual(21, self.round1.target_temperature)
|
||||
self.assertFalse(self.round1.is_away_mode_on)
|
||||
|
||||
self.assertEqual('Hot Water', self.round2.name)
|
||||
self.assertEqual(TEMP_CELSIUS, self.round2.unit_of_measurement)
|
||||
self.assertEqual(21, self.round2.current_temperature)
|
||||
self.assertEqual(None, self.round2.target_temperature)
|
||||
self.assertFalse(self.round2.is_away_mode_on)
|
||||
|
||||
def test_away_mode(self):
|
||||
"""Test setting the away mode."""
|
||||
self.assertFalse(self.round1.is_away_mode_on)
|
||||
self.round1.turn_away_mode_on()
|
||||
self.assertTrue(self.round1.is_away_mode_on)
|
||||
self.assertEqual(self.device.set_temperature.call_count, 1)
|
||||
self.assertEqual(
|
||||
self.device.set_temperature.call_args, mock.call('House', 16)
|
||||
)
|
||||
|
||||
self.device.set_temperature.reset_mock()
|
||||
self.round1.turn_away_mode_off()
|
||||
self.assertFalse(self.round1.is_away_mode_on)
|
||||
self.assertEqual(self.device.cancel_temp_override.call_count, 1)
|
||||
self.assertEqual(
|
||||
self.device.cancel_temp_override.call_args, mock.call('House')
|
||||
)
|
||||
|
||||
def test_set_temperature(self):
|
||||
"""Test setting the temperature."""
|
||||
self.round1.set_temperature(25)
|
||||
self.assertEqual(self.device.set_temperature.call_count, 1)
|
||||
self.assertEqual(
|
||||
self.device.set_temperature.call_args, mock.call('House', 25)
|
||||
)
|
||||
|
||||
def test_set_hvac_mode(self: unittest.TestCase) -> None:
|
||||
"""Test setting the system operation."""
|
||||
self.round1.set_hvac_mode('cool')
|
||||
self.assertEqual('cool', self.round1.operation)
|
||||
self.assertEqual('cool', self.device.system_mode)
|
||||
|
||||
self.round1.set_hvac_mode('heat')
|
||||
self.assertEqual('heat', self.round1.operation)
|
||||
self.assertEqual('heat', self.device.system_mode)
|
||||
|
||||
|
||||
class TestHoneywellUS(unittest.TestCase):
|
||||
"""A test class for Honeywell US thermostats."""
|
||||
|
||||
def setup_method(self, method):
|
||||
"""Test the setup method."""
|
||||
self.client = mock.MagicMock()
|
||||
self.device = mock.MagicMock()
|
||||
self.honeywell = honeywell.HoneywellUSThermostat(
|
||||
self.client, self.device)
|
||||
|
||||
self.device.fan_running = True
|
||||
self.device.name = 'test'
|
||||
self.device.temperature_unit = 'F'
|
||||
self.device.current_temperature = 72
|
||||
self.device.setpoint_cool = 78
|
||||
self.device.setpoint_heat = 65
|
||||
self.device.system_mode = 'heat'
|
||||
self.device.fan_mode = 'auto'
|
||||
|
||||
def test_properties(self):
|
||||
"""Test the properties."""
|
||||
self.assertTrue(self.honeywell.is_fan_on)
|
||||
self.assertEqual('test', self.honeywell.name)
|
||||
self.assertEqual(72, self.honeywell.current_temperature)
|
||||
|
||||
def test_unit_of_measurement(self):
|
||||
"""Test the unit of measurement."""
|
||||
self.assertEqual(TEMP_FAHRENHEIT, self.honeywell.unit_of_measurement)
|
||||
self.device.temperature_unit = 'C'
|
||||
self.assertEqual(TEMP_CELSIUS, self.honeywell.unit_of_measurement)
|
||||
|
||||
def test_target_temp(self):
|
||||
"""Test the target temperature."""
|
||||
self.assertEqual(65, self.honeywell.target_temperature)
|
||||
self.device.system_mode = 'cool'
|
||||
self.assertEqual(78, self.honeywell.target_temperature)
|
||||
|
||||
def test_set_temp(self):
|
||||
"""Test setting the temperature."""
|
||||
self.honeywell.set_temperature(70)
|
||||
self.assertEqual(70, self.device.setpoint_heat)
|
||||
self.assertEqual(70, self.honeywell.target_temperature)
|
||||
|
||||
self.device.system_mode = 'cool'
|
||||
self.assertEqual(78, self.honeywell.target_temperature)
|
||||
self.honeywell.set_temperature(74)
|
||||
self.assertEqual(74, self.device.setpoint_cool)
|
||||
self.assertEqual(74, self.honeywell.target_temperature)
|
||||
|
||||
def test_set_hvac_mode(self: unittest.TestCase) -> None:
|
||||
"""Test setting the HVAC mode."""
|
||||
self.honeywell.set_hvac_mode('cool')
|
||||
self.assertEqual('cool', self.honeywell.operation)
|
||||
self.assertEqual('cool', self.device.system_mode)
|
||||
|
||||
self.honeywell.set_hvac_mode('heat')
|
||||
self.assertEqual('heat', self.honeywell.operation)
|
||||
self.assertEqual('heat', self.device.system_mode)
|
||||
|
||||
def test_set_temp_fail(self):
|
||||
"""Test if setting the temperature fails."""
|
||||
self.device.setpoint_heat = mock.MagicMock(
|
||||
side_effect=somecomfort.SomeComfortError)
|
||||
self.honeywell.set_temperature(123)
|
||||
|
||||
def test_attributes(self):
|
||||
"""Test the attributes."""
|
||||
expected = {
|
||||
'fan': 'running',
|
||||
'fanmode': 'auto',
|
||||
'system_mode': 'heat',
|
||||
}
|
||||
self.assertEqual(expected, self.honeywell.device_state_attributes)
|
||||
expected['fan'] = 'idle'
|
||||
self.device.fan_running = False
|
||||
self.assertEqual(expected, self.honeywell.device_state_attributes)
|
||||
|
||||
def test_with_no_fan(self):
|
||||
"""Test if there is on fan."""
|
||||
self.device.fan_running = False
|
||||
self.device.fan_mode = None
|
||||
expected = {
|
||||
'fan': 'idle',
|
||||
'fanmode': None,
|
||||
'system_mode': 'heat',
|
||||
}
|
||||
self.assertEqual(expected, self.honeywell.device_state_attributes)
|
||||
Reference in new issue
Block a user