0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
219 stars 67 forks source link

Add Support for Vacuum Accessories #173

Open nichipedia opened 1 year ago

nichipedia commented 1 year ago

Currently vacuum accessories are not supported by this plugin or the official plugin.

It will be nice to automate my vacuum from the Home App scenes!

0x5e commented 1 year ago

OK, it's on the plan now, please provide the device info json and it will help me better adapt your device, thanks.

nichipedia commented 1 year ago
{
path = /v1.0/devices/eb92c252e09f23544a9zlj/specifications
data = {
  "result": {
    "category": "sd",
    "functions": [
      {
        "code": "switch_go",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "mode",
        "type": "Enum",
        "values": "{\"range\":[\"standby\",\"spiral\",\"wall_follow\",\"random\",\"chargego\",\"partial_bow\"]}"
      },
      {
        "code": "direction_control",
        "type": "Enum",
        "values": "{\"range\":[\"forward\",\"backward\",\"turn_left\",\"turn_right\",\"stop\"]}"
      },
      {
        "code": "suction",
        "type": "Enum",
        "values": "{\"range\":[\"gentle\",\"normal\",\"strong\"]}"
      },
      {
        "code": "water_control",
        "type": "Enum",
        "values": "{\"range\":[\"closed\",\"low\",\"high\"]}"
      }
    ],
    "status": [
      {
        "code": "switch_go",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "mode",
        "type": "Enum",
        "values": "{\"range\":[\"standby\",\"spiral\",\"wall_follow\",\"random\",\"chargego\",\"partial_bow\"]}"
      },
      {
        "code": "direction_control",
        "type": "Enum",
        "values": "{\"range\":[\"forward\",\"backward\",\"turn_left\",\"turn_right\",\"stop\"]}"
      },
      {
        "code": "status",
        "type": "Enum",
        "values": "{\"range\":[\"standby\",\"smart_clean\",\"wall_clean\",\"spot_clean\",\"room_clean\",\"goto_charge\",\"charging\",\"charge_done\",\"cleaning\",\"sleep\",\"in_trouble\"]}"
      },
      {
        "code": "residual_electricity",
        "type": "Integer",
        "values": "{\"unit\":\"%\",\"min\":0,\"max\":100,\"scale\":0,\"step\":1}"
      },
      {
        "code": "suction",
        "type": "Enum",
        "values": "{\"range\":[\"gentle\",\"normal\",\"strong\"]}"
      },
      {
        "code": "clean_time",
        "type": "Integer",
        "values": "{\"unit\":\"min\",\"min\":0,\"max\":9999,\"scale\":0,\"step\":1}"
      },
      {
        "code": "fault",
        "type": "Bitmap",
        "values": "{\"label\":[\"0\",\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\"],\"maxlen\":15}"
      },
      {
        "code": "water_control",
        "type": "Enum",
        "values": "{\"range\":[\"closed\",\"low\",\"high\"]}"
      },
      {
        "code": "log_unseen",
        "type": "String",
        "values": "{\"maxlen\":255}"
      },
      {
        "code": "fan_tank_unseen",
        "type": "Enum",
        "values": "{\"range\":[\"fan_in\",\"fan_tank_in\",\"fan_tank_none\"]}"
      }
    ]
  },
  "success": true,
  "t": 1672196138711,
  "tid": "1bafa0e0865b11ed8bf3266109e39bbb"
}

Here is the JSON from the debug console. I really like the work yall are doing for this plugin. Works great! If I get some time I may pull and try my hand at implementing! 🤪

0x5e commented 1 year ago

Welcome! However the homekit has many limitations, enum is one thing it don't have a good way to support. boolean has switches, integer has sliders(brightness, fanspeed, ...), but enum don't. maybe I have to create x switches for a enum which have x value.

nichipedia commented 1 year ago

I have done ZERO work with type script, and have only spent a small amount of time overviewing the the code base. Could you just create a class that just persists an immutable set of Strings? Here's some "pseudo code" of how I could do it in Java...

public class TestValues {
      public static final String ENUM1 = "value1";
      public static final String ENUM2 = "value2";
      ....

      public static final Collection stuff = [key1, key2]
  }
}
....
stuff.stream().foreach(//print each ENUM)

Effectively, thats all an enumeration is right? At least, the enum type in java.

0x5e commented 1 year ago

like this? https://github.com/0x5e/homebridge-tuya-platform/blob/dd7508f1a473b681046d9dcd8ce697ac80d0ba90/src/device/TuyaDevice.ts#L9-L16

I'm not familar with typescript too, this is just my second typescript project. study some basic synatax online and that's enough to write logics for me.