diff options
author | Matthew Garrett <mjg59@coreos.com> | 2016-12-03T22·22-0800 |
---|---|---|
committer | Matthew Garrett <mjg59@coreos.com> | 2016-12-03T22·22-0800 |
commit | 31cd07716573a31c5add48a65d4939e7e1076883 (patch) | |
tree | fb681faf6db5990ca2c91225b946b2e30912dca1 /broadlink/__init__.py | |
parent | c157860f0d54c9e1f2e8ffb7024ea0c5e26e3d1a (diff) |
Expose the type of the discovered device
Allow clients to identify what kind of device has been discovered
Diffstat (limited to 'broadlink/__init__.py')
-rwxr-xr-x | broadlink/__init__.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/broadlink/__init__.py b/broadlink/__init__.py index 12769d13591c..7c3ba81bcb3c 100755 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -123,6 +123,7 @@ def discover(timeout=None): dev = gendevice(devtype, host, mac) devices.append(dev) + class device: def __init__(self, host, mac, timeout=10): self.host = host @@ -136,6 +137,7 @@ class device: self.cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.cs.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) self.cs.bind(('',0)) + self.type = "Unknown" def auth(self): payload = bytearray(0x50) @@ -174,6 +176,9 @@ class device: self.id = payload[0x00:0x04] self.key = payload[0x04:0x14] + def get_type(self): + return self.type + def send_packet(self, command, payload): self.count = (self.count + 1) & 0xffff packet = bytearray(0x38) @@ -239,6 +244,7 @@ class device: class sp1(device): def __init__ (self, host, mac): device.__init__(self, host, mac) + self.type = "SP1" def set_power(self, state): packet = bytearray(4) @@ -249,6 +255,7 @@ class sp1(device): class sp2(device): def __init__ (self, host, mac): device.__init__(self, host, mac) + self.type = "SP2" def set_power(self, state): """Sets the power state of the smart plug.""" @@ -271,6 +278,7 @@ class sp2(device): class a1(device): def __init__ (self, host, mac): device.__init__(self, host, mac) + self.type = "A1" def check_sensors(self): packet = bytearray(16) @@ -320,6 +328,7 @@ class a1(device): class rm(device): def __init__ (self, host, mac): device.__init__(self, host, mac) + self.type = "RM2" def check_data(self): packet = bytearray(16) |