Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polling widget #1766

Merged
merged 7 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions Classes/WebServer/rest_recreateWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Author: zaraki673 & pipiche38
#
from time import time
import json

from Classes.WebServer.headerResponse import (prepResponseMessage,
setupHeadersResponse)
Expand Down Expand Up @@ -31,7 +32,8 @@ def rest_recreate_widgets(self, verb, data, parameters):

if "IEEE" not in data and "NWKID" not in data:
domoticz_error_api("rest_recreate_widgets - unexpected parameter %s " % parameters)
_response["Data"] = {"unexpected parameter %s " % parameters}
_response["Data"] = json.dumps({"Status": "Error", "Description": "unexpected parameter %s " % parameters})

return _response

if "IEEE" in data:
Expand All @@ -40,13 +42,13 @@ def rest_recreate_widgets(self, verb, data, parameters):
domoticz_error_api("rest_recreate_widgets - Unknown device %s " % key)
return _response
nwkid = self.IEEE2NWK[key]
_response["Data"] = {"IEEE %s set to Provisioning Requested at %s" % (key, int(time()))}
_response["Data"] = json.dumps({"Status": "Ok", "Status": "IEEE %s set to Provisioning Requested at %s" % (key, int(time()))})
else:
nwkid = data["NWKID"]
if nwkid not in self.ListOfDevices:
domoticz_error_api("rest_recreate_widgets - Unknown device %s " % nwkid)
return _response
_response["Data"] = {"NwkId %s set to Provisioning Requested at %s" % (nwkid, int(time()))}
_response["Data"] = json.dumps({"Status": "Ok", "Status": "NwkId %s set to Provisioning Requested at %s" % (nwkid, int(time()))})

over_write_type_from_deviceconf( self, self.Devices, nwkid)
self.ListOfDevices[nwkid]["Status"] = "CreateDB"
Expand Down
19 changes: 16 additions & 3 deletions Modules/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
tuya_dimmer_dimmer, tuya_dimmer_onoff,
tuya_energy_onoff, tuya_garage_door_action,
tuya_switch_command, tuya_watertimer_command,
tuya_window_cover_calibration)
tuya_window_cover_calibration, tuya_polling_control)
from Modules.tuyaSiren import (tuya_siren2_trigger, tuya_siren_alarm,
tuya_siren_humi_alarm, tuya_siren_temp_alarm)
from Modules.tuyaTRV import (tuya_coil_fan_thermostat, tuya_fan_speed,
Expand Down Expand Up @@ -140,7 +140,8 @@
"ThermoOnOff",
"ShutterCalibration",
"SwitchAlarm",
"TamperSwitch"
"TamperSwitch",
"PollingControl",
]


Expand Down Expand Up @@ -325,7 +326,7 @@ def handle_command_off(self,Devices, DeviceID, Unit, Level, Nwkid, EPout, Device
request_read_device_status(self, Nwkid)
return

if DeviceType == ("ThermoMode_2", ):
if DeviceType in ("ThermoMode_2", ):
self.log.logging("Command", "Debug", f"handle_command_off : Set Level for Device: {Nwkid} EPout: {EPout} Unit: {Unit} DeviceType: {DeviceType} Level: {Level}", Nwkid)

if ts0601_extract_data_point_infos( self, model_name):
Expand All @@ -335,6 +336,12 @@ def handle_command_off(self,Devices, DeviceID, Unit, Level, Nwkid, EPout, Device
tuya_trv_mode(self, Nwkid, 0)
update_domoticz_widget(self, Devices, DeviceID, Unit, 0, "Off", BatteryLevel, SignalLevel, ForceUpdate_=forceUpdateDev)
return

if DeviceType in ("PollingControl", ):
self.log.logging("Command", "Log", f"handle_command_off : PollingControl Set Level for Device: {Nwkid} EPout: {EPout} Unit: {Unit} DeviceType: {DeviceType} Level: {Level}", Nwkid)
tuya_polling_control(self, Nwkid, Level)
update_domoticz_widget(self, Devices, DeviceID, Unit, 0, "Off", BatteryLevel, SignalLevel, ForceUpdate_=forceUpdateDev)
return

if DeviceType in ("ThermoMode_4", "ThermoMode_5", "ThermoMode_6", "ThermoMode_7"):
self.log.logging("Command", "Debug", f"handle_command_off : Set Level for Device: {Nwkid} EPout: {EPout} Unit: {Unit} DeviceType: {DeviceType} Level: {Level}", Nwkid)
Expand Down Expand Up @@ -839,6 +846,12 @@ def handle_command_setlevel(self,Devices, DeviceID, Unit, Level, Nwkid, EPout, D
update_domoticz_widget(self, Devices, DeviceID, Unit, int(Level // 10), Level, BatteryLevel, SignalLevel, ForceUpdate_=forceUpdateDev )
return

if DeviceType in ("PollingControl", ):
self.log.logging("Command", "Log", f"handle_command_setlevel : PollingControl Set Level for Device: {Nwkid} EPout: {EPout} Unit: {Unit} DeviceType: {DeviceType} Level: {Level}", Nwkid)
tuya_polling_control(self, Nwkid, Level)
update_domoticz_widget(self, Devices, DeviceID, Unit, int(Level // 10), Level, BatteryLevel, SignalLevel, ForceUpdate_=forceUpdateDev )
return

if DeviceType == "ThermoMode_4":
self.log.logging(
"Command",
Expand Down
13 changes: 13 additions & 0 deletions Modules/switchSelectorWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,19 @@
"01": (1, "On"),
"ForceUpdate": False
},
"PollingControl": {
"00": (0, "00"),
"01": (1, "10"),
"02": (2, "20"),
"ForceUpdate": False,
"SelectorStyle": 1,
"LevelNames": "Off|Slow Polling|Fast Polling",
"Language": {
"fr-FR": {
"LevelNames": "Arrêt|Mesures normale|Mesures rapides"
}
}
},
"SOS": {
"01": (1, "On"),
"ForceUpdate": True
Expand Down
36 changes: 31 additions & 5 deletions Modules/tuya.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,29 @@ def tuya_cmd_ts004F(self, NwkId, mode):


def tuya_cmd_0x0000_0xf0(self, NwkId):

# Seen at pairing of a WGH-JLCZ02 / TS011F and TS0201 and TS0601 (MOES BRT-100)

payload = "11" + get_and_inc_ZCL_SQN(self, NwkId) + "fe"
raw_APS_request( self, NwkId, '01', "0000", "0104", payload, zigate_ep=ZIGATE_EP, ackIsDisabled=is_ack_tobe_disabled(self, NwkId), )
self.log.logging("Tuya", "Debug", "tuya_cmd_0x0000_0xf0 - Nwkid: %s reset device Cmd: fe" % NwkId)


def tuya_polling_control(self, Nwkid, Level):
# Mapping Level to Polling modes
polling_modes = {0: "Off", 10: "Normal Polling", 20: "Fast Polling"}

self.log.logging("Tuya", "Log", f"tuya_polling_control - Nwkid: {Nwkid}/01 Level {Level}")

# Set default Tuya device info and polling mode
tuya_device_info = self.ListOfDevices.setdefault(Nwkid, {}).setdefault("Tuya", {})
tuya_device_info["Polling"] = polling_modes.get(Level, tuya_device_info.get("Polling", "Normal Polling"))

self.log.logging("Tuya", "Log", f"tuya_polling_control - Nwkid: {Nwkid}/01 Polling Mode {tuya_device_info['Polling']}")


def tuya_polling(self, nwkid):
"""Some Tuya devices, requirea specific polling"""

device_model = self.ListOfDevices.get(nwkid, {}).get("Model")
if device_model is None:
return False
Expand All @@ -160,6 +173,23 @@ def tuya_polling(self, nwkid):
# Each consecutive polling must be separated by 15s by default
tuya_elapse_time_consecutive_polling = get_deviceconf_parameter_value(self, device_model, "TUYA_DATA_REQUEST_POLLING_CONSECUTIVE_ELAPSE", return_default=15)

# Retrieve the device information
tuya_device_info = self.ListOfDevices.setdefault(nwkid, {}).setdefault("Tuya", {})
additional_polls = tuya_device_info.get("AdditionalPolls", tuya_data_request_polling_additional)

polling_status = tuya_device_info.setdefault("Polling", "Off")

if polling_status == "Off":
# No polling , just exit
return

elif polling_status == "Fast Polling":
# Force polling to every 15s
tuya_data_request_polling = 10
tuya_data_query = 60 # A query ( 0x03 ) every minutes
tuya_data_request_polling_additional = 0
tuya_elapse_time_consecutive_polling = 5

self.log.logging("Tuya", "Debug", f"tuya_polling - Nwkid: {nwkid}/01 tuya_data_request_polling {tuya_data_request_polling}")
self.log.logging("Tuya", "Debug", f"tuya_polling - Nwkid: {nwkid}/01 tuya_data_query {tuya_data_query}")
self.log.logging("Tuya", "Debug", f"tuya_polling - Nwkid: {nwkid}/01 tuya_data_request_polling_additional {tuya_data_request_polling_additional}")
Expand All @@ -176,10 +206,6 @@ def tuya_polling(self, nwkid):
elif current_battery_level and current_battery_level < 50:
tuya_data_request_polling *= 6

# Retrieve the device information
tuya_device_info = self.ListOfDevices.setdefault(nwkid, {}).setdefault("Tuya", {})
additional_polls = tuya_device_info.get("AdditionalPolls", tuya_data_request_polling_additional)

self.log.logging("Tuya", "Debug", f"tuya_polling - Nwkid: {nwkid}/01 AdditionalPolls {additional_polls}")

if tuya_data_query and should_poll(self, nwkid, tuya_device_info, "LastTuyaDataQuery", polling_interval=tuya_data_query):
Expand Down
Loading