Combine garage_door and rollershutter to cover (#2891)
* First draft for cover component * Efficiency from @martinhjelmare * migrate demo * migrate demo test * migrate command_line rollershutter * migrate command_line test * migrate rpi_gpio garage_door * make some abstract methods optional * migrate homematic * migrate scsgate * migrate rfxtrx and test * migrate zwave * migrate wink * migrate mqtt rollershutter and test * requirements * coverage * Update mqtt with garage door * Naming and cleanup * update test_demo.py * update demo and core * Add deprecated warning to rollershutter and garage_door * Naming again * Update * String constants * Make sure set_position works properly in demo too * Make sure position is not set if not available. * Naming, and is_closed * Update zwave.py * requirements * Update test_rfxtrx.py * fix mqtt * requirements * fix wink version * Fixed demo test * naming
This commit is contained in:
1 parent
a43ea81d8e
commit
cf832499cd
21 files changed
+2006
-11
No files matched your search
@@ -0,0 +1,84 @@
|
||||
"""The tests the cover command line platform."""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import homeassistant.core as ha
|
||||
import homeassistant.components.cover as cover
|
||||
from homeassistant.components.cover import (
|
||||
command_line as cmd_rs)
|
||||
|
||||
|
||||
class TestCommandCover(unittest.TestCase):
|
||||
"""Test the cover command line platform."""
|
||||
|
||||
def setup_method(self, method):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = ha.HomeAssistant()
|
||||
self.hass.config.latitude = 32.87336
|
||||
self.hass.config.longitude = 117.22743
|
||||
self.rs = cmd_rs.CommandCover(self.hass, 'foo',
|
||||
'cmd_open', 'cmd_close',
|
||||
'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)
|
||||
mock_run.assert_called_once_with('runme', shell=True)
|
||||
|
||||
def test_state_value(self):
|
||||
"""Test with state value."""
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, 'cover_status')
|
||||
test_cover = {
|
||||
'statecmd': 'cat {}'.format(path),
|
||||
'opencmd': 'echo 1 > {}'.format(path),
|
||||
'closecmd': 'echo 1 > {}'.format(path),
|
||||
'stopcmd': 'echo 0 > {}'.format(path),
|
||||
'value_template': '{{ value }}'
|
||||
}
|
||||
self.assertTrue(cover.setup(self.hass, {
|
||||
'cover': {
|
||||
'platform': 'command_line',
|
||||
'covers': {
|
||||
'test': test_cover
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual('unknown', state.state)
|
||||
|
||||
cover.open_cover(self.hass, 'cover.test')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual('open', state.state)
|
||||
|
||||
cover.close_cover(self.hass, 'cover.test')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual('open', state.state)
|
||||
|
||||
cover.stop_cover(self.hass, 'cover.test')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual('closed', state.state)
|
||||
@@ -0,0 +1,138 @@
|
||||
"""The tests for the Demo cover platform."""
|
||||
import unittest
|
||||
from datetime import timedelta
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from homeassistant.components import cover
|
||||
from tests.common import get_test_home_assistant, fire_time_changed
|
||||
|
||||
ENTITY_COVER = 'cover.living_room_window'
|
||||
|
||||
|
||||
class TestCoverDemo(unittest.TestCase):
|
||||
"""Test the Demo cover."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.assertTrue(cover.setup(self.hass, {'cover': {
|
||||
'platform': 'demo',
|
||||
}}))
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_close_cover(self):
|
||||
"""Test closing the cover."""
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(70, state.attributes.get('current_position'))
|
||||
cover.close_cover(self.hass, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
for _ in range(7):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(0, state.attributes.get('current_position'))
|
||||
|
||||
def test_open_cover(self):
|
||||
"""Test opening the cover."""
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(70, state.attributes.get('current_position'))
|
||||
cover.open_cover(self.hass, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
for _ in range(7):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(100, state.attributes.get('current_position'))
|
||||
|
||||
def test_set_cover_position(self):
|
||||
"""Test moving the cover to a specific position."""
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(70, state.attributes.get('current_position'))
|
||||
cover.set_cover_position(self.hass, 10, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
for _ in range(6):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(10, state.attributes.get('current_position'))
|
||||
|
||||
def test_stop_cover(self):
|
||||
"""Test stopping the cover."""
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(70, state.attributes.get('current_position'))
|
||||
cover.open_cover(self.hass, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
cover.stop_cover(self.hass, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
fire_time_changed(self.hass, future)
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(80, state.attributes.get('current_position'))
|
||||
|
||||
def test_close_cover_tilt(self):
|
||||
"""Test closing the cover tilt."""
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(50, state.attributes.get('current_tilt_position'))
|
||||
cover.close_cover_tilt(self.hass, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
for _ in range(7):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(0, state.attributes.get('current_tilt_position'))
|
||||
|
||||
def test_open_cover_tilt(self):
|
||||
"""Test opening the cover tilt."""
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(50, state.attributes.get('current_tilt_position'))
|
||||
cover.open_cover_tilt(self.hass, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
for _ in range(7):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(100, state.attributes.get('current_tilt_position'))
|
||||
|
||||
def test_set_cover_tilt_position(self):
|
||||
"""Test moving the cover til to a specific position."""
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(50, state.attributes.get('current_tilt_position'))
|
||||
cover.set_cover_tilt_position(self.hass, 90, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
for _ in range(7):
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(90, state.attributes.get('current_tilt_position'))
|
||||
|
||||
def test_stop_cover_tilt(self):
|
||||
"""Test stopping the cover tilt."""
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(50, state.attributes.get('current_tilt_position'))
|
||||
cover.close_cover_tilt(self.hass, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
future = dt_util.utcnow() + timedelta(seconds=1)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
cover.stop_cover_tilt(self.hass, ENTITY_COVER)
|
||||
self.hass.pool.block_till_done()
|
||||
fire_time_changed(self.hass, future)
|
||||
state = self.hass.states.get(ENTITY_COVER)
|
||||
self.assertEqual(40, state.attributes.get('current_tilt_position'))
|
||||
@@ -0,0 +1,174 @@
|
||||
"""The tests for the MQTT cover platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
from homeassistant.const import STATE_OPEN, STATE_CLOSED, STATE_UNKNOWN
|
||||
import homeassistant.components.cover as cover
|
||||
from tests.common import mock_mqtt_component, fire_mqtt_message
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestCoverMQTT(unittest.TestCase):
|
||||
"""Test the MQTT cover."""
|
||||
|
||||
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, cover.DOMAIN, {
|
||||
cover.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'qos': 0,
|
||||
'payload_open': 'OPEN',
|
||||
'payload_close': 'CLOSE',
|
||||
'payload_stop': 'STOP'
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '0')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_CLOSED, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '50')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_OPEN, state.state)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '100')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_OPEN, state.state)
|
||||
|
||||
def test_send_open_cover_command(self):
|
||||
"""Test the sending of open_cover."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, cover.DOMAIN, {
|
||||
cover.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'qos': 2
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
cover.open_cover(self.hass, 'cover.test')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(('command-topic', 'OPEN', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
def test_send_close_cover_command(self):
|
||||
"""Test the sending of close_cover."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, cover.DOMAIN, {
|
||||
cover.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'qos': 2
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
cover.close_cover(self.hass, 'cover.test')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(('command-topic', 'CLOSE', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
def test_send_stop__cover_command(self):
|
||||
"""Test the sending of stop_cover."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, cover.DOMAIN, {
|
||||
cover.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'qos': 2
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
cover.stop_cover(self.hass, 'cover.test')
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertEqual(('command-topic', 'STOP', 2, False),
|
||||
self.mock_publish.mock_calls[-1][1])
|
||||
state = self.hass.states.get('cover.test')
|
||||
self.assertEqual(STATE_UNKNOWN, state.state)
|
||||
|
||||
def test_state_attributes_current_cover_position(self):
|
||||
"""Test the current cover position."""
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, cover.DOMAIN, {
|
||||
cover.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'state-topic',
|
||||
'command_topic': 'command-topic',
|
||||
'payload_open': 'OPEN',
|
||||
'payload_close': 'CLOSE',
|
||||
'payload_stop': 'STOP'
|
||||
}
|
||||
})
|
||||
|
||||
state_attributes_dict = self.hass.states.get(
|
||||
'cover.test').attributes
|
||||
self.assertTrue('current_position' in state_attributes_dict)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '0')
|
||||
self.hass.pool.block_till_done()
|
||||
current_cover_position = self.hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
self.assertEqual(0, current_cover_position)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '50')
|
||||
self.hass.pool.block_till_done()
|
||||
current_cover_position = self.hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
self.assertEqual(50, current_cover_position)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', '101')
|
||||
self.hass.pool.block_till_done()
|
||||
current_cover_position = self.hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
self.assertEqual(50, current_cover_position)
|
||||
|
||||
fire_mqtt_message(self.hass, 'state-topic', 'non-numeric')
|
||||
self.hass.pool.block_till_done()
|
||||
current_cover_position = self.hass.states.get(
|
||||
'cover.test').attributes['current_position']
|
||||
self.assertEqual(50, current_cover_position)
|
||||
@@ -0,0 +1,216 @@
|
||||
"""The tests for the Rfxtrx cover platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
from homeassistant.components import rfxtrx as rfxtrx_core
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestCoverRfxtrx(unittest.TestCase):
|
||||
"""Test the Rfxtrx cover 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, 'cover', {
|
||||
'cover': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'0b1100cd0213c7f210010f51': {
|
||||
'name': 'Test',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
|
||||
def test_invalid_config_capital_letters(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'2FF7f216': {
|
||||
'name': 'Test',
|
||||
'packetid': '0b1100cd0213c7f210010f51',
|
||||
'signal_repetitions': 3}
|
||||
}}}))
|
||||
|
||||
def test_invalid_config_extra_key(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'invalid_key': 'afda',
|
||||
'devices':
|
||||
{'213c7f216': {
|
||||
'name': 'Test',
|
||||
'packetid': '0b1100cd0213c7f210010f51',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
|
||||
def test_invalid_config_capital_packetid(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'213c7f216': {
|
||||
'name': 'Test',
|
||||
'packetid': 'AA1100cd0213c7f210010f51',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
|
||||
def test_invalid_config_missing_packetid(self):
|
||||
"""Test configuration."""
|
||||
self.assertFalse(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
'devices':
|
||||
{'213c7f216': {
|
||||
'name': 'Test',
|
||||
rfxtrx_core.ATTR_FIREEVENT: True}
|
||||
}}}))
|
||||
|
||||
def test_default_config(self):
|
||||
"""Test with 0 cover."""
|
||||
self.assertTrue(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'platform': 'rfxtrx',
|
||||
'devices': {}}}))
|
||||
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
||||
|
||||
def test_one_cover(self):
|
||||
"""Test with 1 cover."""
|
||||
self.assertTrue(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'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.open_cover()
|
||||
entity.close_cover()
|
||||
entity.stop_cover()
|
||||
|
||||
def test_several_covers(self):
|
||||
"""Test with 3 covers."""
|
||||
self.assertTrue(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'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_covers(self):
|
||||
"""Test with discovery of covers."""
|
||||
self.assertTrue(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'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_cover_noautoadd(self):
|
||||
"""Test with discovery of cover when auto add is False."""
|
||||
self.assertTrue(_setup_component(self.hass, 'cover', {
|
||||
'cover': {'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))
|
||||
Reference in new issue
Block a user