### Register Gateway Event Listeners Source: https://github.com/egeback/aiomihome/blob/master/README.md Sets up callback functions for heartbeat and device data events from the gateway. The 'data' argument in callbacks contains the received information. ```python async def heartbeat_callback(data): print("HEARTBEAT RECIVED", data) async def device_callback(data): print("Device data RECIVED", data) gateway.heartbeat_callback = heartbeat_callback gateway.device_callback = device_callback ``` -------------------------------- ### Auto-discover Gateways Configuration Source: https://github.com/egeback/aiomihome/blob/master/README.md Configuration for auto-discovering Xiaomi gateways. Ensure the 'key' variable is defined. ```python gateways_config = [ { "host": "10.0.4.104", "sid": "7811dcb07917", "port": 9898, "key": key } ] service = XiaomiService(gateways_config=gateways_config) # Start the mulitcast socket listner await service.listen() # Run the auto discover gateways = await service.discover() print("Number of gateways found: {}".format(len(gateways))) # Get first gateway gateway = gateways[0] ``` -------------------------------- ### Directly Connect to Gateway Source: https://github.com/egeback/aiomihome/blob/master/README.md Establishes a direct connection to a specified Xiaomi gateway. Requires the gateway's host, port, SID, and key. ```python service = XiaomiService() # Start the mulitcast socket listner await service.listen() # Create a gatewate connetion gateway = await service.add_gateway("10.0.4.104", 9898, "7811dcb07917", key) ``` -------------------------------- ### Control Gateway Light Color Source: https://github.com/egeback/aiomihome/blob/master/README.md Sets the gateway's light to different colors (red, green, blue) sequentially, followed by turning it off. Requires an active gateway connection. ```python # Red await gateway.set_color(255, 0, 0) await asyncio.sleep(1) # Green await gateway.set_color(0, 255, 0) await asyncio.sleep(1) # Blue await gateway.set_color(0, 0, 255) await asyncio.sleep(1) # Off await gateway.turn_off_light() ``` -------------------------------- ### Print Gateway Device Information Source: https://github.com/egeback/aiomihome/blob/master/README.md Iterates through the gateway's known devices and prints their types, counts, models, and data. This snippet assumes 'gateway' is an initialized Gateway object. ```python print("Turn on light") for device_type, devices in gateway.devices.items(): print(device_type, len(devices)) for device in devices: print(" ", device['model']) print(device) for value_key, value in device['data'].items(): print(" ", value_key, value) ``` -------------------------------- ### Close Gateway Connections Source: https://github.com/egeback/aiomihome/blob/master/README.md Closes all active connections managed by the XiaomiService. ```python await service.close() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.