Async music mode not working properly
The AsyncBulb music mode runs into the standard rate limits when music mode is enabled while the standard Bulb does not. See the example code which errors at 60 requests for the async code but does not error for the sync code.
from yeelight import Bulb
from yeelight.aio import AsyncBulb
import asyncio
import time
async def do_nothing(param):
pass
async def main():
bulb = AsyncBulb("10.76.19.240")
await bulb.async_listen(do_nothing)
bulb.turn_on()
bulb.start_music()
print(bulb.music_mode)
counter = 0
while True:
await bulb.async_set_rgb(255, 0, 0)
counter += 1
print(counter)
await asyncio.sleep(0.1)
await bulb.async_set_rgb(0, 255, 0)
counter += 1
print(counter)
await asyncio.sleep(0.1)
await bulb.async_set_rgb(0, 0, 255)
counter += 1
print(counter)
await asyncio.sleep(0.1)
# asyncio.run(main())
def main_sync():
bulb = Bulb("10.76.19.240")
bulb.turn_on()
bulb.start_music()
counter = 0
while True:
bulb.set_rgb(255, 0, 0)
counter += 1
print(counter)
time.sleep(0.1)
bulb.set_rgb(0, 255, 0)
counter += 1
print(counter)
time.sleep(0.1)
bulb.set_rgb(0, 0, 255)
counter += 1
print(counter)
time.sleep(0.1)
main_sync()
Edited by Alex