Exemplo n.º 1
0
        data_report = json.loads(report['data'])
        # Update device data from given report
        for _, gateway in mihome.gateways.items():
            if not sensor_id in gateway.sensors:
                print(f'UNKNOWN DEVICE sid = {sensor_id}')
            else:
                sensor = gateway.sensors[sensor_id]
                update_sensor_data(gateway, sensor, data_report, True)
    except Exception as inst:
        print(type(inst))    # the exception instance
        print(inst.args)     # arguments stored in .args
        print(inst)          # __str__ allows args to be printed directly, but may be overridden in exception subclasses


mihome = XiaomiGatewayDiscovery(report_callback, gateways_config, 'any')
mihome.discover_gateways()
for host, gateway in mihome.gateways.items():
    print(f'GATEWAY [{host}] - SENSOR DISCOVERED:')
    for sensor_id, sensor in gateway.sensors.items():
        print(f'{sensor_id} - {sensor}')
mihome.listen()
while True:
    time.sleep(10)
    for host, gateway in mihome.gateways.items():
        print(f'---GATEWAY [{host}]: token: {gateway.token}')
        for sensor_id, sensor in gateway.sensors.items():
            cmd = '{"cmd":"read","sid":"' + sensor_id + '"}'
            resp = gateway._send_cmd(cmd, "read_ack") if int(
                gateway.proto[0:1]) == 1 else gateway._send_cmd(cmd, "read_rsp")
            if _validate_data(resp):
                data_report = sensor['data']
Exemplo n.º 2
0
#! /usr/bin/env python
#coding=utf-8
from xiaomi_gateway import (XiaomiGateway, XiaomiGatewayDiscovery)

a1 = XiaomiGatewayDiscovery()
print a1.discover_gateways()
'''
ip = ""
port =
sid = 
key = 
'''