From 1bcd596376ef0b09e99c429e288ae6891b7177a1 Mon Sep 17 00:00:00 2001 From: eliovir Date: Mon, 7 Nov 2022 22:47:33 +0100 Subject: [PATCH] Corriger la lecture de la batterie de Lywsd02 --- resources/blead/devices/lywsd02.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/resources/blead/devices/lywsd02.py b/resources/blead/devices/lywsd02.py index 88b2b80..e914af5 100755 --- a/resources/blead/devices/lywsd02.py +++ b/resources/blead/devices/lywsd02.py @@ -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' @@ -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] @@ -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)) @@ -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) \ No newline at end of file