Hmm I was using log.warning() and log.debug() inside the loop and they did nothing, outside the loop they would print fine. Not really important just odd behavior.
In other news I was able to send a color command to the light but I do have one minor gripe for you. That is that (0,0,0,0) does not execute through set_extended_color_zones() - I would have expected it to turn that zone off. Instead I had to use (0,0,0,6500).
I also need to be able to send a set_power() command in the event the light is off but Iām getting some aiolifx exceptions from this (even though it does work). I suspect I need to set up an asyncio wait but Iām not exactly sure.
@service
def z_sunrise_test2(Transition=60):
"""Window Sunshine"""
#init
Transition = Transition * 60 #transition time should be in minutes
connection = LIFXConnection(IP_ADDR, MAC)
connection.async_setup()
# connection.device.get_version()
# connection.device.get_hostfirmware()
connection.device.get_extended_color_zones()
connection.device.get_power()
#await connection
while connection.device.color_zones is None or connection.device.get_power() is None:
asyncio.sleep(0)
power = connection.device.get_power()
#set colors for phase1 in HSBK values of 0 to 65535
phase1 = [
(6553, 65535, 1965, 4000),
(6553, 65535, 1965, 4000),
(0, 0, 0, 6500),
(0, 0, 0, 6500),
(50243, 24247, 1966, 6500),
(0, 0, 0, 6500),
(50243, 24247, 1966, 6500),
(0, 0, 0, 6500),
(0, 0, 0, 6500),
(50243, 24247, 1966, 6500),
(0, 0, 0, 6500),
(50243, 24247, 1966, 6500),
(0, 0, 0, 6500),
(0, 0, 0, 6500),
(6553, 65535, 1965, 4000),
(6553, 65535, 1965, 4000)
]
# Fill in the remaining empty/non-existant zones
for _ in range(len(phase1), 82):
phase1.append((0, 0, 0, 0))
#if the light is off we need zero transition time, otherwise the light will blast us in the face
if (power == 0):
phase1_time = 0
else:
phase1_time = 15
#send command to light
connection.device.set_extended_color_zones(phase1, len(connection.device.color_zones), duration=(phase1_time * 1000))
if power==0: connection.device.set_power(True,2000)
Hereās the error:
2023-10-18 08:12:20.003 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1163, in _read_ready
self._protocol.datagram_received(data, addr)
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 223, in datagram_received
callb(self, response)
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 971, in
mycallb = lambda x, y: (mypartial(y), callb(x, y))
^^^^^^^^^^^
TypeError: 'int' object is not callable
2023-10-18 08:12:20.484 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1163, in _read_ready
self._protocol.datagram_received(data, addr)
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 223, in datagram_received
callb(self, response)
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 971, in
mycallb = lambda x, y: (mypartial(y), callb(x, y))
^^^^^^^^^^^
TypeError: 'int' object is not callable
2023-10-18 08:12:20.990 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1163, in _read_ready
self._protocol.datagram_received(data, addr)
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 223, in datagram_received
callb(self, response)
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 971, in
mycallb = lambda x, y: (mypartial(y), callb(x, y))
^^^^^^^^^^^
TypeError: 'int' object is not callable
2023-10-18 08:12:21.584 ERROR (Recorder) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 347, in try_sending
await event.wait()
File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
await fut
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 346, in try_sending
async with asyncio_timeout(timeout_secs):
File "/usr/local/lib/python3.11/asyncio/timeouts.py", line 111, in __aexit__
raise TimeoutError from exc_val
TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 354, in try_sending
callb(self, None)
File "/usr/local/lib/python3.11/site-packages/aiolifx/aiolifx.py", line 971, in
mycallb = lambda x, y: (mypartial(y), callb(x, y))
^^^^^^^^^^^
TypeError: 'int' object is not callable