mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Align switch group handling with light. (#7577)
This commit is contained in:
committed by
Paulus Schoutsen
parent
2b70b1881a
commit
d472d81538
@@ -86,15 +86,144 @@ def test_default_setup(hass, monkeypatch):
|
||||
# test changing state from HA propagates to Rflink
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: 'switch.test'}))
|
||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
||||
yield from hass.async_block_till_done()
|
||||
assert hass.states.get('switch.test').state == 'off'
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
assert protocol.send_command_ack.call_args_list[0][0][0] == 'protocol_0_0'
|
||||
assert protocol.send_command_ack.call_args_list[0][0][1] == 'off'
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: 'switch.test'}))
|
||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
||||
yield from hass.async_block_till_done()
|
||||
assert hass.states.get('switch.test').state == 'on'
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
assert protocol.send_command_ack.call_args_list[1][0][1] == 'on'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_group_alias(hass, monkeypatch):
|
||||
"""Group aliases should only respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
'rflink': {
|
||||
'port': '/dev/ttyABC0',
|
||||
},
|
||||
DOMAIN: {
|
||||
'platform': 'rflink',
|
||||
'devices': {
|
||||
'protocol_0_0': {
|
||||
'name': 'test',
|
||||
'group_aliasses': ['test_group_0_0'],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
event_callback, _, _, _ = yield from mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
||||
# test sending group command to group alias
|
||||
event_callback({
|
||||
'id': 'test_group_0_0',
|
||||
'command': 'allon',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
|
||||
# test sending group command to group alias
|
||||
event_callback({
|
||||
'id': 'test_group_0_0',
|
||||
'command': 'off',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_nogroup_alias(hass, monkeypatch):
|
||||
"""Non group aliases should not respond to group commands."""
|
||||
config = {
|
||||
'rflink': {
|
||||
'port': '/dev/ttyABC0',
|
||||
},
|
||||
DOMAIN: {
|
||||
'platform': 'rflink',
|
||||
'devices': {
|
||||
'protocol_0_0': {
|
||||
'name': 'test',
|
||||
'nogroup_aliasses': ['test_nogroup_0_0'],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
event_callback, _, _, _ = yield from mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
||||
# test sending group command to nogroup alias
|
||||
event_callback({
|
||||
'id': 'test_nogroup_0_0',
|
||||
'command': 'allon',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
# should not affect state
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
||||
# test sending group command to nogroup alias
|
||||
event_callback({
|
||||
'id': 'test_nogroup_0_0',
|
||||
'command': 'on',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
# should affect state
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_nogroup_device_id(hass, monkeypatch):
|
||||
"""Device id that do not respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
'rflink': {
|
||||
'port': '/dev/ttyABC0',
|
||||
},
|
||||
DOMAIN: {
|
||||
'platform': 'rflink',
|
||||
'devices': {
|
||||
'test_nogroup_0_0': {
|
||||
'name': 'test',
|
||||
'group': False,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
event_callback, _, _, _ = yield from mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
||||
# test sending group command to nogroup
|
||||
event_callback({
|
||||
'id': 'test_nogroup_0_0',
|
||||
'command': 'allon',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
# should not affect state
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
||||
# test sending group command to nogroup
|
||||
event_callback({
|
||||
'id': 'test_nogroup_0_0',
|
||||
'command': 'on',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
# should affect state
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
|
||||
Reference in New Issue
Block a user