From aea3cc32f59e01a8967b9a5be8eac9ae74145933 Mon Sep 17 00:00:00 2001 From: sqozz Date: Fri, 17 Jan 2020 17:12:33 +0100 Subject: [PATCH 1/3] Add function to read current plug config --- sem6000.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sem6000.py b/sem6000.py index 1a3ffc6..29414fe 100644 --- a/sem6000.py +++ b/sem6000.py @@ -38,6 +38,13 @@ class SEMSocket(): msg = self.BTLEMessage(self, cmd, payload) return msg.send() + def getSynConfig(self): + #15, 5, 16, 0, 0, 0, 17, -1, -1 + cmd = bytearray([0x10]) + payload = bytearray([0x00, 0x00, 0x00]) + msg = self.BTLEMessage(self, cmd, payload) + msg.send() + def setStatus(self, status): # 0f 06 03 00 01 00 00 05 ff ff -> on # 0f 06 03 00 00 00 00 04 ff ff -> off @@ -274,6 +281,13 @@ class SEMSocket(): self.__btle_device.power_factor = power / (voltage * current) except ZeroDivisionError: self.__btle_device.power_factor = None + elif message_type == 0x10: + print("ordinaryPrice:", data[5] / 100) + print("valleyPrice", data[6] / 100) + print("valleyStart", (data[7] << 8 | data[8]) / 60) + print("valleyEnd", (data[9] << 8 | data[10]) / 60) + icons = ["plug", "speaker", "flatscreen", "desk lamp", "oven", "kitchen machine", "canning pot", "stanging lamp", "kettle", "mixer", "hanging lamp", "toaster", "washing machine", "fan", "fridge", "iron", "printer", "monitor", "notebook", "workstation", "video recorder", "curling iron", "heater"] + print("iconName", data[12]) elif message_type == 0x17: #authentication related response if data[5] == 0x00 or data[5] == 0x01: # in theory the fifth byte indicates a login attempt response (0) or a response to a password change (1) From 80c0c5dd4b641352f249342254b3fe0381e1125e Mon Sep 17 00:00:00 2001 From: sqozz Date: Mon, 20 Jan 2020 21:11:28 +0100 Subject: [PATCH 2/3] Add getSN function --- sem6000.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sem6000.py b/sem6000.py index 29414fe..c37d788 100644 --- a/sem6000.py +++ b/sem6000.py @@ -45,6 +45,13 @@ class SEMSocket(): msg = self.BTLEMessage(self, cmd, payload) msg.send() + def getSN(self): + # 15, 5, 17, 0, 0, 0, 18, -1, -1 + cmd = bytearray([0x11]) + payload = bytearray([0x00, 0x00, 0x00]) + msg = self.BTLEMessage(self, cmd, payload) + msg.send() + def setStatus(self, status): # 0f 06 03 00 01 00 00 05 ff ff -> on # 0f 06 03 00 00 00 00 04 ff ff -> off From 9b49abd66ed9a82fcfec0b1620a31113d51f166c Mon Sep 17 00:00:00 2001 From: sqozz Date: Fri, 8 May 2020 19:35:46 +0200 Subject: [PATCH 3/3] Make current config availible as attributes --- sem6000.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/sem6000.py b/sem6000.py index c37d788..d5f8f1d 100644 --- a/sem6000.py +++ b/sem6000.py @@ -4,6 +4,7 @@ import datetime import uuid class SEMSocket(): + icons = ["plug", "speaker", "flatscreen", "desk lamp", "oven", "kitchen machine", "canning pot", "stanging lamp", "kettle", "mixer", "hanging lamp", "toaster", "washing machine", "fan", "fridge", "iron", "printer", "monitor", "notebook", "workstation", "video recorder", "curling iron", "heater"] password = "0000" powered = False voltage = 0 @@ -15,6 +16,7 @@ class SEMSocket(): mac_address = "" custom_service = None authenticated = False + _icon_idx = None _name = None _read_char = None _write_char = None @@ -163,26 +165,10 @@ class SEMSocket(): # print("SynVer") # self.read_char.read_value() - #def GetSynConfig(self): - # print("GetSynConfig") - # #15, 5, 16, 0, 0, 0, 17, -1, -1 - # self.write_char.write_value(bytearray(b'\x0f\x05\x10\x00\x00\x00\x11\xff\xff')) - #def ______RESET(self): # #15, 5, 16, 0, 0, 0, 17, -1, -1 ??? maybe reset? # pass - #def GetSN(self): - # print("GetSN") - # #15, 5, 17, 0, 0, 0, 18, -1, -1 - # self.write_char.write_value(bytearray(b'\x0f\x05\x11\x00\x00\x00\x12\xff\xff')) - - # self.SynVer() - # self.notify_char.enable_notifications() - # self.Login("1337") - # self.GetSynConfig() - # #self.GetSN() - class NotConnectedException(Exception): pass @@ -289,12 +275,15 @@ class SEMSocket(): except ZeroDivisionError: self.__btle_device.power_factor = None elif message_type == 0x10: - print("ordinaryPrice:", data[5] / 100) - print("valleyPrice", data[6] / 100) - print("valleyStart", (data[7] << 8 | data[8]) / 60) - print("valleyEnd", (data[9] << 8 | data[10]) / 60) - icons = ["plug", "speaker", "flatscreen", "desk lamp", "oven", "kitchen machine", "canning pot", "stanging lamp", "kettle", "mixer", "hanging lamp", "toaster", "washing machine", "fan", "fridge", "iron", "printer", "monitor", "notebook", "workstation", "video recorder", "curling iron", "heater"] - print("iconName", data[12]) + self.__btle_device.default_charge = (data[5] / 100) + self.__btle_device.night_charge = (data[6] / 100) + night_charge_start_time = int((data[7] << 8 | data[8]) / 60) + night_charge_end_time = int((data[9] << 8 | data[10]) / 60) + self.__btle_device.night_charge_start_time = time.strptime(str(night_charge_start_time), "%H") + self.__btle_device.night_charge_end_time = time.strptime(str(night_charge_end_time), "%H") + self.__btle_device.night_mode = not bool(data[11]) + self.__btle_device.icon_idx = data[12] + self.__btle_device.power_protect = (data[13] << 8 | data[14]) elif message_type == 0x17: #authentication related response if data[5] == 0x00 or data[5] == 0x01: # in theory the fifth byte indicates a login attempt response (0) or a response to a password change (1)