Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -4,8 +4,11 @@ from homeassistant.components.switch import DOMAIN
|
||||
from homeassistant.const import STATE_ON, STATE_OFF, STATE_UNAVAILABLE
|
||||
from tests.common import mock_coro
|
||||
from .common import (
|
||||
async_init_zigpy_device, make_attribute, make_entity_id,
|
||||
async_test_device_join, async_enable_traffic
|
||||
async_init_zigpy_device,
|
||||
make_attribute,
|
||||
make_entity_id,
|
||||
async_test_device_join,
|
||||
async_enable_traffic,
|
||||
)
|
||||
|
||||
ON = 1
|
||||
@@ -19,11 +22,11 @@ async def test_switch(hass, config_entry, zha_gateway):
|
||||
|
||||
# create zigpy device
|
||||
zigpy_device = await async_init_zigpy_device(
|
||||
hass, [OnOff.cluster_id, Basic.cluster_id], [], None, zha_gateway)
|
||||
hass, [OnOff.cluster_id, Basic.cluster_id], [], None, zha_gateway
|
||||
)
|
||||
|
||||
# load up switch domain
|
||||
await hass.config_entries.async_forward_entry_setup(
|
||||
config_entry, DOMAIN)
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
cluster = zigpy_device.endpoints.get(1).on_off
|
||||
@@ -41,40 +44,41 @@ async def test_switch(hass, config_entry, zha_gateway):
|
||||
|
||||
# turn on at switch
|
||||
attr = make_attribute(0, 1)
|
||||
cluster.handle_message(False, 1, 0x0a, [[attr]])
|
||||
cluster.handle_message(False, 1, 0x0A, [[attr]])
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
|
||||
# turn off at switch
|
||||
attr.value.value = 0
|
||||
cluster.handle_message(False, 0, 0x0a, [[attr]])
|
||||
cluster.handle_message(False, 0, 0x0A, [[attr]])
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
|
||||
# turn on from HA
|
||||
with patch(
|
||||
'zigpy.zcl.Cluster.request',
|
||||
return_value=mock_coro([0x00, Status.SUCCESS])):
|
||||
"zigpy.zcl.Cluster.request", return_value=mock_coro([0x00, Status.SUCCESS])
|
||||
):
|
||||
# turn on via UI
|
||||
await hass.services.async_call(DOMAIN, 'turn_on', {
|
||||
'entity_id': entity_id
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "turn_on", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert len(cluster.request.mock_calls) == 1
|
||||
assert cluster.request.call_args == call(
|
||||
False, ON, (), expect_reply=True, manufacturer=None)
|
||||
False, ON, (), expect_reply=True, manufacturer=None
|
||||
)
|
||||
|
||||
# turn off from HA
|
||||
with patch(
|
||||
'zigpy.zcl.Cluster.request',
|
||||
return_value=mock_coro([0x01, Status.SUCCESS])):
|
||||
"zigpy.zcl.Cluster.request", return_value=mock_coro([0x01, Status.SUCCESS])
|
||||
):
|
||||
# turn off via UI
|
||||
await hass.services.async_call(DOMAIN, 'turn_off', {
|
||||
'entity_id': entity_id
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "turn_off", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert len(cluster.request.mock_calls) == 1
|
||||
assert cluster.request.call_args == call(
|
||||
False, OFF, (), expect_reply=True, manufacturer=None)
|
||||
False, OFF, (), expect_reply=True, manufacturer=None
|
||||
)
|
||||
|
||||
# test joining a new switch to the network and HA
|
||||
await async_test_device_join(
|
||||
hass, zha_gateway, OnOff.cluster_id, DOMAIN)
|
||||
await async_test_device_join(hass, zha_gateway, OnOff.cluster_id, DOMAIN)
|
||||
Reference in new issue
Block a user