/
light.py
48 lines (34 loc) · 1.1 KB
/
light.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import copy
from typing import Any, List
from chroma_feedback import color, helper, reporter
from chroma_feedback.typing import Color, Consumer, ProducerReport, Status
from .api import get_api
LIGHTS = None
def get_lights() -> Any:
global LIGHTS
if not LIGHTS:
LIGHTS = get_api().all_lights()
return LIGHTS
def filter_lights(lights : Any, light_ids : List[str]) -> Any:
if light_ids:
for light in copy.copy(lights):
if light.path not in light_ids:
lights.remove(light)
return lights
def process_lights(lights : Any, producer_report : List[ProducerReport]) -> List[Consumer]:
result : List[Consumer] = []
status : Status = reporter.resolve_report_status(producer_report)
# process lights
for light in lights:
if set_light(light, color.get_by_status(status)):
result.append(
{
'name': 'embrava.blynclight',
'type': 'light',
'description': helper.create_description(light.info['product_string'], light.path),
'status': status
})
return result
def set_light(light : Any, color_config : Color) -> bool:
light.on(tuple(color_config['rgb']))
return light.is_on is True