1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-10 18:00:12 +01:00
python-broadlink/cli/broadlink_discovery

31 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python
import argparse
import broadlink
from broadlink.exceptions import StorageError
parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
parser.add_argument("--timeout", type=int, default=5, help="timeout to wait for receiving discovery responses")
parser.add_argument("--ip", default=None, help="ip address to use in the discovery")
2020-05-09 19:35:51 +02:00
parser.add_argument("--dst-ip", default="255.255.255.255", help="destination ip address to use in the discovery")
args = parser.parse_args()
2019-05-22 07:28:02 +02:00
print("Discovering...")
devices = broadlink.discover(timeout=args.timeout, local_ip_address=args.ip, discover_ip_address=args.dst_ip)
for device in devices:
if device.auth():
2019-05-22 07:28:02 +02:00
print("###########################################")
print(device.type)
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)))
try:
2019-05-22 07:28:02 +02:00
print("temperature = {}".format(device.check_temperature()))
except (AttributeError, StorageError):
pass
2019-05-22 07:28:02 +02:00
print("")
else:
2019-05-22 07:28:02 +02:00
print("Error authenticating with device : {}".format(device.host))