-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_light.py
More file actions
50 lines (33 loc) · 1.04 KB
/
test_light.py
File metadata and controls
50 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pytest
from mock import patch, Mock
import json
from xcomfort.bridge import Bridge
from xcomfort.devices import (Light, LightState)
from xcomfort.constants import Messages
class MockBridge(Bridge):
def __init__(self):
self._sent_message = None
async def send_message(self, message_type, message):
self._sent_message = message
@pytest.mark.asyncio
async def test_light_switch_on():
bridge = MockBridge()
device = Light(bridge, 1, "", True)
await device.switch(True)
assert bridge._sent_message == {"deviceId": 1, "switch": True}
def test_lightstate_switch_on():
device = Light(None, 1, "", True)
payload = {
"switch": True,
"dimmvalue": 50
}
device.handle_state(payload)
assert device.state.value.switch == True
assert device.state.value.dimmvalue == 50
def test_lightstate_switch_on_when_not_dimmable():
device = Light(None, 1, "", False)
payload = {
"switch": True
}
device.handle_state(payload)
assert device.state.value.switch == True