{
  "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. If the TV guide (EPG) is configured, the guide is at the same address under /epg (e.g. http://<homebridge-ip>:8999/epg); the exact URL is printed in the log at start-up.",
  "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"
            }
          },
          "hideDisconnectedInputs": {
            "title": "Hide disconnected HDMI inputs",
            "description": "Hide HDMI inputs with nothing connected from the Home app input list.",
            "type": "boolean",
            "default": false
          },
          "wolMode": {
            "title": "Wake-on-LAN mode",
            "description": "auto: local broadcast. directed-broadcast: send to the subnet broadcast address (needed when Homebridge and the TV are on different VLANs). disabled: REST power-on only. Default: auto, or directed-broadcast when a WOL address is set.",
            "type": "string",
            "oneOf": [
              {
                "title": "Auto",
                "enum": [
                  "auto"
                ]
              },
              {
                "title": "Directed broadcast (cross-VLAN)",
                "enum": [
                  "directed-broadcast"
                ]
              },
              {
                "title": "Disabled",
                "enum": [
                  "disabled"
                ]
              }
            ],
            "required": false
          },
          "woladdress": {
            "title": "WOL broadcast address",
            "description": "Broadcast address for directed broadcast, e.g. 192.168.11.255 (NOT the TV IP). Derived from the TV IP when empty.",
            "type": "string",
            "format": "ipv4",
            "placeholder": "192.168.11.255",
            "required": false
          },
          "wolBurstCount": {
            "title": "WOL burst count",
            "description": "Magic packets sent per power-on attempt. Default 5.",
            "type": "integer",
            "placeholder": "5",
            "minimum": 1,
            "required": false
          },
          "wolBurstInterval": {
            "title": "WOL burst interval (ms)",
            "description": "Delay between magic packets. Default 500.",
            "type": "integer",
            "placeholder": "500",
            "minimum": 50,
            "required": false
          },
          "wakeWaitMaxMs": {
            "title": "Wake wait max (ms)",
            "description": "How long to wait for the TV to answer after WOL. Default 45000.",
            "type": "integer",
            "placeholder": "45000",
            "minimum": 1000,
            "required": false
          },
          "wakeWaitIntervalMs": {
            "title": "Wake wait poll interval (ms)",
            "description": "Power-status poll interval while waiting after WOL. Default 2000.",
            "type": "integer",
            "placeholder": "2000",
            "minimum": 250,
            "required": false
          },
          "postWakePollRate": {
            "title": "Post-wake poll rate (ms)",
            "description": "Faster status polling right after the TV wakes. Default 2000.",
            "type": "integer",
            "placeholder": "2000",
            "minimum": 250,
            "required": false
          },
          "postWakePollWindow": {
            "title": "Post-wake poll window (ms)",
            "description": "Duration of the faster polling after wake. Default 30000.",
            "type": "integer",
            "placeholder": "30000",
            "minimum": 0,
            "required": false
          },
          "postWakeScanDelay": {
            "title": "Post-wake scan delay (ms)",
            "description": "Delay before the channel/input scan after wake. Default 3000.",
            "type": "integer",
            "placeholder": "3000",
            "minimum": 0,
            "required": false
          },
          "updaterate": {
            "title": "Status poll rate, TV on (ms)",
            "description": "Default 5000.",
            "type": "integer",
            "placeholder": "5000",
            "minimum": 1000,
            "required": false
          },
          "standbyUpdateRate": {
            "title": "Status poll rate, TV in standby (ms)",
            "description": "Default 25000.",
            "type": "integer",
            "placeholder": "25000",
            "minimum": 1000,
            "required": false
          },
          "channelupdaterate": {
            "title": "Channel refresh interval (ms)",
            "description": "Periodic channel list refresh. 0 disables it. Default 30000.",
            "type": "integer",
            "placeholder": "30000",
            "minimum": 0,
            "required": false
          },
          "starttimeout": {
            "title": "Start timeout (ms)",
            "description": "Default 5000.",
            "type": "integer",
            "placeholder": "5000",
            "minimum": 500,
            "required": false
          }
        }
      }
    },
    "epg": {
      "title": "TV guide (EPG)",
      "type": "object",
      "properties": {
        "enabled": {
          "title": "Enable TV guide",
          "type": "boolean",
          "default": true,
          "description": "Shows the 'TV guide' tab in the plugin web UI at http://<homebridge-ip>:<port>/epg (default port 8999; the exact URL is printed in the Homebridge log at start-up). Uses the TV channels selected in the Channel Selector. A 'Download guide now' button on that page forces a refresh."
        },
        "urls": {
          "title": "XMLTV sources",
          "type": "array",
          "description": "One or more XMLTV URLs (.xml or .xml.gz). The first source has priority when several provide the same channel. Configured only here, never through the plugin web page. Free XMLTV guides for 69 countries: https://iptv-epg.org/guides (e.g. Italy: https://iptv-epg.org/files/epg-it.xml, Switzerland: https://iptv-epg.org/files/epg-ch.xml). Use XMLTV guides, not M3U playlists.",
          "items": {
            "type": "string",
            "title": "XMLTV URL",
            "pattern": "^https?://",
            "placeholder": "https://example.org/guide.xml.gz"
          }
        },
        "refreshHours": {
          "title": "Refresh every (hours)",
          "type": "integer",
          "minimum": 1,
          "maximum": 168,
          "placeholder": "12"
        },
        "siriToken": {
          "title": "Siri / Shortcuts token",
          "type": "string",
          "minLength": 12,
          "description": "Optional. Enables spoken TV-guide questions in Italian from an Apple Shortcut (e.g. \"cosa c'è stasera su Rai 1?\") at http://<homebridge-ip>:<port>/api/epg/ask. At least 12 random characters; the Shortcut sends it in the X-Token header. Leave empty to keep the feature off. LAN/VPN only: do not expose the port to the Internet."
        },
        "recordMarginBefore": {
          "title": "Recording: start earlier (minutes)",
          "type": "integer",
          "minimum": 0,
          "maximum": 30,
          "placeholder": "2",
          "description": "Timer recordings from the TV guide start this many minutes before the programme (0-30, default 2)."
        },
        "recordMarginAfter": {
          "title": "Recording: end later (minutes)",
          "type": "integer",
          "minimum": 0,
          "maximum": 30,
          "placeholder": "5",
          "description": "Timer recordings end this many minutes after the programme (0-30, default 5)."
        }
      }
    }
  },
  "form": [
    "autoscan",
    "discoveryRange",
    {
      "type": "fieldset",
      "title": "TV guide (EPG)",
      "expandable": true,
      "expanded": false,
      "items": [
        "epg.enabled",
        {
          "key": "epg.urls",
          "type": "array",
          "items": [
            "epg.urls[]"
          ]
        },
        "epg.refreshHours",
        "epg.siriToken",
        "epg.recordMarginBefore",
        "epg.recordMarginAfter"
      ]
    },
    {
      "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",
        {
          "type": "section",
          "title": "Advanced: power, Wake-on-LAN and polling",
          "expandable": true,
          "expanded": false,
          "items": [
            "tvs[].hideDisconnectedInputs",
            "tvs[].wolMode",
            "tvs[].woladdress",
            "tvs[].wolBurstCount",
            "tvs[].wolBurstInterval",
            "tvs[].wakeWaitMaxMs",
            "tvs[].wakeWaitIntervalMs",
            "tvs[].postWakePollRate",
            "tvs[].postWakePollWindow",
            "tvs[].postWakeScanDelay",
            "tvs[].updaterate",
            "tvs[].standbyUpdateRate",
            "tvs[].channelupdaterate",
            "tvs[].starttimeout"
          ],
          "key": "tvs[]"
        },
        "tvs[].debug",
        {
          "key": "tvs[].applications",
          "items": [
            {
              "key": "tvs[].applications[]",
              "items": [
                "tvs[].applications[].title"
              ]
            }
          ]
        },
        {
          "key": "tvs[].sources",
          "items": [
            "tvs[].sources[]"
          ]
        }
      ]
    }
  ]
}
