From e41d2409422528de1872333e1d4c9b07f96910c3 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel Date: Tue, 16 Jun 2020 18:19:18 -0300 Subject: [PATCH] Add a method to lock/unlock the device --- broadlink/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/broadlink/__init__.py b/broadlink/__init__.py index 6406e15..f54b7b2 100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -244,9 +244,21 @@ class device: def set_name(self, name): packet = bytearray(4) - packet.extend(map(ord, name)) + packet += name.encode('utf-8') + packet += bytearray(0x50 - len(packet)) + packet[0x43] = self.cloud response = self.send_packet(0x6a, packet) check_error(response[0x22:0x24]) + self.name = name + + def set_lock(self, state): + packet = bytearray(4) + packet += self.name.encode('utf-8') + packet += bytearray(0x50 - len(packet)) + packet[0x43] = state + response = self.send_packet(0x6a, packet) + check_error(response[0x22:0x24]) + self.cloud = bool(state) def get_type(self): return self.type