diff --git a/fonctions.py b/fonctions.py index d00cabd..6551efc 100644 --- a/fonctions.py +++ b/fonctions.py @@ -374,6 +374,8 @@ def ProcessAllState(data,model,option): kwarg.update(ReturnUpdateValue('alert', data['alert'], model)) if 'status' in data: kwarg.update(ReturnUpdateValue('status', data['status'])) + if 'pm2_5' in data: + kwarg.update(ReturnUpdateValue('airqualityppb', data['pm2_5'])) if 'on' in data: kwarg.update(ReturnUpdateValue('on', data['on'], model) ) if 'x' in data: @@ -422,8 +424,6 @@ def ProcessAllState(data,model,option): kwarg.update(ReturnUpdateValue('lockstate', data['lockstate'])) if 'airqualityppb' in data: kwarg.update(ReturnUpdateValue('airqualityppb', data['airqualityppb'])) - if 'pm2_5' in data: - kwarg.update(ReturnUpdateValue('airqualityppb', data['pm2_5'])) if 'bri' in data: kwarg.update(ReturnUpdateValue('bri', data['bri'], model) ) if 'lift' in data: @@ -436,6 +436,8 @@ def ProcessAllState(data,model,option): kwarg.update(ReturnUpdateValue( 'action' , data['action'], model ) ) if 'speed' in data: kwarg.update(ReturnUpdateValue( 'speed' , data['speed'], model ) ) + if 'expectedrotation' in data: + kwarg.update(ReturnUpdateValue( 'expectedrotation' , data['expectedrotation'], model ) ) #if 'lastupdated' in data: # kwarg.update(ReturnUpdateValue('lastupdated', data['lastupdated'])) @@ -712,6 +714,14 @@ def ReturnUpdateValue(command, val ,option = None): kwarg['nValue'] = 0 kwarg['sValue'] = str(val) + if command == 'expectedrotation': + kwarg['nValue'] = int(val) + + if kwarg['nValue'] == 0: + kwarg['sValue'] = 'Off' + else: + kwarg['sValue'] = str( kwarg['nValue'] ) + #switch if command == 'buttonevent': @@ -746,6 +756,18 @@ def ButtonconvertionXCUBE_R(val): return kwarg +def ButtonconvertionXCUBET1_R(val): + kwarg = {} + + kwarg['nValue'] = int(val) + + if kwarg['nValue'] == 0: + kwarg['sValue'] = 'Off' + else: + kwarg['sValue'] = str( kwarg['nValue'] ) + + return kwarg + def ButtonconvertionXCUBE(val): kwarg = {} val = str(val) @@ -775,6 +797,38 @@ def ButtonconvertionXCUBE(val): return kwarg +def ButtonconvertionXCUBET1(val, gesture): + kwarg = {} + gest = int(gesture) + face = str(val) + v = 0 + + if gest == 0: # wake + v = 20 + elif gest == 1: # shake + v = 10 + elif gest == 2: # Drop + v = 30 + elif gest == 3: # 90 flip + v = 40 + elif gest == 4: # 180 flip + v = 50 + elif gest == 5: # push + v = 60 + elif gest == 6: # double tap + v = 70 + else: # Unknown + v = 0 + + if v == 0: + kwarg['sValue'] = 'Off' + else: + kwarg['sValue'] = str( v ) + + kwarg['nValue'] = v + + return kwarg + # <=4002 >=5002 +=2002 -=3002 4001/5001/2001/3001 def ButtonconvertionTradfriRemote(val): kwarg = {} diff --git a/icons/batterylevelempty_icons.zip b/icons/batterylevelempty_icons.zip new file mode 100644 index 0000000..d22949f Binary files /dev/null and b/icons/batterylevelempty_icons.zip differ diff --git a/icons/batterylevelfull_icons.zip b/icons/batterylevelfull_icons.zip new file mode 100644 index 0000000..474d66d Binary files /dev/null and b/icons/batterylevelfull_icons.zip differ diff --git a/icons/batterylevellow_icons.zip b/icons/batterylevellow_icons.zip new file mode 100644 index 0000000..9c1aa4b Binary files /dev/null and b/icons/batterylevellow_icons.zip differ diff --git a/icons/batterylevelok_icons.zip b/icons/batterylevelok_icons.zip new file mode 100644 index 0000000..0f87fb6 Binary files /dev/null and b/icons/batterylevelok_icons.zip differ diff --git a/plugin.py b/plugin.py index 51ac26a..07809b0 100644 --- a/plugin.py +++ b/plugin.py @@ -3,7 +3,7 @@ # Author: Smanar # """ - +

deCONZ Bridge


@@ -64,6 +64,7 @@ from fonctions import rgb_to_xy, rgb_to_hsv, xy_to_rgb from fonctions import Count_Type, ProcessAllState, ProcessAllConfig, First_Json, JSON_Repair, get_JSON_payload from fonctions import ButtonconvertionXCUBE, ButtonconvertionXCUBE_R, ButtonconvertionTradfriRemote, ButtonconvertionTradfriSwitch +from fonctions import ButtonconvertionXCUBET1, ButtonconvertionXCUBET1_R from fonctions import ButtonConvertion, VibrationSensorConvertion from fonctions import installFE, uninstallFE from widget import Createdatawidget @@ -134,8 +135,23 @@ def onStart(self): Domoticz.Status("Enabling special setting ENABLEBATTERYWIDGET") global ENABLEBATTERYWIDGET ENABLEBATTERYWIDGET = True - self.SpecialDeviceList = self.SpecialDeviceList + ["current", "voltage"] + #Custom icon files for battery level + #https://github.com/999LV/BatteryLevel + icons = {"batterylevelfull": "icons/batterylevelfull_icons.zip", + "batterylevelok": "icons/batterylevelok_icons.zip", + "batterylevellow": "icons/batterylevellow_icons.zip", + "batterylevelempty": "icons/batterylevelempty_icons.zip"} + + # load custom battery images + for key, value in icons.items(): + if key not in Images: + Domoticz.Image(value).Create() + Domoticz.Status("Added icon: " + key + " from file " + value) + Domoticz.Status("Number of icons loaded = " + str(len(Images))) + for image in Images: + Domoticz.Log("Icon " + str(Images[image].ID) + " " + Images[image].Name) + #Read banned devices try: with open(Parameters["HomeFolder"]+"banned_devices.txt", 'r') as myPluginConfFile: @@ -626,7 +642,27 @@ def InitDomoticzDB(self,key,_Data,Type_device): #ignore ZHASwitch if vibration sensor if 'sensitivity' in ConfigList: return - if 'lumi.sensor_cube' in Model: + #Used by Xiaomi Cube T1 + if 'lumi.remote.cagl01' in Model: + if IEEE.endswith('-03-000c'): + Type = 'XCubeT1_R' + elif IEEE.endswith('-02-0012'): + Type = 'XCubeT1_C' + else: + # Useless device + self.Devices[IEEE]['state'] = 'banned' + return + #Used by Xiaomi Cube T1 Pro + elif 'lumi.remote.cagl02' in Model: + if IEEE.endswith('-03-000c'): + Type = 'XCubeT1_R' + elif IEEE.endswith('-02-0012'): + Type = 'XCubeT1_C' + else: + # Useless device + self.Devices[IEEE]['state'] = 'banned' + return + elif 'lumi.sensor_cube' in Model: if IEEE.endswith('-03-000c'): Type = 'XCube_R' elif IEEE.endswith('-02-0012'): @@ -723,7 +759,7 @@ def InitDomoticzDB(self,key,_Data,Type_device): #Create the current device self.CreateIfnotExist(IEEE,'ZHADoorLock',Name) # power and consumption on the same endpoint - elif Model == 'ZHEMI101' or Model == 'TH1124ZB' or Model == '45856' or Model == 'E1C-NB7': + elif Model == 'ZHEMI101' or Model == 'TH1124ZB' or Model == 'OTH4000-ZB' or Model == '45856' or Model == 'E1C-NB7': self.Devices[IEEE]['option'] = 1 self.CreateIfnotExist(IEEE,Type,Name,1) else: @@ -974,6 +1010,10 @@ def WebSocketConnexion(self,_Data): kwarg.update(ButtonconvertionXCUBE(state['buttonevent']) ) elif model == 'XCube_R': kwarg.update(ButtonconvertionXCUBE_R(state['buttonevent']) ) + elif model == 'XCubeT1_C': + kwarg.update(ButtonconvertionXCUBET1(state['buttonevent'], state['gesture']) ) + elif model == 'XCubeT1_R': + kwarg.update(ButtonconvertionXCUBET1_R(state['buttonevent']) ) elif model == 'Tradfri_remote': kwarg.update(ButtonconvertionTradfriRemote(state['buttonevent']) ) elif model == 'Tradfri_on/off_switch': @@ -1399,7 +1439,16 @@ def UpdateDeviceProc(kwarg,Unit): NewIEE = Devices[Unit].DeviceID.split("-")[0] Unit2 = GetDomoDeviceInfo(NewIEE + '_battery') if Unit2 and getattr(Devices[Unit2],'BatteryLevel') != kwarg['BatteryLevel']: - kwarg2 = {"nValue":0, "sValue":str(kwarg["BatteryLevel"])} + levelBatt=kwarg['BatteryLevel'] + if levelBatt >= 75: + icon = "batterylevelfull" + elif levelBatt >= 50: + icon = "batterylevelok" + elif levelBatt >= 25: + icon = "batterylevellow" + else: + icon = "batterylevelempty" + kwarg2 = {"nValue":0, "sValue":str(kwarg["BatteryLevel"]),"Image":Images[icon].ID} Devices[Unit2].Update(**kwarg2) Domoticz.Debug("### Update special device ("+NewIEE+") : " + str(kwarg)) diff --git a/widget.py b/widget.py index 35631b8..f4e3fa9 100644 --- a/widget.py +++ b/widget.py @@ -255,6 +255,10 @@ def Createdatawidget(IEEE, _Name, _Type, opt): kwarg['TypeName'] = 'Custom' kwarg['Options'] = {"Custom": ("1;degree")} + elif _Type == 'ZHARelativeRotary': + kwarg['TypeName'] = 'Custom' + kwarg['Options'] = {"Custom": ("1;degree")} + elif _Type == 'Thermostat_Mode': kwarg['Type'] = 244 kwarg['Subtype'] = 62