Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions resources/blead/devices/lywsd02.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from multiconnect import Connector
from notification import Notification

UUID_BATTERY = 'EBE0CCC4-7A0A-4B0C-8A1A-6FF2997DA3A6'

class Lywsd02():
def __init__(self):
self.name = 'lywsd02'
Expand All @@ -31,7 +33,7 @@ def parse(self,data,mac,name,manuf):
if val_type in ['04']: # type: temperature
t_data = val_data[2:4] + val_data[0:2]
temp = int(t_data,16)/10.0
logging.debug('Lywsd02------ Advertising Data=> Temp' + str(temp))
logging.debug('Lywsd02------ Advertising Data=> Temp: ' + str(temp))
action['temperature'] = temp
elif val_type in ['06']: # type: moisture
h_data = val_data[2:4] + val_data[0:2]
Expand Down Expand Up @@ -63,16 +65,16 @@ def read(self,mac):
if not conn.isconnected:
return
Firm = bytearray(conn.readCharacteristic('0x24'))
batt = bytearray(conn.readCharacteristic('0x18'))
battery = batt[0]
ch = conn.conn.getCharacteristics(uuid=UUID_BATTERY)[0]
battery = ord(ch.read())
firmware = "".join(map(chr, Firm))
notification = Notification(conn,XiaomiHT)
notification = Notification(conn,Lywsd02)
conn.writeCharacteristic('0x10','0100',response=True)
notification.subscribe(2)
result['battery'] = battery
result['firmware'] = firmware
result['id'] = mac
logging.debug('XIAOMIHT------'+str(result))
logging.debug('Lywsd02------ Result: '+str(result))
return result
except Exception as e:
logging.error(str(e))
Expand All @@ -89,4 +91,4 @@ def handlenotification(self,conn,handle,data,action={}):
result['source'] = globals.daemonname
globals.JEEDOM_COM.add_changes('devices::'+conn.mac,result)

globals.COMPATIBILITY.append(Lywsd02)
globals.COMPATIBILITY.append(Lywsd02)