mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add events to Dynalite platform (#38583)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
"""Test Dynalite bridge."""
|
||||
|
||||
|
||||
from dynalite_devices_lib.dynalite_devices import (
|
||||
CONF_AREA as dyn_CONF_AREA,
|
||||
CONF_PRESET as dyn_CONF_PRESET,
|
||||
NOTIFICATION_PACKET,
|
||||
NOTIFICATION_PRESET,
|
||||
DynaliteNotification,
|
||||
)
|
||||
|
||||
from homeassistant.components import dynalite
|
||||
from homeassistant.components.dynalite.const import (
|
||||
ATTR_AREA,
|
||||
ATTR_HOST,
|
||||
ATTR_PACKET,
|
||||
ATTR_PRESET,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from tests.async_mock import AsyncMock, Mock, patch
|
||||
@@ -95,3 +110,41 @@ async def test_register_then_add_devices(hass):
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("light.name")
|
||||
assert hass.states.get("switch.name2")
|
||||
|
||||
|
||||
async def test_notifications(hass):
|
||||
"""Test that update works."""
|
||||
host = "1.2.3.4"
|
||||
entry = MockConfigEntry(domain=dynalite.DOMAIN, data={dynalite.CONF_HOST: host})
|
||||
entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.dynalite.bridge.DynaliteDevices"
|
||||
) as mock_dyn_dev:
|
||||
mock_dyn_dev().async_setup = AsyncMock(return_value=True)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
notification_func = mock_dyn_dev.mock_calls[1][2]["notification_func"]
|
||||
event_listener1 = Mock()
|
||||
hass.bus.async_listen("dynalite_packet", event_listener1)
|
||||
packet = [5, 4, 3, 2]
|
||||
notification_func(
|
||||
DynaliteNotification(NOTIFICATION_PACKET, {NOTIFICATION_PACKET: packet})
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
event_listener1.assert_called_once()
|
||||
my_event = event_listener1.mock_calls[0][1][0]
|
||||
assert my_event.data[ATTR_HOST] == host
|
||||
assert my_event.data[ATTR_PACKET] == packet
|
||||
event_listener2 = Mock()
|
||||
hass.bus.async_listen("dynalite_preset", event_listener2)
|
||||
notification_func(
|
||||
DynaliteNotification(
|
||||
NOTIFICATION_PRESET, {dyn_CONF_AREA: 7, dyn_CONF_PRESET: 2}
|
||||
)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
event_listener2.assert_called_once()
|
||||
my_event = event_listener2.mock_calls[0][1][0]
|
||||
assert my_event.data[ATTR_HOST] == host
|
||||
assert my_event.data[ATTR_AREA] == 7
|
||||
assert my_event.data[ATTR_PRESET] == 2
|
||||
|
||||
Reference in New Issue
Block a user