hass-core/tests/components/dynalite/test_light.py
Ziv 4467409e5c
Dynalite Integration (#27841)
* Initial commit

* ran hassfest and gen_requirements_all scripts

* fixes per request from Paulus Schoutsen

* ran gen_requirements_all

* updated library version - removed some debug leftover

* get_requirements again...

* added documentation URL

* ran isort

* changed storage in hass.data[DOMAIN] to use entry_id instead of host

* adopted unit tests to latest fix

* Update const.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-02-10 13:16:04 -08:00

44 lines
1.7 KiB
Python
Executable file

"""Test Dynalite light."""
from unittest.mock import Mock, call, patch
from homeassistant.components.dynalite import DOMAIN
from homeassistant.components.dynalite.light import DynaliteLight, async_setup_entry
from tests.common import mock_coro
async def test_light_setup():
"""Test a successful setup."""
hass = Mock()
entry = Mock()
async_add = Mock()
bridge = Mock()
hass.data = {DOMAIN: {entry.entry_id: bridge}}
await async_setup_entry(hass, entry, async_add)
bridge.register_add_entities.assert_called_once()
assert bridge.register_add_entities.mock_calls[0] == call(async_add)
async def test_light():
"""Test the light entity."""
device = Mock()
device.async_turn_on = Mock(return_value=mock_coro(Mock()))
device.async_turn_off = Mock(return_value=mock_coro(Mock()))
bridge = Mock()
dyn_light = DynaliteLight(device, bridge)
assert dyn_light.name is device.name
assert dyn_light.unique_id is device.unique_id
assert dyn_light.available is device.available
assert dyn_light.hidden is device.hidden
await dyn_light.async_update() # does nothing
assert dyn_light.device_info is device.device_info
assert dyn_light.brightness is device.brightness
assert dyn_light.is_on is device.is_on
await dyn_light.async_turn_on(aaa="bbb")
assert device.async_turn_on.mock_calls[0] == call(aaa="bbb")
await dyn_light.async_turn_off(ccc="ddd")
assert device.async_turn_off.mock_calls[0] == call(ccc="ddd")
with patch.object(dyn_light, "hass"):
with patch.object(dyn_light, "schedule_update_ha_state") as update_ha:
dyn_light.try_schedule_ha()
update_ha.assert_called_once()