{
  "pluginAlias": "smartthings-tv",
  "pluginType": "platform",
  "singular": true,
  "customUi": true,
  "schema": {
    "type": "object",
    "properties": {
      "tokenType": {
        "title": "SmartThings authentication type",
        "type": "string",
        "required": true,
        "description": "The authentication type to be used for SmartThings API.",
        "default": "pat",
        "oneOf": [
          {
            "title": "PAT",
            "enum": [
              "pat"
            ]
          },
          {
            "title": "OAuth",
            "enum": [
              "oauth"
            ]
          }
        ]
      },
      "token": {
        "title": "SmartThings personal access token",
        "type": "string",
        "required": true,
        "description": "The SmartThings API token is needed to authenticate the requests sent to the SmartThings API. To generate a PAT open https://account.smartthings.com/tokens and generate a new one (make sure at least devices is selected).",
        "condition": {
          "functionBody": "return model.tokenType === \"pat\";"
        }
      },
      "oauthClientId": {
        "title": "OAuth client id",
        "type": "string",
        "required": true,
        "description": "The client id of the OAuth application.",
        "condition": {
          "functionBody": "return model.tokenType === \"oauth\";"
        }
      },
      "oauthClientSecret": {
        "title": "OAuth client secret",
        "type": "string",
        "required": true,
        "description": "The client secret of the OAuth application.",
        "condition": {
          "functionBody": "return model.tokenType === \"oauth\";"
        }
      },
      "oauthRefreshToken": {
        "title": "OAuth refresh token",
        "type": "string",
        "required": true,
        "description": "The refresh token used for OAuth.",
        "condition": {
          "functionBody": "return model.tokenType === \"oauth\";"
        }
      },
      "capabilityLogging": {
        "title": "Capability Logging",
        "type": "boolean",
        "required": false,
        "description": "The SmartThings API returns the list of supported actions of a device as capabilities. For implementing new features it is neccessary to know the scheme the capability uses. Enable this property to log all capabilities of supported SmartThings devices."
      },
      "cyclicCallsLogging": {
        "title": "Cyclic calls Logging",
        "type": "boolean",
        "required": false,
        "description": "Enable debug logging for cyclic calls (e.g. polling)."
      },
      "registerApplications": {
        "title": "Register applications",
        "type": "boolean",
        "required": false,
        "description": "To use installed application as input sources, a predefined list of applications will be used. Please note that this has no effect on SoundBars."
      },
      "registerPictureModes": {
        "title": "Register picture modes",
        "type": "boolean",
        "required": false,
        "description": "Registers all available picture modes as separate switches that can be toggled to enable a picture mode. Uses the names as exposed from the SmartThings API. Please note that this has no effect on SoundBars."
      },
      "registerSoundModes": {
        "title": "Register sound modes",
        "type": "boolean",
        "required": false,
        "description": "Registers all available sound modes as separate switches that can be toggled to enable a sound mode. Uses the names as exposed from the SmartThings API. Please note that this has no effect on SoundBars"
      },
      "registerAmbientSwitch": {
        "title": "Register ambient mode switch",
        "type": "boolean",
        "required": false,
        "description": "Registers a stateless switches that can be toggled to switch ambient mode on."
      },
      "registerAmbientModes": {
        "title": "Register ambient modes",
        "type": "boolean",
        "required": false,
        "description": "Registers all available ambient modes as separate switches that can be toggled to enable an ambient mode. Uses the names as exposed from the SmartThings API. Please note that this has no effect on SoundBars."
      },
      "registerVolumeSlider": {
        "title": "Register volume slider",
        "type": "boolean",
        "required": false,
        "description": "Registers a separate volume slider accessorry that will be exposed as a light bulb accessory (because there is currently no option to change a speaker volume directly using Home)."
      },
      "registerInputSwitches": {
        "title": "Register input sources as switches",
        "type": "boolean",
        "required": false,
        "description": "Register all input sources as seperate stateless switches that can be toggled to switch to input source."
      },
      "pollInterval": {
        "title": "State polling interval [ms]",
        "type": "number",
        "required": false,
        "description": "Some characteristics are not updated automatically (e.g. power state). To enable polling these characteristics automatically set this value to the desired polling interval in milliseconds. Leave empty to disable this functionality."
      },
      "deviceBlocklist": {
        "description": "Devices not to be registered.",
        "type": "array",
        "items": {
          "title": "Device Id",
          "type": "string",
          "description": "The SmartThings device id. Check the log or go to https://account.smartthings.com/ and get the device id."
        }
      },
      "deviceMappings": {
        "description": "Use the device mappings when e.g. turning on the accessory does not work as expected. When a device mapping is available the wake-on-lan functionality is used to turn on the device instead of the SmartThings API. To make use of the functionality you must enter the mapping using the SmartThings device ID and the mac address of the device. If status does not show up properly you can use the ping functionality to determine the device status. To make use of it you must enter the SmartThings device ID and the ip address of the device.",
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "deviceId": {
              "title": "Device Id",
              "type": "string",
              "required": true,
              "description": "The SmartThings device id. Check the log or go to https://account.smartthings.com/ and get the device id."
            },
            "nameOverride": {
              "title": "Name override",
              "type": "string",
              "description": "Use this to override the default display name of the device. Must be configured here because name configured in HomeKit will get lost after restart."
            },
            "wol": {
              "title": "Wake-on-lan functionality",
              "type": "boolean",
              "description": "Enables usage of wake-on-lan functionality to turn the device on. Use only if using the SmartThings API does not work for your device."
            },
            "macAddress": {
              "title": "Mac address",
              "type": "string",
              "description": "The mac address of the device to turn device on using wake-on-lan functionality.",
              "pattern": "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([0-9a-fA-F]{4}\\.[0-9a-fA-F]{4}\\.[0-9a-fA-F]{4})$",
              "condition": {
                "functionBody": "return model.deviceMappings[arrayIndices].wol === true;"
              }
            },
            "ping": {
              "title": "Ping functionality",
              "type": "boolean",
              "description": "Enables usage of ping functionality to determine if device is turned on. Use only if using the SmartThings API does not work for your device."
            },
            "ipAddress": {
              "title": "IP address",
              "type": "string",
              "description": "The IP address of the device (assign a static IP address to make sure it does not change) to determine the status using ping.",
              "pattern": "((^\\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\\s*$)|(^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$))",
              "condition": {
                "functionBody": "return model.deviceMappings[arrayIndices].ping === true;"
              }
            },
            "infoKey": {
              "title": "Info key",
              "type": "string",
              "description": "The key to be emulated when pressing info button in HomeKit remote. The list of valid values must be read from the log as it differs per device. To do so enable capabilityLogging and look for log entry containing the possible values. Please note that this has no effect on SoundBars."
            },
            "inputSources": {
              "title": "Custom input sources list",
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "title": "Input source name",
                    "type": "string"
                  },
                  "id": {
                    "title": "Input source id",
                    "type": "string"
                  }
                },
                "required": false,
                "description": "Overrides the device's default input sources map to add custom input sources. Check the log for information about the default input sources."
              }
            },
            "applications": {
              "title": "Custom application list",
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "title": "Application name",
                    "type": "string"
                  },
                  "ids": {
                    "title": "Application IDs",
                    "type": "array",
                    "items": {
                      "title": "Application ID",
                      "type": "string",
                      "pattern": "^\\d+$"
                    }
                  }
                }
              },
              "required": false,
              "description": "Overrides the default application mapping list to add custom applications. Please note that this has no effect on SoundBars."
            },
            "validateApplications": {
              "title": "Validate application list",
              "type": "boolean",
              "description": "Validates the list of applications by trying to open them when starting the plugin. This list will be checked for availability at the TV(s) and eventually be registered as input sources. Make sure to have the TV(s) turned on when starting your instance as this functionality requires your TV(s) be turned on to determine whether an application is installed or not. On startup the applications will be opened to determine if they are available. Do not use your TV until the input source is being changed back to the first one (usually Live TV). Afterwards the list of working applications will be written to this device list of applications. Note that this flag will be set to off after validation the application list. So check will only run on first start or manual reset. Please note that this has no effect on SoundBars.",
              "default": true
            },
            "category": {
              "title": "Display icon",
              "type": "integer",
              "description": "The icon to be used as a hint to iOS clients about what type of Accessory this represents. Can be used to override default values.",
              "required": false,
              "oneOf": [
                {
                  "title": "AppleTV",
                  "enum": [
                    "24"
                  ]
                },
                {
                  "title": "HomePod",
                  "enum": [
                    "25"
                  ]
                },
                {
                  "title": "Speaker",
                  "enum": [
                    "26"
                  ]
                },
                {
                  "title": "AirPort",
                  "enum": [
                    "27"
                  ]
                },
                {
                  "title": "Television",
                  "enum": [
                    "31"
                  ]
                },
                {
                  "title": "Remote Control",
                  "enum": [
                    "32"
                  ]
                },
                {
                  "title": "Router",
                  "enum": [
                    "33"
                  ]
                },
                {
                  "title": "Audio Receiver",
                  "enum": [
                    "34"
                  ]
                },
                {
                  "title": "TV Set Top Box",
                  "enum": [
                    "35"
                  ]
                },
                {
                  "title": "TV Streaming Stick",
                  "enum": [
                    "36"
                  ]
                }
              ]
            }
          }
        }
      },
      "tvDeviceTypes": {
        "title": "TV device types",
        "description": "List of SmartThings device types that should be registered as TVs (leave empty to use default values)",
        "type": "array",
        "items": {
          "title": "Device type",
          "type": "string",
          "description": "The SmartThings device type as appearing in the Debug log"
        },
        "default": [
          "oic.d.tv",
          "x.com.st.d.monitor"
        ]
      },
      "soundbarDeviceTypes": {
        "title": "Soundbar device types",
        "description": "List of SmartThings device types that should be registered as Soundbar (leave empty to use default values)",
        "type": "array",
        "items": {
          "title": "Device type",
          "type": "string",
          "description": "The SmartThings device type as appearing in the Debug log"
        },
        "default": [
          "oic.d.networkaudio"
        ]
      }
    }
  }
}
