Skip to content

Commit

Permalink
Merge branch 'wip-develop' into stable7
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed May 13, 2024
2 parents 5fea01e + 5d42ad4 commit d2a56c8
Show file tree
Hide file tree
Showing 185 changed files with 7,697 additions and 6,721 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Data/zigatePDM-*
Data/ZigateGroupsConfig**
Data/Zigate.json
Data/*.backup**
Data/zigpy_persistent**
www/zigate/reports/*
Logs/*
Reports/*
Expand Down
2 changes: 1 addition & 1 deletion .hidden/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"branch": "stable7", "version": "7.1.011"}
{"branch": "wip-develop", "version": "7.2.094"}
151 changes: 56 additions & 95 deletions Classes/AdminWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"""

import Domoticz
from datetime import datetime
from Modules.domoticzAbstractLayer import (
FreeUnit, domo_create_api, domo_read_nValue_sValue, domo_update_api,
domoticz_error_api, find_first_unit_widget_from_deviceID)

DEVICEID_ADMIN_WIDGET = "Zigate-01-"
DEVICEID_STATUS_WIDGET = "Zigate-02-"
Expand All @@ -21,91 +22,63 @@
DEVICEID_TXT_WIDGET_TXT = "Zigate Notifications"


def _get_switch_selector_options(self, ):
if self.pluginconf.pluginConf["eraseZigatePDM"]:
return {
"LevelActions": "|||||||",
"LevelNames": "Off|Purge Reports|Soft Reset|One Time Enrollment|Perm. Enrollment|Interf Scan|LQI Report|Erase PDM",
"LevelOffHidden": "true",
"SelectorStyle": "0",
}

return {
"LevelActions": "|||||||",
"LevelNames": "Off|Purge Reports|Soft Reset|One Time Enrolmennt|Perm. Enrollment|Interf Scan|LQI Report",
"LevelOffHidden": "true",
"SelectorStyle": "0",
}

class AdminWidgets:
def __init__(self, PluginConf, Devices, ListOfDevices, HardwareID):
def __init__(self, log, PluginConf, pluginParameters, ListOfDomoticzWidget, Devices, ListOfDevices, HardwareID):

self.pluginconf = PluginConf
self.pluginParameters = pluginParameters
self.ListOfDomoticzWidget = ListOfDomoticzWidget
self.Devices = Devices # Point to the List of Domoticz Devices
self.ListOfDevices = ListOfDevices # Point to the Global ListOfDevices
self.HardwareID = HardwareID
self.log = log
self.createStatusWidget(Devices)
self.createNotificationWidget(Devices)
# createAdminWidget( self, Devices )

def FreeUnit(self, Devices):
"""
FreeUnit
Look for a Free Unit number.
"""
for x in range(1, 255):
if x not in Devices:
return x

return len(Devices) + 1

def createAdminWidget(self, Devices):

deviceid_admin_widget = DEVICEID_ADMIN_WIDGET + "%02s" % self.HardwareID
unit = 0
for x in Devices:
if Devices[x].DeviceID == deviceid_admin_widget:
unit = x
break
if unit != 0:

if find_first_unit_widget_from_deviceID(self, Devices, deviceid_admin_widget ):
return

if self.pluginconf.pluginConf["eraseZigatePDM"]:
Options = {
"LevelActions": "|||||||",
"LevelNames": "Off|Purge Reports|Soft Reset|One Time Enrollment|Perm. Enrollment|Interf Scan|LQI Report|Erase PDM",
"LevelOffHidden": "true",
"SelectorStyle": "0",
}
else:
Options = {
"LevelActions": "|||||||",
"LevelNames": "Off|Purge Reports|Soft Reset|One Time Enrolmennt|Perm. Enrollment|Interf Scan|LQI Report",
"LevelOffHidden": "true",
"SelectorStyle": "0",
}

unit = self.FreeUnit(Devices)
widget_name = DEVICEID_ADMIN_WIDGET_TXT + " %02s" % self.HardwareID
myDev = Domoticz.Device(
DeviceID=deviceid_admin_widget,
Name=widget_name,
Unit=unit,
Type=244,
Subtype=62,
Switchtype=18,
Options=Options,
)
myDev.Create()
ID = myDev.ID
if myDev.ID == -1:
Domoticz.Error("createAdminWidget - Fail to create %s. %s" % (widget_name, str(myDev)))
unit = FreeUnit(self, Devices, deviceid_admin_widget, nbunit_=1)
ID = domo_create_api(self, Devices, deviceid_admin_widget, unit, widget_name, Type_=244, Subtype_=62, Switchtype_=18, widgetOptions=_get_switch_selector_options(self))
if ID == -1:
domoticz_error_api("createAdminWidget - Fail to create %s." % (widget_name))
return

def createStatusWidget(self, Devices):

deviceid_status_widget = DEVICEID_STATUS_WIDGET + "%02s" % self.HardwareID
unit = 0
for x in Devices:
if Devices[x].DeviceID == deviceid_status_widget:
unit = x
break
if unit != 0:

if find_first_unit_widget_from_deviceID(self, Devices, deviceid_status_widget):
return

unit = self.FreeUnit(Devices)
unit = FreeUnit(self, Devices, deviceid_status_widget, nbunit_=1)
widget_name = DEVICEID_STATUS_WIDGET_TXT + " %02s" % self.HardwareID
myDev = Domoticz.Device(
DeviceID=deviceid_status_widget, Name=widget_name, Unit=unit, Type=243, Subtype=22, Switchtype=0
)
myDev.Create()
ID = myDev.ID
if myDev.ID == -1:
Domoticz.Error("createAdminWidget - Fail to create %s. %s" % (widget_name, str(myDev)))
ID = domo_create_api(self, Devices, deviceid_status_widget, unit, widget_name, Type_=243, Subtype_=22, Switchtype_=0,)

if ID == -1:
domoticz_error_api("createAdminWidget - Fail to create %s." % (widget_name))
return

self.updateStatusWidget(Devices, "Off")
Expand All @@ -114,23 +87,14 @@ def createStatusWidget(self, Devices):
def createNotificationWidget(self, Devices):

deviceid_txt_widget = DEVICEID_TXT_WIDGET + "%02s" % self.HardwareID
unit = 0
for x in Devices:
if Devices[x].DeviceID == deviceid_txt_widget:
unit = x
break
if unit != 0:
if find_first_unit_widget_from_deviceID(self, Devices, deviceid_txt_widget ):
return

unit = self.FreeUnit(Devices)
unit = FreeUnit(self, Devices, deviceid_txt_widget, nbunit_=1)
widget_name = DEVICEID_TXT_WIDGET_TXT + " %02s" % self.HardwareID
myDev = Domoticz.Device(
DeviceID=deviceid_txt_widget, Name=widget_name, Unit=unit, Type=243, Subtype=19, Switchtype=0
)
myDev.Create()
ID = myDev.ID
if myDev.ID == -1:
Domoticz.Error("createNotificationWidget - Fail to create %s. %s" % (widget_name, str(myDev)))
ID = domo_create_api(self, Devices, deviceid_txt_widget, unit, widget_name, Type_=243, Subtype_=19, Switchtype_=0,)
if ID == -1:
domoticz_error_api("createNotificationWidget - Fail to create %s." % (widget_name))
return

return
Expand All @@ -147,42 +111,39 @@ def handleAdminWidget(self, Devices, Unit, Command, Color):
return

def updateStatusWidget(self, Devices, statusType):

STATUS_WIDGET = {"No Communication": 4, "Startup": 0, "Ready": 1, "Enrollment": 3, "Busy": 3}

deviceid_status_widget = DEVICEID_STATUS_WIDGET + "%02s" % self.HardwareID
if statusType not in STATUS_WIDGET:
return

unit = 0
for x in Devices:
if Devices[x].DeviceID == deviceid_status_widget:
unit = x
break
if unit == 0:
unit = find_first_unit_widget_from_deviceID(self, Devices, deviceid_status_widget )
if not unit:
return

nValue = STATUS_WIDGET[statusType]
sValue = str(statusType)
if sValue != Devices[unit].sValue:
Devices[unit].Update(nValue=nValue, sValue=sValue)

_, cur_svalue = domo_read_nValue_sValue(self, Devices, deviceid_status_widget, unit)

if sValue != cur_svalue:
domo_update_api(self, Devices, deviceid_status_widget, unit, nValue, sValue)

return

def updateNotificationWidget(self, Devices, notification):
deviceid_txt_widget = DEVICEID_TXT_WIDGET + "%02s" % self.HardwareID
unit = 0
for x in Devices:
if Devices[x].DeviceID == deviceid_txt_widget:
unit = x
break
if unit == 0:
unit = find_first_unit_widget_from_deviceID(self, Devices, deviceid_txt_widget )
if not unit:
return

nValue = 0
_, cur_svalue = domo_read_nValue_sValue(self, Devices, deviceid_txt_widget, unit)

sValue = str(notification)
if sValue != Devices[unit].sValue:
Devices[unit].Update(nValue=nValue, sValue=sValue)
if sValue != cur_svalue:
domo_update_api(self, Devices, deviceid_txt_widget, unit, 0, sValue)

def handleCommand(self, Command):
return


5 changes: 3 additions & 2 deletions Classes/DomoticzDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import time
import urllib.request
import ssl
import Domoticz

from Modules.restartPlugin import restartPluginViaDomoticzJsonApi
from Classes.LoggingManagement import LoggingManagement
Expand Down Expand Up @@ -330,7 +329,9 @@ def extract_AddValue(self, ID, attribute):
result = self.get_device_status( ID)
if result is None:
return 0


if 'result' not in result:
return 0
AdjValue = 0
for x in result['result']:
AdjValue = x[attribute]
Expand Down
57 changes: 26 additions & 31 deletions Classes/GroupMgtv2/GroupManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,55 +50,44 @@
# - Managing device short address changes ( could be better to store the IEEE )
#

import os
import json
import os
import pickle

import Domoticz

from Classes.GroupMgtv2.GrpServices import scan_device_for_grp_membership
from Classes.GroupMgtv2.GrpMigration import GrpMgtv2Migration
from Modules.zigateConsts import MAX_LOAD_ZIGATE
from Classes.GroupMgtv2.GrpServices import scan_device_for_grp_membership
from Classes.LoggingManagement import LoggingManagement
from Modules.zigateConsts import MAX_LOAD_ZIGATE


class GroupsManagement(object):

from Classes.GroupMgtv2.GrpDatabase import (load_groups_list_from_json,
update_due_to_nwk_id_change,
write_groups_list)
from Classes.GroupMgtv2.GrpDomoticz import (processCommand,
update_domoticz_group_device)
from Classes.GroupMgtv2.GrpIkeaRemote import \
manageIkeaTradfriRemoteLeftRight
from Classes.GroupMgtv2.GrpResponses import (
statusGroupRequest,
remove_group_member_ship_response,
look_for_group_member_ship_response,
check_group_member_ship_response,
add_group_member_ship_response,
)

from Classes.GroupMgtv2.GrpDomoticz import update_domoticz_group_device, processCommand
from Classes.GroupMgtv2.GrpDatabase import (
write_groups_list,
load_groups_list_from_json,
update_due_to_nwk_id_change,
)
add_group_member_ship_response, check_group_member_ship_response,
look_for_group_member_ship_response, remove_group_member_ship_response,
statusGroupRequest)
from Classes.GroupMgtv2.GrpServices import (
FullRemoveOfGroup,
checkAndTriggerIfMajGroupNeeded,
addGroupMemberShip,
RemoveNwkIdFromAllGroups,
get_available_grp_id,
add_group_member_ship_from_remote,
)
FullRemoveOfGroup, RemoveNwkIdFromAllGroups,
add_group_member_ship_from_remote, addGroupMemberShip,
checkAndTriggerIfMajGroupNeeded, get_available_grp_id)
from Classes.GroupMgtv2.GrpWebServices import (
process_web_request,
ScanAllDevicesForGroupMemberShip,
ScanDevicesForGroupMemberShip,
)
from Classes.GroupMgtv2.GrpIkeaRemote import manageIkeaTradfriRemoteLeftRight
ScanAllDevicesForGroupMemberShip, ScanDevicesForGroupMemberShip,
process_web_request)

def __init__(
self,
zigbee_communitation,
VersionNewFashion,
DomoticzMajor,
DomoticzMinor,
DomoticzBuild,
PluginConf,
ZigateComm,
adminWidgets,
Expand All @@ -107,9 +96,11 @@ def __init__(
Devices,
ListOfDevices,
IEEE2NWK,
ListOfDomoticzWidget,
DeviceConf,
log,
readZclClusters
readZclClusters,
pluginParameters
):
self.zigbee_communication = zigbee_communitation
self.HB = 0
Expand All @@ -131,7 +122,11 @@ def __init__(
self.VersionNewFashion = VersionNewFashion
self.DomoticzMajor = DomoticzMajor
self.DomoticzMinor = DomoticzMinor
self.DomoticzBuild = DomoticzBuild
self.readZclClusters = readZclClusters
self.pluginParameters = pluginParameters
self.ListOfDomoticzWidget = ListOfDomoticzWidget

# Check if we have to open the old format
if os.path.isfile(self.pluginconf.pluginConf["pluginData"] + "/GroupsList-%02d.pck" % hardwareID):
# We are in the Migration from Old Group Managemet to new.
Expand Down
Loading

0 comments on commit d2a56c8

Please sign in to comment.