{
    "pluginAlias": "SignalK",
    "pluginType": "platform",
    "singular": true,
    "headerDisplay": "This plugin maps [API keys of a Signal K server](https://github.com/Krillle/homebridge-signalk/blob/master/README.md#mapped-api-keys-and-devices) to matching HomeKit devices.",
    "footerDisplay": "For help or in case of issues please visit the [GitHub repository](https://github.com/Krillle/homebridge-signalk/issues).",
    "schema": {
        "type": "object",
        "properties": {
            "host": {
                "title": "Signal K Host",
                "type": "string",
                "default": "127.0.0.1:3000",
                "required": true,
                "description": "Hostname or IP address and port of your Signal K server"
            },
            "ssl": {
                "title": "Signal K Host Uses SSL",
                "type": "boolean",
                "default": false,
                "required": true,
                "description": "Check if Signal K server is awaiting connections via SSL"
            },
            "accessRequest": {
                "title": "Use Access Requests to access Signal K server",
                "type": "boolean",
                "default": true,
                "required": false,
                "description": "Check to use Signal K Access Requests to request and be granted access to the Signal K server. Approve access request in Signal K > Security > Access Requests. To reset access request, uncheck and restart Homebridge."
            },
            "securityToken": {
                "title": "Signal K Security Token",
                "type": "string",
                "required": false,
                "description": "Token entered here overrides token from access requests. Create token with signalk-generate-token."
            },
            "removeDevicesNotPresent": {
               "title": "Remove Devices Not Present in Signal K",
               "type": "boolean",
               "placeholder": false,
               "description": "If checked, devices which are not present in Signal K (after restart of Signal K server) are removed from HomeKit (at start of Homebridge server). Uncheck to prevent devices disappearing when restarting Raspberry Pi in case homebridge loads faster than the Signal K tree is being filled."
            },
            "signalkInitializeDelay": {
               "title": "Signal K API Delay",
               "type": "integer",
               "placeholder": 10000,
               "description": "Delay before adding or removing devices to give Signal K time to fill the API tree (in milliseconds)"
            },
            "autodetectNewAccessoriesInterval": {
                "title": "Detecting New Devices Interval",
                "type": "integer",
                "placeholder": 900000,
              "description": "Interval to check for new devices (in milliseconds)"
            },
            "accessRequestInterval": {
                "title": "Access Request Interval",
                "type": "integer",
                "placeholder": 60000,
              "description": "Interval to check Signal K access request status (in milliseconds)"
            },
            "emptyBatteryVoltage": {
                "title": "Empty Battery Voltage",
                "type": "number",
                "placeholder": 22,
              "description": "Voltage at which battery state of charge will be shown as 0% (ignored if SOC is reported from battery)"
            },
            "fullBatteryVoltage": {
                "title": "Full Battery Voltage",
                "type": "number",
                "placeholder": 25.8,
                "description": "Voltage at which battery state of charge will be shown as 100% (ignored if SOC is reported from battery)"
            },
            "lowBatteryVoltage": {
                "title": "Low Battery Voltage",
                "type": "number",
                "placeholder": 23.5,
                "description": "Voltage below wich a battery low warning will be shown"
            },
            "chargingBatteryVoltage": {
                "title": "Charging Battery Voltage",
                "type": "number",
                "placeholder": 27,
                "description": "Voltage above wich batteries will be shown as charging (ignored if current is reported from battery)"
            },
            "lowFreshWaterLevel": {
                "title": "Fresh Water Low Level",
                "type": "integer",
                "placeholder": 25,
                "minimum": 0,
                "maximum": 100,
                "description": "Percent level below wich fresh water tanks will show a warning"
            },
            "highWasteWaterLevel": {
                "title": "Waster Water High Level",
                "type": "integer",
                "placeholder": 75,
                "minimum": 0,
                "maximum": 100,
                "description": "Percent level above wich waste water tanks will show a warning"
            },
            "highBlackWaterLevel": {
                "title": "Black Water High Level",
                "type": "integer",
                "placeholder": 75,
                "minimum": 0,
                "maximum": 100,
                "description": "Percent level above wich black water tanks will show a warning"
            },
            "lowFuelLevel": {
                "title": "Fuel Low Level",
                "type": "integer",
                "placeholder": 50,
                "minimum": 0,
                "maximum": 100,
                "description": "Percent level below wich fuel tanks will show a warning"
            },
            "lowLubricationLevel": {
                "title": "Lubrication Low Level",
                "type": "integer",
                "placeholder": 50,
                "minimum": 0,
                "maximum": 100,
                "description": "Percent level below wich lubrication tanks will show a warning"
            },
            "lowLiveWellLevel": {
                "title": "Fuel Live Well Level",
                "type": "integer",
                "placeholder": 50,
                "minimum": 0,
                "maximum": 100,
                "description": "Percent level below wich live well tanks will show a warning"
            },
            "lowGasLevel": {
                "title": "Fuel Gas Level",
                "type": "integer",
                "placeholder": 50,
                "minimum": 0,
                "maximum": 100,
                "description": "Percent level below wich gas tanks will show a warning"
            },
            "lowBallastLevel": {
                "title": "Fuel Ballast Level",
                "type": "integer",
                "placeholder": 50,
                "minimum": 0,
                "maximum": 100,
                "description": "Percent level below wich ballast tanks will show a warning"
            },
            "contactSensors": {
                "title": "Contact Sensors",
                "type": "array",
                "description": "Set up contact sensors which are triggered when a Signal K API key reaches a threshold value.",
                "items": {
                    "type": "object",
                    "properties": {
                      "key": {
                        "title": "API Key",
                        "type": "string",
                        "required": true,
                        "placeholder": "e.g. navigation.speedOverGround",
                        "description": "Signal K API key for which you want to see a contact sensor device in HomeKit"
                      },
                      "name": {
                        "title": "Name",
                        "type": "string",
                        "description": "Name to be shown for this contact sensor device in HomeKit"
                      },
                      "operator": {
                        "title": "Operator",
                        "type": "string",
                        "default": ">",
                        "oneOf": [
                           { "title": "Equal to treshold (==)", "enum": ["=="] },
                           { "title": "Not equal to treshold (!=)", "enum": ["!="] },
                           { "title": "Less than treshold (<)", "enum": ["<"] },
                           { "title": "Less than or equal to treshold (<=)", "enum": ["<="] },
                           { "title": "Greater than treshold (>)", "enum": [">"] },
                           { "title": "Greater than or equal to treshold (>=)", "enum": [">="] }
                        ]
                      },
                      "treshold": {
                        "title": "Treshold",
                        "type": "string"
                      }
                    },
                    "required": [ "key" ]
                }
            },
            "ignoredPaths": {
                "title": "Ignored API Keys",
                "type": "array",
                "description": "Signal K API keys for which you don't want to see a device in HomeKit. Associated devices will be deleted from HomeKit if already present.",
                "items": {
                    "title": "API Key",
                    "type": "string",
                    "placeholder": "tanks.wasteWater.0"
                }
            }

        }
    },
    "form": null,
    "display": null,
    "layout": [
      {
        "items": [
          "host",
          "ssl",
          "accessRequest"
        ]
      },
      {
        "type": "fieldset",
        "title": "Optional Configuration",
        "expandable": true,
        "items": [
          "securityToken",          
          "removeDevicesNotPresent",
          "signalkInitializeDelay",
          "autodetectNewAccessoriesInterval",
          "accessRequestInterval",
          "emptyBatteryVoltage",
          "fullBatteryVoltage",
          "lowBatteryVoltage",
          "chargingBatteryVoltage",
          "lowFreshWaterLevel",
          "highWasteWaterLevel",
          "highBlackWaterLevel",
          "lowFuelLevel",
          "lowLubricationLevel",
          "lowLiveWellLevel",
          "lowGasLevel",
          "lowBallastLevel"
        ]
      },
      {
        "key": "contactSensors",
        "expandable": true,
        "type": "array",
        "items": [
          {
            "type": "div",
            "items": [
              {
                "items": [
                  "contactSensors[].key",
                  "contactSensors[].name",
                  {
                    "type": "flex",
                    "flex-flow": "row wrap",
                    "items": [
                      {
                        "type": "flex",
                        "flex-flow": "column",
                        "items": [
                          "contactSensors[].operator"
                        ]
                      },
                      {
                        "type": "flex",
                        "flex-flow": "column",
                        "items": [
                          "contactSensors[].treshold"
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "key": "ignoredPaths",
        "expandable": true,
        "type": "array",
        "items": [
          {
            "type": "div",
            "displayFlex": true,
            "flex-direction": "row",
            "items": [
              {
                "key": "ignoredPaths[]"
              }
            ]
          }
        ]
      }
    ]
}
