mirror of https://github.com/arendst/Tasmota.git
introduced "inverted" setting (#18607)
ensure that matter support still works if the "inverted" flag is set on the shutter side
This commit is contained in:
parent
aac1b08074
commit
ffedb96702
|
@ -43,6 +43,7 @@ class Matter_Plugin_Shutter : Matter_Plugin_Device
|
|||
var shadow_shutter_target
|
||||
var shadow_shutter_tilt
|
||||
var shadow_shutter_direction # 1=opening -1=closing 0=not moving TODO
|
||||
var shadow_shutter_inverted # 1=same as matter 0=matter must invert
|
||||
|
||||
#############################################################
|
||||
# Constructor
|
||||
|
@ -50,12 +51,34 @@ class Matter_Plugin_Shutter : Matter_Plugin_Device
|
|||
super(self).init(device, endpoint, arguments)
|
||||
self.tasmota_shutter_index = arguments.find(self.ARG #-'relay'-#)
|
||||
if self.tasmota_shutter_index == nil self.tasmota_shutter_index = 0 end
|
||||
self.shadow_shutter_inverted = -1
|
||||
end
|
||||
|
||||
#############################################################
|
||||
# Update inverted set
|
||||
#
|
||||
# Update "inverted" flag from Status 13
|
||||
def update_inverted()
|
||||
# get the min/max tilt values
|
||||
if (self.shadow_shutter_inverted == -1)
|
||||
var r_st13 = tasmota.cmd("Status 13", true) # issue `Status 13`
|
||||
if r_st13.contains('StatusSHT')
|
||||
r_st13 = r_st13['StatusSHT'] # skip root
|
||||
var d = r_st13.find("SHT"+str(self.tasmota_shutter_index), {}).find('Opt')
|
||||
tasmota.log("MTR: opt: "+str(d))
|
||||
if d != nil
|
||||
self.shadow_shutter_inverted = int(d[size(d)-1]) # inverted is at the most right character
|
||||
tasmota.log("MTR: Inverted flag: "+str(self.shadow_shutter_inverted))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#############################################################
|
||||
# Update shadow
|
||||
#
|
||||
def update_shadow()
|
||||
self.update_inverted()
|
||||
var sp = tasmota.cmd("ShutterPosition" + str(self.tasmota_shutter_index + 1), true)
|
||||
if sp
|
||||
self.parse_sensors(sp)
|
||||
|
@ -71,10 +94,12 @@ class Matter_Plugin_Shutter : Matter_Plugin_Device
|
|||
var TLV = matter.TLV
|
||||
var cluster = ctx.cluster
|
||||
var attribute = ctx.attribute
|
||||
var matter_position
|
||||
|
||||
# ====================================================================================================
|
||||
if cluster == 0x0102 # ========== Window Covering 5.3 p.289 ==========
|
||||
self.update_shadow_lazy()
|
||||
self.update_inverted()
|
||||
if attribute == 0x0000 # ---------- Type / enum8 ----------
|
||||
return TLV.create_TLV(TLV.U1, 0xFF) # 0xFF = unknown type of shutter
|
||||
elif attribute == 0x0005 # ---------- NumberOfActuationsLift / u16 ----------
|
||||
|
@ -83,14 +108,23 @@ class Matter_Plugin_Shutter : Matter_Plugin_Device
|
|||
return TLV.create_TLV(TLV.U1, 1 + 8) # Operational + Lift Position Aware
|
||||
elif attribute == 0x000D # ---------- EndProductType / u8 ----------
|
||||
return TLV.create_TLV(TLV.U1, 0xFF) # 0xFF = unknown type of shutter
|
||||
|
||||
elif attribute == 0x000E # ---------- CurrentPositionLiftPercent100ths / u16 ----------
|
||||
return TLV.create_TLV(TLV.U2, (100 - self.shadow_shutter_pos) * 100)
|
||||
if self.shadow_shutter_inverted == 0
|
||||
matter_position = (100 - self.shadow_shutter_pos) * 100
|
||||
else
|
||||
matter_position = self.shadow_shutter_pos * 100
|
||||
end
|
||||
return TLV.create_TLV(TLV.U2, matter_position)
|
||||
elif attribute == 0x000A # ---------- OperationalStatus / u8 ----------
|
||||
var op = self.shadow_shutter_direction == 0 ? 0 : (self.shadow_shutter_direction > 0 ? 1 : 2)
|
||||
return TLV.create_TLV(TLV.U1, op)
|
||||
elif attribute == 0x000B # ---------- TargetPositionLiftPercent100ths / u16 ----------
|
||||
return TLV.create_TLV(TLV.U2, (100 - self.shadow_shutter_target) * 100)
|
||||
if self.shadow_shutter_inverted == 0
|
||||
matter_position = (100 - self.shadow_shutter_target) * 100
|
||||
else
|
||||
matter_position = self.shadow_shutter_target * 100
|
||||
end
|
||||
return TLV.create_TLV(TLV.U2, matter_position)
|
||||
|
||||
elif attribute == 0x0017 # ---------- Mode / u8 ----------
|
||||
return TLV.create_TLV(TLV.U1, 0) # normal mode
|
||||
|
@ -137,7 +171,10 @@ class Matter_Plugin_Shutter : Matter_Plugin_Device
|
|||
var pos_100 = val.findsubval(0)
|
||||
if pos_100 != nil
|
||||
pos_100 = pos_100 / 100
|
||||
tasmota.cmd("ShutterStopPosition"+str(self.tasmota_shutter_index+1) + " " + str(100 - pos_100), true)
|
||||
if self.shadow_shutter_inverted == 0
|
||||
pos_100 = 100 - pos_100
|
||||
end
|
||||
tasmota.cmd("ShutterPosition"+str(self.tasmota_shutter_index+1) + " " + str(pos_100), true)
|
||||
ctx.log = "pos%:"+str(pos_100)
|
||||
self.update_shadow()
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue