From 80a4d7d13e1e1bf4ef8989c1f650b43e41f88a01 Mon Sep 17 00:00:00 2001 From: Daniel Correa Lobato Date: Sat, 4 Aug 2018 23:35:18 -0300 Subject: [PATCH 1/4] hottest vs. coldest and type of bulb Updated the example: -- temperature=100 is the coldest color, not hottest -- bulb method requires three parameters: address, code and type/kind of bulb --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bcf1329..6a990b9 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,16 @@ A simple Python API for controlling LED bulbs from [Eufy](https://www.eufylife.c Example use ----------- -This will connect to a bulb and turn it on at 50% brightness and the hottest colour temperature. +This will connect to a bulb and turn it on at 50% brightness and the coldest colour temperature. ``` import lakeside -bulb = lakeside.bulb(ip_address, access_code) +bulb = lakeside.bulb(ip_address, access_code, type) bulb.connect() bulb.set_state(power=True, brightness=50, temperature=100) ``` -The ip and access code can be obtained by doing: +The ip, access code and type can be obtained by doing: ``` import lakeside From 9734f4d6eb5c39310e664b79a58922d3a4e8d285 Mon Sep 17 00:00:00 2001 From: Daniel Correa Lobato Date: Sun, 5 Aug 2018 00:48:30 -0300 Subject: [PATCH 2/4] Handle disconnection A terrible -- but working -- solution for issue #7. The disconnection is perceived during the `recv()`, so at receiving zero bytes, we do a reconnect, reissue the command, and receive data again. Definitely not the best solution for this, but at least it is working now. --- lakeside/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lakeside/__init__.py b/lakeside/__init__.py index 00c239e..d43518e 100755 --- a/lakeside/__init__.py +++ b/lakeside/__init__.py @@ -71,10 +71,20 @@ def send_packet(self, packet, response): encrypted_packet = cipher.encrypt(raw_packet) - self.s.send(encrypted_packet) + try: + self.s.send(encrypted_packet) + except: + self.connect() + self.s.send(encrypted_packet) + print("depois do reconnect") + if response: data = self.s.recv(1024) - + if (len(data) == 0): + self.connect() + self.s.send(encrypted_packet) + data = self.s.recv(1024) + cipher = AES.new(bytes(key), AES.MODE_CBC, bytes(iv)) decrypted_packet = cipher.decrypt(data) From 84c845971706756e6188043f0fc4dcb6705fed46 Mon Sep 17 00:00:00 2001 From: Daniel Correa Lobato Date: Sun, 5 Aug 2018 00:51:15 -0300 Subject: [PATCH 3/4] Handle disconnection A terrible -- but working -- solution for issue #7. The disconnection is perceived during the `recv()`, so at receiving zero bytes, we do a reconnect, reissue the command, and receive data again. Definitely not the best solution for this, but at least it is working now. --- lakeside/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lakeside/__init__.py b/lakeside/__init__.py index d43518e..b924bd7 100755 --- a/lakeside/__init__.py +++ b/lakeside/__init__.py @@ -76,7 +76,6 @@ def send_packet(self, packet, response): except: self.connect() self.s.send(encrypted_packet) - print("depois do reconnect") if response: data = self.s.recv(1024) From 5aba7658166cfd459585286fd27bd949b4093b6a Mon Sep 17 00:00:00 2001 From: Daniel Correa Lobato Date: Sat, 19 Dec 2020 17:59:32 -0300 Subject: [PATCH 4/4] -- Add support for device icon URL -- Added a guard against devices without the correct structure (from PR #20) --- lakeside/__init__.py | 18 ++++++++++-------- setup.py | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lakeside/__init__.py b/lakeside/__init__.py index 095f38d..c06cf3d 100755 --- a/lakeside/__init__.py +++ b/lakeside/__init__.py @@ -42,14 +42,16 @@ def get_devices(username, password): info = r.json() for item in info['items']: - if item['device'] is not None: - devices.append({ - 'address': item['device']['wifi']['lan_ip_addr'], - 'code': item['device']['local_code'], - 'type': item['device']['product']['product_code'], - 'name': item['device']['alias_name'], - 'id': item['device']['id'], - }) + if item['device'] is not None and item['device']['wifi'] is not None: + entry = dict() + entry['address'] = item['device']['wifi']['lan_ip_addr'] + entry['code'] = item['device']['local_code'] + entry['type'] = item['device']['product']['product_code'] + entry['name'] = item['device']['alias_name'] + entry['id'] = item['device']['id'] + if item['device']['product']['icon_url'] is not None: + entry['icon_url'] = item['device']['product']['icon_url'] + devices.append(entry) return devices diff --git a/setup.py b/setup.py index ecc25ac..678aaca 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ setup( name='lakeside', - version="0.12", + version="0.13", author='Matthew Garrett', author_email='mjg59@google.com', url='http://github.com/google/python-lakeside',