Skip to content

Commit a3f4b87

Browse files
committed
simplify import error logic
1 parent 1d58f75 commit a3f4b87

3 files changed

Lines changed: 259 additions & 253 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ relies on the PlugApi as well.
1919
There are also some small utilities included,`ps-plugevents` and `ps-rawplug`
2020
showcasing the use of the first interface approach, and `ps-events` the latter.
2121
.
22-
The `ps-events` is effectively a consumer of the the PowersensorDevices event
22+
The `ps-events` is effectively a consumer the PowersensorDevices event
2323
stream and dumps all events to standard out. Similary, `ps-plugevents` shows
2424
the event stream from a single plug (plus whatever it might be relaying for),
2525
and `ps-rawplug` shows the raw event stream from the plug. Note that the format

src/powersensor_local/devices.py

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ async def _plug_lost(self, mac: str) -> None:
125125
# Internal event routing
126126
# ------------------------------------------------------------------
127127

128-
async def _emit_if_subscribed(self, ev: str, obj: dict) -> None:
128+
async def _emit_if_subscribed(self, ev: str, mac: str, obj: dict) -> None:
129129
if self._event_cb is None:
130130
return
131-
device = self._devices.get(obj.get('mac'))
131+
device = self._devices.get(mac)
132132
if device is not None and device.subscribed:
133133
obj['event'] = ev
134134
await self._event_cb(obj)
@@ -150,7 +150,7 @@ async def _reemit(self, ev: str, obj: dict[str, str]) -> None:
150150
obj['event'] = ev
151151
await self._event_cb(obj)
152152
else:
153-
await self._emit_if_subscribed(ev, obj)
153+
await self._emit_if_subscribed(ev, mac, obj)
154154

155155
async def _add_device(self, mac: str, typ: str) -> None:
156156
if mac in self._devices:

0 commit comments

Comments
 (0)