forked from sqozz/sem6000
Add function to sync the time with the plug
This commit is contained in:
parent
f656c5d516
commit
a5312baef3
14
sem6000.py
14
sem6000.py
|
@ -1,5 +1,6 @@
|
||||||
from bluepy import btle
|
from bluepy import btle
|
||||||
import time
|
import time
|
||||||
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
class SEMSocket():
|
class SEMSocket():
|
||||||
|
@ -42,6 +43,17 @@ class SEMSocket():
|
||||||
msg = self.BTLEMessage(self, cmd, payload)
|
msg = self.BTLEMessage(self, cmd, payload)
|
||||||
msg.send()
|
msg.send()
|
||||||
|
|
||||||
|
def syncTime(self):
|
||||||
|
#15, 12, 1, 0, SECOND, MINUTE, HOUR_OF_DAY, DAY_OF_MONTH, MONTH (+1), int(YEAR/256), YEAR%256, 0, 0, CHKSUM, 255, 255
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
cmd = bytearray([0x01])
|
||||||
|
payload = bytearray([0x00])
|
||||||
|
payload += bytearray([now.second, now.minute, now.hour])
|
||||||
|
payload += bytearray([now.day, now.month, int(now.year/256), now.year%256])
|
||||||
|
payload += bytearray([0x00, 0x00])
|
||||||
|
msg = self.BTLEMessage(self, cmd, payload)
|
||||||
|
msg.send()
|
||||||
|
|
||||||
def login(self, password):
|
def login(self, password):
|
||||||
self.password = password
|
self.password = password
|
||||||
cmd = bytearray([0x17])
|
cmd = bytearray([0x17])
|
||||||
|
@ -191,6 +203,8 @@ class SEMSocket():
|
||||||
print("Checksum error!")
|
print("Checksum error!")
|
||||||
else:
|
else:
|
||||||
print("Unknown error:", data)
|
print("Unknown error:", data)
|
||||||
|
elif message_type == 0x01:
|
||||||
|
print("Time synced")
|
||||||
elif message_type == 0x03: #switch toggle
|
elif message_type == 0x03: #switch toggle
|
||||||
print("Switch toggled")
|
print("Switch toggled")
|
||||||
self.__btle_device.getStatus()
|
self.__btle_device.getStatus()
|
||||||
|
|
Loading…
Reference in a new issue