@@ -128,21 +128,24 @@ def translate_raw_message(message: dict, relay_mac: str):
128128 Translates raw messages from the plug API into stable, documented events.
129129
130130 Args:
131- - message: The raw message (decoded into a dict)
132- - relay_mac: The id (MAC address) of the plug the message was received
131+ message: The raw message (decoded into a dict)
132+ relay_mac: The id (MAC address) of the plug the message was received
133133 through. When the message origin is not the plug, the events returned
134134 from this function will have "via": relay_mac added to denote what
135135 plug is acting as the relay for them.
136136
137137 Returns:
138+
138139 A dictionary of events, quite possibly empty. The key is the event
139140 name that the event should be emitted under, with the value being
140141 the event data itself (a dict).
141142
142143 Possible events returned:
144+
143145 - "average_power": An event denoting the average power seen over a
144146 short duration, such as 1 or 30 seconds typically. Both plugs and
145147 powersensors may originate these. The event data comprises:
148+
146149 - "mac": The MAC address of the device.
147150 - "role": The assigned role of the device, if known.
148151 - "via": The id of the relaying plug, if from a sensor.
@@ -155,6 +158,7 @@ def translate_raw_message(message: dict, relay_mac: str):
155158 information on the power components feeding into the power measurement.
156159 To be read in conjunction with the "average_power" message with the
157160 same starttime_utc value. Comprises:
161+
158162 - "mac": The MAC address of the device.
159163 - "role": The assigned role of the device, if known.
160164 - "starttime_utc": Seconds since the Unix Epoch, in UTC.
@@ -165,6 +169,7 @@ def translate_raw_message(message: dict, relay_mac: str):
165169
166170 - "summation_energy": An event reporting an energy summation value.
167171 Issued for both plugs and sensors. Comprises:
172+
168173 - "mac": The MAC address of the device.
169174 - "role": The assigned role of the device, if known.
170175 - "via": The id of the relaying plug, if from a sensor.
@@ -184,6 +189,7 @@ def translate_raw_message(message: dict, relay_mac: str):
184189 - "average_flow": An event denoting the average flow rate seen over a
185190 short duration, such as 1 or 30 seconds typically. Only originated by
186191 water sensors. The event data comprises:
192+
187193 - "mac": The MAC address of the device.
188194 - "role": The assigned role of the device, if known.
189195 - "via": The id of the relaying plug.
@@ -193,6 +199,7 @@ def translate_raw_message(message: dict, relay_mac: str):
193199
194200 - "summation_volume": An event reporting a volume summation value.
195201 Issued only for water sensors. Comprises:
202+
196203 - "mac": The MAC address of the device.
197204 - "role": The assigned role of the device, if known.
198205 - "via": The id of the relaying plug.
@@ -209,33 +216,36 @@ def translate_raw_message(message: dict, relay_mac: str):
209216 unknown unit, for an average over a short duration, such as 1 or 30
210217 seconds typically. Issued by powersensors, prior to calibration.
211218 The event data comprises:
219+
212220 - "mac": The MAC address of the device.
213221 - "role": The assigned role of the device, if known.
214222 - "via": The id of the relaying plug.
215223 - "starttime_utc": Seconds since the Unix Epoch, in UTC.
216224 - "duration_s": The number of seconds the reading is calculated over.
217225 - "value": The value, in unspecified units. The only valid thing
218- to use this value for is display it relative to other uncalibrated
219- values from the same device. The magnitude of the value is an
220- indication of the strength of the signal seen by the sensor, but
221- the unit is most definitely NOT in Watts. For most purposes, this
222- event can (and should be) ignored. Once the backend has successfully
223- calibrated the sensor against one or more plugs, these events
224- will be replaced by "average_power" events instead.
226+ to use this value for is display it relative to other uncalibrated
227+ values from the same device. The magnitude of the value is an
228+ indication of the strength of the signal seen by the sensor, but
229+ the unit is most definitely NOT in Watts. For most purposes, this
230+ event can (and should be) ignored. Once the backend has successfully
231+ calibrated the sensor against one or more plugs, these events
232+ will be replaced by "average_power" events instead.
225233
226234 - "battery_level": An event reporting the battery level of a sensor.
227235 The event data comprises:
236+
228237 - "mac": The MAC address of the device.
229238 - "role": The assigned role of the device, if known.
230239 - "via": The id of the relaying plug.
231240 - "starttime_utc": Seconds since the Unix Epoch, in UTC.
232241 - "volts": The current battery level, in Volts. Sensors operate
233- on 3.7V nominally, with a fully charged battery at around 4.2V.
234- Precise battery curves vary individually.
242+ on 3.7V nominally, with a fully charged battery at around 4.2V.
243+ Precise battery curves vary individually.
235244
236245 - "radio_signal_quality": An event reporting radio signal quality for
237246 a sensor. Note that this is for the long-range radio comms with the
238247 plug, not for the WiFi signal. The event comprises:
248+
239249 - "mac": The MAC address of the device.
240250 - "role": The assigned role of the device, if known.
241251 - "via": The id of the relaying plug.
@@ -245,7 +255,6 @@ def translate_raw_message(message: dict, relay_mac: str):
245255 during the reporting window. Values below -90 are considered poor
246256 reception.
247257 - "last_rssi": The most recent RSSI value.
248-
249258 """
250259 evs : dict = {}
251260 typ = message ['type' ]
0 commit comments