tests/models.py

33 lines
694 B
Python
Raw Normal View History

2024-05-31 14:58:46 +03:00
from dataclasses import dataclass
2024-05-31 15:09:48 +03:00
from typing import Any, Iterable
2024-05-31 14:58:46 +03:00
@dataclass
class SensorData:
mac: str
value: Any
time: int | None = None
name: str | None = None
2024-05-31 15:09:48 +03:00
def create_nm_req(
dev_mac: str,
dev_name: str | None = None,
sensors: Iterable[SensorData] = ()) -> str:
'''Generate a NarodMon format (#mac#value) request'''
res = '#' + dev_mac
if dev_name is not None:
res += '#' + dev_name
res += '\n'
for s in sensors:
res += f'#{s.mac}#{s.value}'
if s.time is not None:
res += f'#{s.time}'
if s.name is not None:
res += '#' + s.name
res += '\n'
return res