Mercurial > code > home > repos > light-bridge
comparison light.py @ 5:7eeda7f4f9cd
spell it to_dict, for compat with DataClassJsonMixin
author | drewp@bigasterisk.com |
---|---|
date | Sun, 28 Jan 2024 16:01:43 -0800 |
parents | e8e4fd6d5619 |
children | fc8ed0efcd72 |
comparison
equal
deleted
inserted
replaced
4:e8e4fd6d5619 | 5:7eeda7f4f9cd |
---|---|
1 | |
2 import asyncio | 1 import asyncio |
3 import logging | 2 import logging |
4 from dataclasses import dataclass | 3 from dataclasses import dataclass |
4 | |
5 from color import Color | |
5 | 6 |
6 log = logging.getLogger('light') | 7 log = logging.getLogger('light') |
7 | 8 |
8 | 9 |
9 @dataclass | 10 @dataclass |
14 colorRequest: Color | 15 colorRequest: Color |
15 colorMessage: dict | 16 colorMessage: dict |
16 colorCurrent: Color | 17 colorCurrent: Color |
17 latencyMs: float | 18 latencyMs: float |
18 | 19 |
19 def to_js(self): | 20 def to_dict(self): |
20 return { | 21 return { |
21 'light': { | 22 'light': { |
22 'name': self.name, | 23 'name': self.name, |
23 'address': self.address, | 24 'address': self.address, |
24 'online': self.online, | 25 'online': self.online, |
40 return self._d[name] | 41 return self._d[name] |
41 | 42 |
42 async def changes(self): # yields None on any data change | 43 async def changes(self): # yields None on any data change |
43 while True: | 44 while True: |
44 yield None | 45 yield None |
45 await asyncio.sleep(1) | 46 await asyncio.sleep(1) # todo |
46 | 47 |
47 def to_js(self): | 48 def to_dict(self): |
48 return {'lights': [d.to_js() for d in sorted(self._d.values(), key=lambda r: r.name)]} | 49 return {'lights': [d.to_dict() for d in sorted(self._d.values(), key=lambda r: r.name)]} |