0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
206 stars 58 forks source link

WindowCoveringAccessory doesn't handle devices that report percent_control and control MQ messages #473

Open jimcrammond opened 2 weeks ago

jimcrammond commented 2 weeks ago

Prerequisite

Cache

Version

1.7.0-beta.53

Device Infomation JSON File

{
    "active_time": 1710178624,
    "biz_type": 18,
    "category": "cl",
    "create_time": 1710178624,
    "icon": "smart/program_category_icon/cl.png",
    "model": "LS830-TY",
    "name": "Dining Room Curtain",
    "online": true,
    "product_id": "550grkojy40jodv0",
    "product_name": "智能窗帘",
    "status": [
      {
        "code": "control",
        "value": "close"
      },
      {
        "code": "control_back",
        "value": true
      },
      {
        "code": "percent_control",
        "value": 100
      },
      {
        "code": "percent_state",
        "value": 94
      },
      {
        "code": "time_total",
        "value": 0
      }
    ],
    "sub": false,
    "time_zone": "-07:00",
    "update_time": 1716796862,
    "schema": [
      {
        "code": "control",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "open",
            "stop",
            "close"
          ]
        }
      },
      {
        "code": "control_back",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "percent_control",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "unit": "%",
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "percent_state",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "%",
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "time_total",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "ms",
          "min": 0,
          "max": 120000,
          "scale": 0,
          "step": 1
        }
      }
    ]
  }

Device Control Mode

None

Logs

No response

Other Infomations

I have a Quoya curtain that can be open/closed or partially opened. When fully opened/closed, the MQTT status message with code = "control" is generated rather than code = "percent_control". However, the accessory does not handle that case (at least when the open/close happened externally, e.g. through a scene or the Smart Life App). The onDeviceStatusUpdate callback will update the TargetPosition characteristics based on TargetPositionPercent which is not updated from this message.

The result is that currentPosition and TargetPosition get out of sync and so the curtain is displayed as Opening... or Closing... in the Apple Home app.

Probably need to override the base class onDeviceStatusUpdate definition with one that looks at the status parameter and updates the TargetPosition characteristic appropriately.

jimcrammond commented 2 weeks ago

A bit more information about this device. It appears that the control and percent_control attributes operate independently. That means that if I move the curtain partially closed in the Smart Life App, the percent_control value is updated, but not the control value and if I hit the open or close buttons in the app, the control value is updated but not the percent_control. The following status is reported in the Tuya UI after closing the curtain. Note percent_control is not updated from its previous setting. (Also note that value 0 means open and 100 means closed for this device - I use the overrides to invert that but this shows the values in the Tuya side)

{ "result": { "properties": [ { "code": "control", "custom_name": "", "dp_id": 1, "time": 1718744593364, "value": "close" }, { "code": "percent_control", "custom_name": "", "dp_id": 2, "time": 1718730125346, "value": 37 }, { "code": "percent_state", "custom_name": "", "dp_id": 3, "time": 1718744598263, "value": 94 }, { "code": "control_back", "custom_name": "", "dp_id": 5, "time": 1712105450538, "value": true }, { "code": "fault", "custom_name": "", "dp_id": 10, "time": 1710178624257, "value": 0 }, { "code": "time_total", "custom_name": "", "dp_id": 11, "time": 1710178624257, "value": 0 } ] },

The way I think the homebridge plugin works is to query the percent_control value in Tuya backend after an MQ message is received, regardless of the message received, to determine TargetPosition. But it needs to look at percent_control or control value based on the last message received.