Skip to content

Commit

Permalink
Merge pull request #155 from Smanar/beta
Browse files Browse the repository at this point in the history
Version 28
  • Loading branch information
Smanar committed May 24, 2023
2 parents 1e13715 + cbfb6e7 commit 9cbaa81
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 7 deletions.
58 changes: 56 additions & 2 deletions fonctions.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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']))

Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {}
Expand Down
Binary file added icons/batterylevelempty_icons.zip
Binary file not shown.
Binary file added icons/batterylevelfull_icons.zip
Binary file not shown.
Binary file added icons/batterylevellow_icons.zip
Binary file not shown.
Binary file added icons/batterylevelok_icons.zip
Binary file not shown.
59 changes: 54 additions & 5 deletions plugin.py
Expand Up @@ -3,7 +3,7 @@
# Author: Smanar
#
"""
<plugin key="deCONZ" name="deCONZ plugin" author="Smanar" version="1.0.27" wikilink="https://github.com/Smanar/Domoticz-deCONZ" externallink="https://phoscon.de/en/conbee2">
<plugin key="deCONZ" name="deCONZ plugin" author="Smanar" version="1.0.28" wikilink="https://github.com/Smanar/Domoticz-deCONZ" externallink="https://phoscon.de/en/conbee2">
<description>
<br/><br/>
<h2>deCONZ Bridge</h2><br/>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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))

Expand Down
4 changes: 4 additions & 0 deletions widget.py
Expand Up @@ -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
Expand Down

0 comments on commit 9cbaa81

Please sign in to comment.