deCONZ - create deconz_events through sensor platform (#26592)

* Move event creation into sensor platform where it belongs
* Fixed the weird failing test observed during device automation PR
This commit is contained in:
Robert Svensson 2019-09-14 00:16:37 +02:00 committed by GitHub
parent 357f2421c8
commit fb1acfccc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 90 deletions

View file

@ -0,0 +1,60 @@
"""Test deCONZ remote events."""
from unittest.mock import Mock
from homeassistant.components.deconz.deconz_event import CONF_DECONZ_EVENT, DeconzEvent
from homeassistant.core import callback
async def test_create_event(hass):
"""Successfully created a deCONZ event."""
mock_remote = Mock()
mock_remote.name = "Name"
mock_gateway = Mock()
mock_gateway.hass = hass
event = DeconzEvent(mock_remote, mock_gateway)
assert event.event_id == "name"
async def test_update_event(hass):
"""Successfully update a deCONZ event."""
mock_remote = Mock()
mock_remote.name = "Name"
mock_gateway = Mock()
mock_gateway.hass = hass
event = DeconzEvent(mock_remote, mock_gateway)
mock_remote.changed_keys = {"state": True}
calls = []
@callback
def listener(event):
"""Mock listener."""
calls.append(event)
unsub = hass.bus.async_listen(CONF_DECONZ_EVENT, listener)
event.async_update_callback()
await hass.async_block_till_done()
assert len(calls) == 1
unsub()
async def test_remove_event(hass):
"""Successfully update a deCONZ event."""
mock_remote = Mock()
mock_remote.name = "Name"
mock_gateway = Mock()
mock_gateway.hass = hass
event = DeconzEvent(mock_remote, mock_gateway)
event.async_will_remove_from_hass()
assert event._device is None

View file

@ -126,24 +126,6 @@ async def test_add_device(hass):
assert len(mock_dispatch_send.mock_calls[0]) == 3
@pytest.mark.skip(reason="fails for unkown reason, will refactor in a separate PR")
async def test_add_remote(hass):
"""Successful add remote."""
entry = Mock()
entry.data = ENTRY_CONFIG
remote = Mock()
remote.name = "name"
remote.type = "ZHASwitch"
remote.register_async_callback = Mock()
deconz_gateway = gateway.DeconzGateway(hass, entry)
deconz_gateway.async_add_remote([remote])
await hass.async_block_till_done()
assert len(deconz_gateway.events) == 1
async def test_shutdown():
"""Successful shutdown."""
hass = Mock()
@ -218,53 +200,3 @@ async def test_get_gateway_fails_cannot_connect(hass):
side_effect=pydeconz.errors.RequestError,
), pytest.raises(errors.CannotConnect):
assert await gateway.get_gateway(hass, ENTRY_CONFIG, Mock(), Mock()) is False
@pytest.mark.skip(reason="fails for unkown reason, will refactor in a separate PR")
async def test_create_event(hass):
"""Successfully created a deCONZ event."""
mock_remote = Mock()
mock_remote.name = "Name"
mock_gateway = Mock()
mock_gateway.hass = hass
event = gateway.DeconzEvent(mock_remote, mock_gateway)
await hass.async_block_till_done()
assert event.event_id == "name"
@pytest.mark.skip(reason="fails for unkown reason, will refactor in a separate PR")
async def test_update_event(hass):
"""Successfully update a deCONZ event."""
hass.bus.async_fire = Mock()
mock_remote = Mock()
mock_remote.name = "Name"
mock_gateway = Mock()
mock_gateway.hass = hass
event = gateway.DeconzEvent(mock_remote, mock_gateway)
await hass.async_block_till_done()
mock_remote.changed_keys = {"state": True}
event.async_update_callback()
assert len(hass.bus.async_fire.mock_calls) == 1
@pytest.mark.skip(reason="fails for unkown reason, will refactor in a separate PR")
async def test_remove_event(hass):
"""Successfully update a deCONZ event."""
mock_remote = Mock()
mock_remote.name = "Name"
mock_gateway = Mock()
mock_gateway.hass = hass
event = gateway.DeconzEvent(mock_remote, mock_gateway)
await hass.async_block_till_done()
event.async_will_remove_from_hass()
assert event._device is None