2020-10-21 19:32:32 +02:00
|
|
|
#!/usr/bin/env python3
|
2017-01-11 01:55:02 +01:00
|
|
|
import argparse
|
|
|
|
|
2019-10-02 08:25:27 +02:00
|
|
|
import broadlink
|
2021-04-29 23:59:58 +02:00
|
|
|
from broadlink.const import DEFAULT_BCAST_ADDR, DEFAULT_TIMEOUT
|
2020-06-08 12:21:55 +02:00
|
|
|
from broadlink.exceptions import StorageError
|
2019-10-02 08:25:27 +02:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
|
2021-04-29 23:59:58 +02:00
|
|
|
parser.add_argument("--timeout", type=int, default=DEFAULT_TIMEOUT, help="timeout to wait for receiving discovery responses")
|
2019-07-29 08:39:50 +02:00
|
|
|
parser.add_argument("--ip", default=None, help="ip address to use in the discovery")
|
2021-04-29 23:59:58 +02:00
|
|
|
parser.add_argument("--dst-ip", default=DEFAULT_BCAST_ADDR, help="destination ip address to use in the discovery")
|
2017-01-11 01:55:02 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2019-05-22 07:28:02 +02:00
|
|
|
print("Discovering...")
|
2020-03-04 22:25:00 +01:00
|
|
|
devices = broadlink.discover(timeout=args.timeout, local_ip_address=args.ip, discover_ip_address=args.dst_ip)
|
2017-01-11 01:55:02 +01:00
|
|
|
for device in devices:
|
|
|
|
if device.auth():
|
2019-05-22 07:28:02 +02:00
|
|
|
print("###########################################")
|
|
|
|
print(device.type)
|
2019-10-02 08:25:27 +02:00
|
|
|
print("# broadlink_cli --type {} --host {} --mac {}".format(hex(device.devtype), device.host[0],
|
|
|
|
''.join(format(x, '02x') for x in device.mac)))
|
2019-05-22 07:28:02 +02:00
|
|
|
print("Device file data (to be used with --device @filename in broadlink_cli) : ")
|
|
|
|
print("{} {} {}".format(hex(device.devtype), device.host[0], ''.join(format(x, '02x') for x in device.mac)))
|
2020-06-08 12:21:55 +02:00
|
|
|
try:
|
2019-05-22 07:28:02 +02:00
|
|
|
print("temperature = {}".format(device.check_temperature()))
|
2020-06-08 12:21:55 +02:00
|
|
|
except (AttributeError, StorageError):
|
|
|
|
pass
|
2019-05-22 07:28:02 +02:00
|
|
|
print("")
|
2017-01-11 01:55:02 +01:00
|
|
|
else:
|
2019-05-22 07:28:02 +02:00
|
|
|
print("Error authenticating with device : {}".format(device.host))
|