Skip to content

Commit 75cf7c1

Browse files
committed
Fix incorrect detection of LIFX white bulbs
Signed-off-by: Avi Miller <me@dje.li>
1 parent 5270cf5 commit 75cf7c1

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

aiolifx_effects/aiolifx_effects.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
2+
from functools import partial
23
import random
4+
35
from aiolifx.aiolifx import features_map
46

5-
from functools import partial
67

78
# aiolifx waveform modes
89
WAVEFORM_SINE = 1
@@ -13,10 +14,11 @@
1314

1415
def lifx_white(device):
1516
"""Return true if the device supports neither color nor temperature range."""
16-
return bool(
17-
features_map[device.product]["color"] is False
18-
and features_map[device.product]["temperature_range"] is None
19-
)
17+
max_kelvin = features_map[device.product].get("max_kelvin", None)
18+
min_kelvin = features_map[device.product].get("min_kelvin", None)
19+
20+
if max_kelvin is not None and min_kelvin is not None:
21+
return bool(max_kelvin == min_kelvin)
2022

2123

2224
def has_extended_multizone(device):
@@ -94,6 +96,9 @@ async def start(self, effect, participants):
9496
# Remember the current state
9597
tasks = []
9698
for device in participants:
99+
if device.version is None:
100+
response = await AwaitAioLIFX().wait(device.get_version)
101+
device.product = response.product
97102
if not self.running.get(device.mac_addr):
98103
tasks.append(AwaitAioLIFX().wait(device.get_color))
99104
if device.color_zones:

examples/colorloop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def register(self, bulb):
1616
def unregister(self, bulb):
1717
del self.bulbs[bulb.mac_addr]
1818

19-
loop = asyncio.get_event_loop()
19+
loop = asyncio.get_event_loop_policy().get_event_loop()
2020

2121
conductor = aiolifx_effects.Conductor(loop=loop)
2222

examples/pulse.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
import asyncio
4+
from functools import partial
5+
6+
import aiolifx
7+
import aiolifx_effects
8+
9+
class Bulbs:
10+
def __init__(self):
11+
self.bulbs = {}
12+
13+
def register(self, bulb):
14+
self.bulbs[bulb.mac_addr] = bulb
15+
16+
def unregister(self, bulb):
17+
del self.bulbs[bulb.mac_addr]
18+
19+
loop = asyncio.get_event_loop_policy().get_event_loop()
20+
21+
conductor = aiolifx_effects.Conductor(loop=loop)
22+
23+
mybulbs = Bulbs()
24+
25+
discover = loop.create_datagram_endpoint(
26+
partial(aiolifx.LifxDiscovery, loop, mybulbs),
27+
local_addr=('0.0.0.0', 56700))
28+
29+
loop.create_task(discover)
30+
31+
# Probe
32+
sleep = loop.create_task(asyncio.sleep(3))
33+
loop.run_until_complete(sleep)
34+
35+
# Run effect
36+
devices = list(mybulbs.bulbs.values())
37+
effect = aiolifx_effects.EffectPulse(power_on=True, mode="blink", cycles=3)
38+
loop.create_task(conductor.start(effect, devices))
39+
40+
# Stop effect in a while
41+
stop = conductor.stop(devices)
42+
loop.call_later(3, lambda: loop.create_task(stop))
43+
44+
# Wait for completion
45+
sleep = loop.create_task(asyncio.sleep(4))
46+
loop.run_until_complete(sleep)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
setup(
66
name='aiolifx_effects',
77
packages=['aiolifx_effects'],
8-
version='0.3.0',
8+
version='0.3.1',
99
install_requires=['aiolifx>=0.8.6'],
1010
description='aiolifx light effects',
1111
author='Anders Melchiorsen',

0 commit comments

Comments
 (0)