/
remote_value_1count_test.py
86 lines (76 loc) · 3.02 KB
/
remote_value_1count_test.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Unit test for RemoteValue1Count objects."""
import asyncio
import unittest
from xknx import XKNX
from xknx.dpt import DPTArray, DPTBinary
from xknx.exceptions import CouldNotParseTelegram
from xknx.remote_value import RemoteValue1Count
from xknx.telegram import GroupAddress, Telegram
class TestRemoteValue1Count(unittest.TestCase):
"""Test class for RemoteValue1Count objects."""
def setUp(self):
"""Set up test class."""
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def tearDown(self):
"""Tear down test class."""
self.loop.close()
def test_to_knx(self):
"""Test to_knx function with normal operation."""
xknx = XKNX()
remote_value = RemoteValue1Count(xknx)
self.assertEqual(remote_value.to_knx(100), DPTArray((0x64,)))
def test_from_knx(self):
"""Test from_knx function with normal operation."""
xknx = XKNX()
remote_value = RemoteValue1Count(xknx)
self.assertEqual(remote_value.from_knx(DPTArray((0x64,))), 100)
def test_set(self):
"""Test setting value."""
xknx = XKNX()
remote_value = RemoteValue1Count(xknx, group_address=GroupAddress("1/2/3"))
self.loop.run_until_complete(remote_value.set(100))
self.assertEqual(xknx.telegrams.qsize(), 1)
telegram = xknx.telegrams.get_nowait()
self.assertEqual(
telegram, Telegram(GroupAddress("1/2/3"), payload=DPTArray((0x64,)))
)
self.loop.run_until_complete(
remote_value.set(
101,
)
)
self.assertEqual(xknx.telegrams.qsize(), 1)
telegram = xknx.telegrams.get_nowait()
self.assertEqual(
telegram, Telegram(GroupAddress("1/2/3"), payload=DPTArray((0x65,)))
)
def test_process(self):
"""Test process telegram."""
xknx = XKNX()
remote_value = RemoteValue1Count(xknx, group_address=GroupAddress("1/2/3"))
telegram = Telegram(
destination_address=GroupAddress("1/2/3"), payload=DPTArray((0x64,))
)
self.loop.run_until_complete(remote_value.process(telegram))
self.assertEqual(remote_value.value, 100)
def test_to_process_error(self):
"""Test process errornous telegram."""
xknx = XKNX()
remote_value = RemoteValue1Count(xknx, group_address=GroupAddress("1/2/3"))
with self.assertRaises(CouldNotParseTelegram):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"), payload=DPTBinary(1)
)
self.loop.run_until_complete(remote_value.process(telegram))
with self.assertRaises(CouldNotParseTelegram):
telegram = Telegram(
destination_address=GroupAddress("1/2/3"),
payload=DPTArray(
(
0x64,
0x65,
)
),
)
self.loop.run_until_complete(remote_value.process(telegram))