Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
"""Series-neutral models. Every operation returns the same shape for both
|
|
series; anything only one series has goes under `detail`."""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Any, Dict, Optional
|
|
|
|
from .errors import BadRequest
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class UnitAddress:
|
|
host: Optional[str]
|
|
tcp_port: Optional[int]
|
|
port: Optional[str]
|
|
baud: Optional[int]
|
|
|
|
def __post_init__(self) -> None:
|
|
if not self.host and not self.port:
|
|
raise BadRequest(
|
|
"specify 'host' (TCP, e.g. ?host=10.0.0.5&tcp_port=9034) "
|
|
"or 'port' (serial, e.g. ?port=/dev/ttyACM0)"
|
|
)
|
|
|
|
@property
|
|
def key(self) -> str:
|
|
"""One key per physical link -- what the per-unit lock is keyed on."""
|
|
if self.host:
|
|
return f"tcp:{self.host}:{self.tcp_port}"
|
|
return f"serial:{self.port}"
|
|
|
|
|
|
@dataclass
|
|
class UnitInfo:
|
|
serial: str
|
|
series: int
|
|
model: Optional[str]
|
|
firmware: Optional[str]
|
|
monitoring: Optional[bool]
|
|
active_setup: Optional[str]
|
|
detail: Dict[str, Any] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass
|
|
class UnitStatus:
|
|
serial: str
|
|
series: int
|
|
monitoring: bool
|
|
battery_volts: Optional[float]
|
|
memory_total_bytes: Optional[int]
|
|
memory_free_bytes: Optional[int]
|
|
device_time: Optional[str] # ISO, the unit's own local time
|
|
event_count: Optional[int] # None where it is not cheap (Series 3)
|
|
detail: Dict[str, Any] = field(default_factory=dict)
|
|
|
|
|
|
@dataclass
|
|
class UnitSettings:
|
|
serial: str
|
|
series: int
|
|
setup_name: Optional[str]
|
|
record_mode: Optional[str] # the unit's own name for its mode
|
|
sample_rate: Optional[int]
|
|
record_time_s: Optional[float]
|
|
histogram_interval_s: Optional[int]
|
|
geo_trigger_ips: Optional[float]
|
|
notes: Dict[str, str] = field(default_factory=dict)
|
|
detail: Dict[str, Any] = field(default_factory=dict)
|