Skip to content

Commit 52253c2

Browse files
committed
Add documentation clarifications
1 parent fab270a commit 52253c2

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎src/powersensor_local/devices.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class _PowersensorDevicesBase:
5151
5252
**device_found**
5353
A device has been discovered or re-discovered.
54+
Note that due to device hardware limitations, role information is NOT
55+
reliably available at this time, and therefore not included in this
56+
message.
5457
``{ event: "device_found", device_type: "plug"|"sensor", mac: "..." }``
5558
5659
**device_lost**
@@ -71,6 +74,9 @@ class _PowersensorDevicesBase:
7174
``device_found`` for the same sensor MAC.
7275
7376
Note: ``scan_complete`` is only emitted by PowersensorLegacyDevices.
77+
78+
The typical event cadence is 30 seconds, but may be as frequent as every
79+
second, or less frequent in case of packet loss.
7480
"""
7581

7682
def __init__(
@@ -121,7 +127,13 @@ def _maybe_log(self, level: _LogLevel, msg: str, *args) -> None:
121127
# ------------------------------------------------------------------
122128

123129
def subscribe(self, mac: str) -> None:
124-
"""Subscribe to events from the device with the given MAC address."""
130+
"""Subscribe to events from the device with the given MAC address.
131+
132+
Subscriptions are automatically removed if a device disappears,
133+
ensuring no accumulating resource leakage. Use the `device_found`
134+
message to resubscribe if a subscription is still desired when the
135+
device returns, if it returns.
136+
"""
125137
device = self._devices.get(mac)
126138
if device:
127139
device.subscribed = True

‎src/powersensor_local/virtual_household.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ def __init__(self, with_solar: bool):
150150
processing, but until such a time may generate incorrect values
151151
for home usage. Similarly, if this is set to True but no solar
152152
exists, no events may be generated.
153+
154+
It is expected that a user of this library will persist this flag
155+
and restore it upon reinitialisation. Powersensor kits may or may
156+
not include a solar sensor, but once an installation has been
157+
observed to have a solar sensor this is expected to stay so.
158+
In particular, this is to guard against the (somewhat common)
159+
scenario where a solar sensor runs out of battery and stops sending
160+
data. Without having persisted the with_solar flag, the system
161+
would be generating incorrect data until such a time the solar
162+
sensor is recharged. It is vastly preferable to have the system
163+
show no data than show incorrect data.
153164
"""
154165
super().__init__()
155166
self._expect_solar = with_solar

‎src/powersensor_local/xlatemsg.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def translate_raw_message(message: dict, relay_mac: str):
136136
through. When the message origin is not the plug, the events returned
137137
from this function will have "via": relay_mac added to denote what
138138
plug is acting as the relay for them.
139+
Note that the relaying plug for a sensor can change at any point
140+
without warning, and the topology is not stable. The relay_mac is
141+
intended as a diagnostic aid only.
139142
140143
Returns:
141144
@@ -243,7 +246,15 @@ def translate_raw_message(message: dict, relay_mac: str):
243246
- "starttime_utc": Seconds since the Unix Epoch, in UTC.
244247
- "volts": The current battery level, in Volts. Sensors operate
245248
on 3.7V nominally, with a fully charged battery at around 4.2V.
246-
Precise battery curves vary individually.
249+
Precise battery curves vary individually. It is intentional that
250+
we do not attempt to map these to a percentage value here, as
251+
between individual differences and environmental conditions they
252+
are bound to be inaccurate. Short of characterising each battery
253+
in its environment, any such mapping will be inaccurate. It can
254+
be argued that users wishing a simple percentage display are best
255+
off using a simple linear extrapolation across the middle part of
256+
the curve, e.g. 3.3V and 4.15V. It's not entirely accurate, but
257+
it's also not useless.
247258
248259
- "radio_signal_quality": An event reporting radio signal quality for
249260
a sensor. Note that this is for the long-range radio comms with the

0 commit comments

Comments
 (0)