{
  "pluginAlias": "SaphiTV",
  "pluginType": "platform",
  "singular": false,
  "schema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "required": true,
        "default": "Saphi TV"
      },
      "ip_adress": {
        "type": "string",
        "format": "ipv4",
        "required": true
      },
      "wol_adress": {
        "type": "string",
        "pattern":"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$",
        "required": true
      },
      "has_tv_channels": {
        "type": "boolean",
        "required": true,
        "default": true
      },
      "channel_setup_popup_time": {
        "type": "integer",
        "minimum": 100,
        "maximum": 10000,
        "required": true,
        "default": 2250,
        "condition": {
          "functionBody": "return model.has_tv_channels === false;"
        }
      },
      "startup_time": {
        "type": "integer",
        "minimum": 10,
        "maximum": 30,
        "required": true,
        "default": 15
      },
      "timeout": {
        "type": "integer",
        "minimum": 2,
        "maximum": 15,
        "required": true,
        "default": 5
      },
      "input_delay": {
        "type": "integer",
        "minimum": 150,
        "maximum": 1500,
        "required": true,
        "default": 650
      },
      "api_version": {
        "type": "number",
        "minimum": 1,
        "maximum": 6,
        "required": true,
        "default": 6
      },
      "api_port_no": {
        "type": "number",
        "required": true,
        "default": 1925,
        "minimum": 0,
        "maximum": 9999
      },
      "protocol": {
        "type": "string",
        "oneOf": [
          {
            "title": "HTTP",
            "enum": [
              "http"
            ]
          },
          {
            "title": "HTTPS",
            "enum": [
              "https"
            ]
          }
        ],
        "required": true,
        "default": "http"
      },
      "polling_interval": {
        "type": "integer",
        "minimum": 15,
        "maximum": 120,
        "required": true,
        "default": 40
      },
      "has_ambilight": {
        "type": "boolean",
        "required": true,
        "default": true
      },
      "multirow_apps": {
        "type": "boolean",
        "required": false,
        "default": false
      },
      "vertical_inputs": {
        "type": "boolean",
        "required": false,
        "default": false
      },
      "has_ambihue": {
        "type": "boolean",
        "required": true,
        "default": true,
        "condition": {
          "functionBody": "return model.has_ambilight === true;"
        }
      },
      "ambi_poweroff": {
        "type": "boolean",
        "required": true,
        "default": true,
        "condition": {
          "functionBody": "return (model.has_ambilight === true && model.has_ambihue === true);"
        }
      },
      "ambi_poweron": {
        "type": "boolean",
        "required": true,
        "default": false,
        "condition": {
          "functionBody": "return (model.has_ambilight === true && model.has_ambihue === true);"
        }
      },
      "inputs": {
        "type": "array",
        "items": {
          "title": "Input",
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "required": true,
              "placeholder": "Input Name"
            },
            "type": {
              "placeholder": "type",
              "type": "string",
              "required": true,
              "oneOf": [
                {
                  "title": "TV",
                  "enum": [
                    "TV"
                  ]
                },
                {
                  "title": "App",
                  "enum": [
                    "APP"
                  ]
                },
                {
                  "title": "Source",
                  "enum": [
                    "SOURCE"
                  ]
                },
                {
                  "title": "Channel",
                  "enum": [
                    "CHANNEL"
                  ]
                }
              ]
            },
            "position": {
              "type": "string",
              "required": true,
              "placeholder": "1",
              "pattern": "^\\d+(\\.\\d+)*$",
              "condition": {
                "functionBody": "return model.inputs[arrayIndices].type !== 'TV';"
              }
            }
          }
        }
      }
    }
  },
  "layout": [
    {
      "key": "name",
      "title": "Name",
      "placeholder": "TV Name",
      "description": "How you want to Name your TV",
      "notitle": false
    },
    {
      "type": "fieldset",
      "title": "Local Network",
      "description": "Where can I reach your TV?",
      "expandable": true,
      "expanded": false,
      "items": [
        {
          "type": "flex",
          "flex-flow": "row",
          "items": [
            {
              "title": "IP Adress",
              "key": "ip_adress",
              "placeholder": "192.168.78.98",
              "notitle": false,
              "validationMessage": {
                "202": "Wrong format! Try a valid mac-address",
                "302": "This field is like, uh, required?"
              },
              "description": "IP adress of your TV"
            },
            {
              "title": "MAC Adress",
              "key": "wol_adress",
              "notitle": false,
              "validationMessage": {
                "202": "Wrong format! Try a valid mac-address",
                "302": "This field is like, really required :D"
              },
              "placeholder": "20:DE:20:DE:20:DE",
              "description": "mac adress of your TV"
            }
          ]
        }
      ]
    },
    {
      "type": "fieldset",
      "title": "Capabilities",
      "description": "This controls, what the plugin will do for you.",
      "expandable": true,
      "expanded": false,
      "items": [
        {
          "type": "flex",
          "flex-flow": "column",
          "items": [
            {
              "key": "has_ambilight",
              "title": "TV has Ambilight",
              "description": "Checking this will allow you to control your TVs Ambilight",
              "notitle": false
            },
            {
              "key": "has_ambihue",
              "title": "Ambilight + Hue support",
              "description": "Checking this will add a switch to your TV to control the Ambilight+Hue option.",
              "notitle": false
            },
            {
              "key": "ambi_poweron",
              "notitle": false,
              "title": "automatically turn on Ambilight when turning on TV",
              "description": "This will turn on Ambilight+Hue when you start the TV with the home app"
            },
            {
              "key": "ambi_poweroff",
              "notitle": false,
              "title": "Turn off Ambilight+ before turning off the TV",
              "description": "This will turn off Ambilight+Hue before turning off your TV as a workaround for a known Ambilight+Hue bug where you would get a significant delay"
            }
          ]
        }
      ]
    },
    {
      "type": "fieldset",
      "title": "Inputs",
      "description": "This allows you to add 'inputs' to your TV.",
      "expandable": true,
      "expanded": false,
      "items": [
        {
          "title": "Help",
          "notitle": true,
          "type": "help",
          "helpvalue": "<p> <b>TV</b> only activates WatchTV. <br> <b>App</b> opens an app from your home-bar. <br> <b>Source</b> changes the TVs current input. <br> <b>Channel</b> selects the given channel number.<br> <b>Switch</b> will allow Siri to activate the input. This <b>will</b> clutter your HomeKit! </p>"
        },

        {
          "key": "vertical_inputs",
          "title": "Vertical inputs",
          "description": "Indicates that your Inputs are arranged vertically",
          "notitle": false
        },

        {
          "key": "multirow_apps",
          "title": "Multirow Apps",
          "description": "Indicates that your Apps are on multiple rows.",
          "notitle": false
        },
        {
          "key": "inputs",
          "title": "Input",
          "notitle": true,
          "type": "array",
          "items": [
            {
              "type": "div",
              "displayFlex": true,
              "flex-direction": "row",
              "items": [
                {
                  "key": "inputs[].type",
                  "title": "Type",
                  "flex": "1 1 50px",
                  "notitle": false,
                  "placeholder": "Type"
                },
                {
                  "key": "inputs[].name",
                  "title": "Input name",
                  "flex": "2 2 200px",
                  "notitle": false,
                  "placeholder": "Input name"
                },
                {
                  "key": "inputs[].position",
                  "flex": "1 1 50px",
                  "notitle": false,
                  "title": "Position",
                  "validationMessage": {
                    "202": "Wrong format! Try one of these: 12, 12.1, 0",
                    "302": "This field is like, uh, required?"
                  },
                  "placeholder": "Position"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "fieldset",
      "title": "Advanced",
      "description": "These settings should be OK by default but I wanted to still give you control over them.",
      "expandable": true,
      "expanded": false,
      "items": [
        {
          "type": "tabarray",
          "items": [
            {
              "type": "section",
              "title": "Timings",
              "notitle": true,
              "expandable": false,
              "description": "This allows you to change the timings of this plugin. Please only change these if you need to.",
              "expanded": true,
              "items": [
                {
                  "type": "flex",
                  "flex-flow": "column",
                  "items": [
                    {
                      "key": "startup_time",
                      "notitle": false,
                      "description": "the time your TV takes for a full start-up",
                      "title": "Startup time (s)"
                    },
                    {
                      "key": "input_delay",
                      "title": "Delay between inputs (ms)",
                      "description": "the time between commands. lower feels snapier but it might confuse your TV.",
                      "notitle": false
                    },
                    {
                      "key": "polling_interval",
                      "title": "Polling Interval (s)",
                      "description": "How often the TV state is updated in the background",
                      "notitle": false
                    },
                    {
                      "title": "Timeout time (s)",
                      "description": "how long to wait for a response from your TV before declaring it off. Higher values might make HomeKit go 'No Response'",
                      "key": "timeout",
                      "notitle": false
                    }
                  ]
                }
              ]
            },
            {
              "type": "section",
              "title": "Saphi API",
              "notitle": true,
              "expandable": false,
              "description": "This allows you to change the timings of this plugin. Please only change these if you need to.",
              "expanded": true,
              "items": [
                {
                  "key": "api_version",
                  "title": "API version",
                  "placeholder": "6",
                  "description": "the Saphi-API version your TV is running",
                  "notitle": false
                },
                {
                  "key": "api_port_no",
                  "title": "API port",
                  "placeholder": "1925",
                  "description": "the Saphi-API port your TV is running",
                  "notitle": false
                },
                {
                  "key": "protocol",
                  "title": "API protocol",
                  "description": "the Saphi-API protocol your TV is running",
                  "notitle": false
                }
              ]
            },
            {
              "type": "section",
              "title": "TV Settings",
              "notitle": true,
              "expandable": false,
              "description": "This allows you to change some settings about your TV",
              "expanded": true,
              "items": [
                {
                  "key": "has_tv_channels",
                  "title": "Has TV channels set up",
                  "description": "Uncheck if you did NOT set up your TV with TV Channels.",
                  "notitle": false
                },
                {
                  "key": "channel_setup_popup_time",
                  "title": "time for the popup to appear (ms)",
                  "description": "measure the time for the 'missing channels' popup to appear and enter it here.",
                  "notitle": false
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}