{
  "pluginAlias": "BraviaPlatform",
  "pluginType": "platform",
  "headerDisplay": "After restarting Homebridge, check the log for the web UI URL (default port: 8999). Open that address to enter the PIN shown on your TV, then use the same address to access the Channel Selector UI.",
  "footerDisplay": "For documentation please see https://github.com/diegoweb100/homebridge-bravia-enhanced",
  "schema": {
    "autoscan": {
      "title": "Autoscan (managed TVs)",
      "description": "When enabled, TVs added through the /discover web UI are stored in a separate managed file (plugin-persist/homebridge-bravia/tvs-managed.json) and merged with TVs in this config at load time. The plugin never modifies your config.json. On duplicates by MAC, config.json wins and a warning is logged.",
      "type": "boolean",
      "required": false,
      "default": false
    },
    "discoveryRange": {
      "title": "Discovery range (CIDR)",
      "description": "Subnet(s) to scan from the /discover UI, e.g. '192.168.1.0/24'. Leave empty to autodetect from the local IP. Limited to /20 or smaller (4096 hosts max).",
      "type": "string",
      "required": false
    },
    "tvs": {
      "title": "Registered TVs",
      "required": false,
      "type": "array",
      "items": {
        "name": "TV Config",
        "type": "object",
        "properties": {
          "name": {
            "title": "Name",
            "description": "The name of your TV in HomeKit",
            "type": "string",
            "required": true
          },
          "ip": {
            "title": "IP / Hostname",
            "description": "The IP address or host name of your TV, find or set in your router",
            "type": "string",
            "required": true
          },
          "port": {
            "title": "Port",
            "description": "HTTP port of the TV",
            "placeholder": "80",
            "type": "number",
            "required": false
          },
          "psk": {
            "title": "Pre-Shared Key (PSK)",
            "description": "If set, the plugin uses PSK authentication (X-Auth-PSK header) instead of PIN+cookie pairing. Required for some Bravia XR models (interface v6.x and above). Set the same key on the TV: Settings > Network > IP control > Authentication > Pre-Shared Key.",
            "type": "string",
            "required": false
          },
          "serverPort": {
            "title": "PIN entry / Channel Selector server port",
            "placeholder": "8999",
            "type": "number",
            "required": false,
            "description": "Port of this TV's web UI (PIN entry and Channel Selector). With more than one TV, give each TV a different port."
          },
          "channelSelectorPort": {
            "title": "Channel Selector port override",
            "description": "Override the port used for the Channel Selector web UI (defaults to serverPort)",
            "placeholder": "8999",
            "type": "number",
            "required": false
          },
          "enableChannelSelector": {
            "title": "Enable Channel Selector UI",
            "description": "Controls only the Channel Selector UI page. The web server (needed for pairing) is always active.",
            "type": "boolean",
            "required": false
          },
          "maxInputSources": {
            "title": "Max Input Sources",
            "description": "Maximum number of inputs to register in HomeKit. HomeKit hard limit is 97. Defaults to 97.",
            "placeholder": "97",
            "type": "number",
            "required": false
          },
          "mac": {
            "title": "MAC address",
            "description": "DO NOT set unless you need to use WOL",
            "type": "string",
            "required": false
          },
          "externalaccessory": {
            "title": "External Accessory",
            "description": "Workaround for multiple TVs and remote app, registers this TV as an external accessory",
            "type": "boolean",
            "required": false
          },
          "volumeAccessory": {
            "title": "Volume Accessory",
            "description": "Expose a separate Lightbulb accessory in HomeKit to control TV volume (brightness) and mute (on/off). Defaults to false.",
            "type": "boolean",
            "required": false
          },
          "appsAccessory": {
            "title": "Apps in a separate tile",
            "description": "Show apps in their own '<name> Apps' TV tile in the Home app instead of the TV's input list (needs a one-time pairing with the Homebridge setup code). The ones ticked in the Channel Selector, or all if none. Defaults to false.",
            "type": "boolean",
            "required": false
          },
          "recordingsAccessory": {
            "title": "Recordings in a separate tile (USB drive required)",
            "description": "Show every recording on the TV's USB hard drive in its own '<name> Recordings' TV tile (newest first, updated automatically). Works only while a USB drive is connected to the TV and set up for recording. Defaults to false.",
            "type": "boolean",
            "required": false
          },
          "functionsAccessory": {
            "title": "TV functions in a separate tile",
            "description": "Show TV functions (Teletext, Guide, Subtitles, Record now…) as buttons in their own '<name> Functions' accessory instead of the TV's input list. The ones ticked in the Channel Selector, or all if none. Defaults to false.",
            "type": "boolean",
            "required": false
          },
          "controlsAccessory": {
            "title": "Controls Accessory",
            "description": "Expose a separate '<name> Controls' accessory with one switch per picture mode (switching one off returns to Auto) and a 'Screen off' switch (picture off, sound on). Defaults to false.",
            "type": "boolean",
            "required": false
          },
          "controlsScenes": {
            "title": "Picture modes for the Controls accessory",
            "description": "Picture modes exposed as switches. Default: cinema, game, sports. Your TV's modes are listed in the plugin web page (Pairing & device → Diagnostics).",
            "type": "array",
            "required": false,
            "items": { "type": "string" }
          },
          "volumeAccessoryType": {
            "title": "Volume accessory type",
            "description": "How the volume accessory appears in the Home app. Lightbulb: brightness = volume, on/off = sound on/off (note: \"Hey Siri, turn off all the lights\" also mutes the TV). Fan: speed = volume, on/off = sound on/off, not affected by light commands.",
            "type": "string",
            "default": "lightbulb",
            "oneOf": [
              { "title": "Lightbulb (default)", "enum": ["lightbulb"] },
              { "title": "Fan (not affected by \"turn off all the lights\")", "enum": ["fan"] }
            ],
            "required": false
          },
          "muteSwitch": {
            "title": "Mute switch",
            "description": "Add a '<name> Mute' switch (on = TV muted) for Siri and automations, e.g. \"Hey Siri, turn on TV55 Mute\". It is added to the volume accessory, or published on its own if the volume accessory is off.",
            "type": "boolean",
            "required": false
          },
          "volumeUI": {
            "title": "Volume On-Screen Display",
            "description": "Show the TV's native volume slider overlay on screen when changing volume via HomeKit. Requires setAudioVolume v1.2+. Defaults to false (silent volume changes).",
            "type": "boolean",
            "required": false
          },
          "debug": {
            "title": "Debug Log Output",
            "description": "Gives additional debug output in the log",
            "type": "boolean",
            "required": false
          },
          "soundoutput": {
            "title": "Sound Output",
            "description": "Required for volume control",
            "type": "string",
            "default": "speaker",
            "oneOf": [
              { "title": "Speaker", "enum": ["speaker"] },
              { "title": "Headphone", "enum": ["headphone"] }
            ],
            "required": false
          },
          "tvsource": {
            "title": "TV Source",
            "description": "Select TV input to display TV channels in the input list",
            "type": "string",
            "oneOf": [
              { "title": "Satellite", "enum": ["tv:dvbs"] },
              { "title": "Antenna", "enum": ["tv:dvbt"] },
              { "title": "Cable", "enum": ["tv:dvbc"] }
            ],
            "required": false
          },
          "applications": {
            "title": "App",
            "description": "Leave empty to not list TV apps in the input list, add app names to show those apps. A part of the name should suffice.",
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "title": "App Name",
                  "type": "string"
                }
              }
            },
            "required": false
          },
          "sources": {
            "title": "Source",
            "description": "Leave empty to let the plugin read the input list from the TV. If set, ONLY these Sony source URIs are scanned, e.g. extInput:hdmi, extInput:composite, extInput:scart, extInput:cec, extInput:widi. Do not enter input names such as HDMI 3: use the Channel Selector to pick single inputs.",
            "type": "array",
            "required": false,
            "items": {
              "title": "Source Name",
              "type": "string"
            }
          }
        }
      }
    }
  },
  "form": [
    "autoscan",
    "discoveryRange",
    {
      "key": "tvs",
      "items": [
        "tvs[].name",
        "tvs[].ip",
        "tvs[].tvsource",
        "tvs[].soundoutput",
        "tvs[].port",
        "tvs[].psk",
        "tvs[].mac",
        "tvs[].serverPort",
        "tvs[].channelSelectorPort",
        "tvs[].enableChannelSelector",
        "tvs[].maxInputSources",
        "tvs[].externalaccessory",
        "tvs[].volumeAccessory",
        "tvs[].volumeAccessoryType",
        "tvs[].muteSwitch",
        "tvs[].volumeUI",
        "tvs[].appsAccessory",
        "tvs[].recordingsAccessory",
        "tvs[].functionsAccessory",
        "tvs[].controlsAccessory",
        "tvs[].controlsScenes",
        "tvs[].debug",
        {
          "key": "tvs[].applications",
          "items": [
            {
              "key": "tvs[].applications[]",
              "items": [
                "tvs[].applications[].title"
              ]
            }
          ]
        },
        {
          "key": "tvs[].sources",
          "items": ["tvs[].sources[]"]
        }
      ]
    }
  ]
}