47 lines
1.1 KiB
Python
Executable File
47 lines
1.1 KiB
Python
Executable File
#!/usr/bin/python3 -O
|
|
|
|
import asyncio
|
|
import pathlib
|
|
import pprint
|
|
import typing
|
|
|
|
import aioesphomeapi
|
|
import click
|
|
import yaml
|
|
|
|
def load_secret(secret):
|
|
with open(pathlib.Path(__file__).parent / 'secrets.yaml') as file:
|
|
return yaml.safe_load(file)[secret]
|
|
|
|
async def main_async(device, **kwds):
|
|
api = aioesphomeapi.APIClient(device, 6053, load_secret('api_password'))
|
|
await api.connect(login=True)
|
|
entities, _services = await api.list_entities_services()
|
|
for entity in entities:
|
|
if entity.object_id == 'xmas':
|
|
await api.light_command(entity.key, **kwds)
|
|
|
|
#async def main_async(*args, rgb, **kwds):
|
|
# print(f'{rgb=}')
|
|
|
|
class RGB(typing.NamedTuple):
|
|
r: float
|
|
g: float
|
|
b: float
|
|
|
|
@classmethod
|
|
def fromstr(cls, rgb):
|
|
return cls(*map(float, rgb.split(',')))
|
|
|
|
@click.command()
|
|
@click.option('--device', default='lvng-xmas.lan')
|
|
@click.option('--effect')
|
|
@click.option('--on/--off', 'state', default=None)
|
|
@click.option('--rgb', type=RGB.fromstr)
|
|
@click.option('--brightness', type=float)
|
|
def main(*args, **kwds):
|
|
asyncio.run(main_async(*args, **kwds))
|
|
|
|
if __name__ == '__main__':
|
|
main()
|