-
Notifications
You must be signed in to change notification settings - Fork 0
/
discovery.py
35 lines (28 loc) · 1014 Bytes
/
discovery.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
import pywemo
import re
devices_of_interest = ('Bedroom 2 Plant Light 2',
'Bedroom 2 Plant Heater')
devices = pywemo.discover_devices()
for device in devices:
print (" {}".format(device.name))
device_mapping = {}
for device in devices:
name = device.name
#print(name)
#print('state = ', device.get_state())
metainfo = str(device.metainfo.GetMetaInfo())
deviceinfo = str(device.deviceinfo.GetDeviceInformation())
if hasattr(device, "GetSmartDevInfo"):
print(device.basicevent.GetSmartDevInfo())
#print(device.deviceinfo.controlURL)
ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', device.deviceinfo.controlURL )[0]
url = pywemo.setup_url_for_address(ip)
if name in devices_of_interest:
device_mapping [name] = url
#print(name, metainfo, deviceinfo)
print(device_mapping)
for name, url in device_mapping.items():
#print (name, url)
device = pywemo.discovery.device_from_description(url)
print(device.name)