diff --git a/fixtures.py b/fixtures.py new file mode 100644 index 0000000..aa51400 --- /dev/null +++ b/fixtures.py @@ -0,0 +1,19 @@ +import time + +from models import SensorData + + +cur_time = int(time.time()) +device_mac = '9B-89-A9-ED-F2-FB' +device_name = 'My RaspberryPi 4B' +sensors = [ + SensorData('owner', 'darkcat09'), + SensorData('lat', 56), # just random data + SensorData('lon', 49), + SensorData('alt', 400), + SensorData('t1', 12.42, cur_time), # let it be temp outdoors + SensorData('t2', 22.50, cur_time, 'Temp in living room'), + SensorData('t3', 60.11, None, 'Poor Raspberry CPU...'), + SensorData('p1', 752.33, None, 'Barometer'), + SensorData('p2', 751.42), +] diff --git a/main.py b/main.py new file mode 100644 index 0000000..c1d679f --- /dev/null +++ b/main.py @@ -0,0 +1,30 @@ +import socket +import urllib + +from unittest import TestCase + +from fixtures import device_mac, device_name, sensors + + +TCP_ADDR = ('127.0.0.1', 8283) +UDP_ADDR = ('127.0.0.1', 8283) +HTTP_URL = 'http://127.0.0.1:8080' + + +class TestTCP(TestCase): + + def setUp(self) -> None: + self.sock = socket.socket() + self.sock.connect(TCP_ADDR) + + def test_nm(self) -> None: + self.sock.sendall(b'') # TODO + self._wait_for_ok() + + def test_json(self) -> None: + self.sock.sendall(b'') # TODO + self._wait_for_ok() + + def _wait_for_ok(self) -> None: + data = self.sock.recv(1024) + self.assertEqual(data, b'OK') diff --git a/models.py b/models.py new file mode 100644 index 0000000..04d769a --- /dev/null +++ b/models.py @@ -0,0 +1,10 @@ +from dataclasses import dataclass +from typing import Any + + +@dataclass +class SensorData: + mac: str + value: Any + time: int | None = None + name: str | None = None