Skip to content

Commit

Permalink
Adding PowerFactor handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiche38 committed Nov 3, 2023
1 parent 22043f8 commit 2032411
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions Modules/domoCreate.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def set_default_value( self, Devices, unit, widget_record):
"Alarm_ZL2": { "Type": 243, "Subtype": 22, "Switchtype": 0, },
"Alarm_ZL3": { "Type": 243, "Subtype": 22, "Switchtype": 0, },
"AirPurifierAlarm": { "Type": 243, "Subtype": 22, "Switchtype": 0, },
"PowerFactor": { "Type": 243, "Subtype": 6, "Switchtype": 0, },
"Valve": { "Type": 243, "Subtype": 6, "Switchtype": 0, },
"FanSpeed": { "Type": 243, "Subtype": 6, "Switchtype": 0, },
"ThermoSetpoint": { "Type": 242, "Subtype": 1, },
Expand Down
16 changes: 9 additions & 7 deletions Modules/domoMaj.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,15 @@ def MajDomoDevice(self, Devices, NWKID, Ep, clusterID, value, Attribute_="", Col
data = "09"
UpdateDevice_v2(self, Devices, DeviceUnit, int(data), str(state), BatteryLevel, SignalLevel, ForceUpdate_=True)

if "Valve" in ClusterType: # Valve Position
if WidgetType == "Valve" and Attribute_ in ("026d", "4001", "0008"):
# value int is the % of the valve opening
# Percentage Widget
nValue = round(value, 1)
sValue = str(nValue)
UpdateDevice_v2(self, Devices, DeviceUnit, nValue, sValue, BatteryLevel, SignalLevel)
if "Valve" in ClusterType and (WidgetType == "Valve" and Attribute_ in ("026d", "4001", "0008")):
nValue = round(value, 1)
sValue = str(nValue)
UpdateDevice_v2(self, Devices, DeviceUnit, nValue, sValue, BatteryLevel, SignalLevel)

if "PowerFactor" in ClusterType and WidgetType == "PowerFactor":
nValue = round(value, 1)
sValue = str(nValue)
UpdateDevice_v2(self, Devices, DeviceUnit, nValue, sValue, BatteryLevel, SignalLevel)

if "ThermoMode" in ClusterType: # Thermostat Mode
self.log.logging("Widget", "Debug", "ThermoMode %s WidgetType: %s Value: %s (%s) Attribute_: %s" % (
Expand Down
3 changes: 2 additions & 1 deletion Modules/domoTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ def GetType(self, Addr, Ep):
"fc80": "Heiman",
"Distance": "Distance",
"TamperSwitch": "TamperSwitch",
"Notification": "Notification"
"Notification": "Notification",
"PowerFactor": "PowerFactor"
}

def TypeFromCluster(self, cluster, create_=False, ProfileID_="", ZDeviceID_="", ModelName=""):
Expand Down
17 changes: 11 additions & 6 deletions Modules/tuyaTS0601.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,13 @@ def ts0601_current(self, Devices, nwkid, ep, value):
self.log.logging( "Tuya0601", "Debug", "ts0601_current - Current %s %s %s" % (nwkid, ep, value), nwkid, )
MajDomoDevice(self, Devices, nwkid, ep, "0b04", value, Attribute_="0508")
checkAndStoreAttributeValue(self, nwkid, ep, "0b04", "0508", value) # Store int
store_tuya_attribute(self, nwkid, "Current", value)

store_tuya_attribute(self, nwkid, "Current_%s" %ep, value)

def ts0601_power_factor(self, Devices, nwkid, ep, value):
self.log.logging( "Tuya0601", "Debug", "ts0601_current - Current %s %s %s" % (nwkid, ep, value), nwkid, )
MajDomoDevice(self, Devices, nwkid, ep, "PowerFactor", value)
store_tuya_attribute(self, nwkid, "PowerFactor_%s" %ep, value)

def ts0601_summation_energy(self, Devices, nwkid, ep, value):
self.log.logging( "Tuya0601", "Debug", "ts0601_summation_energy - Current Summation %s %s %s" % (nwkid, ep, value), nwkid, )
previous_summation = getAttributeValue(self, nwkid, ep, "0702", "0000")
Expand All @@ -314,19 +318,19 @@ def ts0601_summation_energy(self, Devices, nwkid, ep, value):
nwkid, ep, value, previous_summation, current_summation), nwkid, )
MajDomoDevice(self, Devices, nwkid, ep, "0702", current_summation, Attribute_="0000")
checkAndStoreAttributeValue(self, nwkid, ep, "0702", "0000", current_summation) # Store int
store_tuya_attribute(self, nwkid, "Energy", value)
store_tuya_attribute(self, nwkid, "Energy_%s" %ep, value)

def ts0601_summation_energy_raw(self, Devices, nwkid, ep, value):
self.log.logging( "Tuya0601", "Debug", "ts0601_summation_energy - Current Summation %s %s %s" % (nwkid, ep, value), nwkid, )
MajDomoDevice(self, Devices, nwkid, ep, "0702", value, Attribute_="0000")
checkAndStoreAttributeValue(self, nwkid, ep, "0702", "0000", value) # Store int
store_tuya_attribute(self, nwkid, "ConsumedEnergy", value)
store_tuya_attribute(self, nwkid, "ConsumedEnergy_%s" %ep, value)

def ts0601_production_energy(self, Devices, nwkid, ep, value):
self.log.logging( "Tuya0601", "Debug", "ts0601_production_energy - Production Energy %s %s %s" % (nwkid, ep, value), nwkid, )
MajDomoDevice(self, Devices, nwkid, ep, "0702", value, Attribute_="0001")
checkAndStoreAttributeValue(self, nwkid, ep, "0702", "0001", value) # Store int
store_tuya_attribute(self, nwkid, "ProducedEnergy", value)
store_tuya_attribute(self, nwkid, "ProducedEnergy_%s" %ep, value)


def ts0601_instant_power(self, Devices, nwkid, ep, value):
Expand All @@ -338,7 +342,7 @@ def ts0601_instant_power(self, Devices, nwkid, ep, value):

checkAndStoreAttributeValue(self, nwkid, ep, "0702", "0400", signed_int)
MajDomoDevice(self, Devices, nwkid, ep, "0702", signed_int)
store_tuya_attribute(self, nwkid, "InstantPower", signed_int) # Store str
store_tuya_attribute(self, nwkid, "InstantPower_%s" %ep, signed_int) # Store str

def ts0601_voltage(self, Devices, nwkid, ep, value):
self.log.logging( "Tuya0601", "Debug", "ts0601_voltage - Voltage %s %s %s" % (nwkid, ep, value), nwkid, )
Expand Down Expand Up @@ -498,6 +502,7 @@ def ts0601_sensor_irrigation_mode(self, Devices, nwkid, ep, value):
"smoke_state": ts0601_smoke_detection,
"smoke_ppm": ts0601_smoke_concentration,
"water_consumption": ts0601_water_consumption,
"power_factor": ts0601_power_factor,
}

def ts0601_tuya_cmd(self, NwkId, Ep, action, data):
Expand Down

0 comments on commit 2032411

Please sign in to comment.