diff light.py @ 12:7cc004eafb82

refactor (approx)
author drewp@bigasterisk.com
date Sun, 28 Jan 2024 20:02:34 -0800
parents 028ed39aa78f
children 1c865af058e7
line wrap: on
line diff
--- a/light.py	Sun Jan 28 17:31:06 2024 -0800
+++ b/light.py	Sun Jan 28 20:02:34 2024 -0800
@@ -68,7 +68,6 @@
 
 class Lights:
     _d: dict[str, Light] = {}
-    _changeSleepTask: asyncio.Task | None = None
 
     def __init__(self):
         self.add(Light('do-desk', 'topic1'))
@@ -83,6 +82,12 @@
     def byName(self, name: str) -> Light:
         return self._d[name]
 
+    def to_dict(self):
+        return {'lights': [d.to_dict() for d in sorted(self._d.values(), key=lambda r: r.name)]}
+
+    # the following is bad. Get a better events lib.
+    _changeSleepTask: asyncio.Task | None = None
+
     async def changes(self):  # yields None on any data change
         while True:
             log.info('Lights has a change')
@@ -101,6 +106,3 @@
         log.info('Lights.notifyChanged()')
         if self._changeSleepTask is not None:
             self._changeSleepTask.cancel()
-
-    def to_dict(self):
-        return {'lights': [d.to_dict() for d in sorted(self._d.values(), key=lambda r: r.name)]}