-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rtl433_to_mqtt.py
More file actions
42 lines (34 loc) · 2.16 KB
/
Copy pathtest_rtl433_to_mqtt.py
File metadata and controls
42 lines (34 loc) · 2.16 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
#!/usr/bin/env python3
# coding: utf-8
import unittest
from rtl433_to_mqtt.rtl433_to_mqtt import process_line
class TestProcessing(unittest.TestCase):
def test_process_thermometer(self):
line = ('{"time" : "2021-10-12 20:22:44", "model" : "Acurite-606TX", "id" : 14, "battery_ok" : 1, '
'"temperature_C" : 14.600, "mic" : "CHECKSUM"}')
topic, payload = process_line(line)
self.assertEqual(topic, 'home/sensor/outsite/thermometer')
self.assertEqual(payload, '{"time":"2021-10-12 20:22:44","battery_ok":1,"temperature_C":14.6}')
def test_process_detector_garage(self):
line = ('{"time" : "2021-10-12 20:25:32", "model" : "Visonic-Powercode", "id" : "6400bd", "tamper" : 0, '
'"alarm" : 1, "battery_ok" : 1, "else" : 0, "restore" : 0, "supervised" : 1, "spidernet" : 0, '
'"repeater" : 0, "mic" : "LRC"}')
topic, payload = process_line(line)
self.assertEqual(topic, 'home/sensor/garage/detector')
self.assertEqual(payload, '{"time":"2021-10-12 20:25:32","battery_ok":1,"alarm":1}')
def test_process_detector_entrance(self):
line = ('{"time" : "2021-10-12 20:25:32", "model" : "Visonic-Powercode", "id" : "64f8ab", "tamper" : 0, '
'"alarm" : 1, "battery_ok" : 1, "else" : 0, "restore" : 0, "supervised" : 1, "spidernet" : 0, '
'"repeater" : 0, "mic" : "LRC"}')
topic, payload = process_line(line)
self.assertEqual(topic, 'home/sensor/entrance/detector')
self.assertEqual(payload, '{"time":"2021-10-12 20:25:32","battery_ok":1,"alarm":1}')
def test_process_detector_livingroom(self):
line = ('{"time" : "2021-10-12 20:25:32", "model" : "Visonic-Powercode", "id" : "a40706", "tamper" : 0, '
'"alarm" : 1, "battery_ok" : 1, "else" : 0, "restore" : 0, "supervised" : 1, "spidernet" : 0, '
'"repeater" : 0, "mic" : "LRC"}')
topic, payload = process_line(line)
self.assertEqual(topic, 'home/sensor/living-room/detector')
self.assertEqual(payload, '{"time":"2021-10-12 20:25:32","battery_ok":1,"alarm":1}')
if __name__ == '__main__':
unittest.main()