#!/usr/bin/python # # Interact with a hub. # import os.path import asyncio import pylutron_caseta as pylutron import pylutron_caseta.smartbridge CERTS_DIR = '/home/gstein/.config/pylutron_caseta' async def example(): # `Smartbridge` provides an API for interacting with the Caséta bridge. bridge = pylutron.smartbridge.Smartbridge.create_tls( '192.168.0.186', os.path.join(CERTS_DIR, '192.168.0.186.key'), os.path.join(CERTS_DIR, '192.168.0.186.crt'), os.path.join(CERTS_DIR, '192.168.0.186-bridge.crt'), ) await bridge.connect() if False: # Get the first light. # The device is represented by a dict. device = bridge.get_devices_by_domain("light")[0] # Turn on the light. # Methods that act on devices expect to be given the device id. await bridge.turn_on(device["device_id"]) if True: print('DEVICES:', bridge.get_devices()) await bridge.close() # Because pylutron_caseta uses asyncio, # it must be run within the context of an asyncio event loop. #loop = asyncio.get_event_loop() #loop.run_until_complete(example()) asyncio.run(example())