{
    "pluginAlias": "ISY",
    "pluginType": "platform",
    "singular": true,
    "headerDisplay": "Homebridge Plugin for ISY Series of Controllers from Universal Devices, Inc.",

    "schema": {
           "$schema": "http://json-schema.org/schema",
        "type": "object",
        "definitions": {
            "DeviceConfig": {
                "properties": {
                    "filter": {
                        "$ref": "#/definitions/DeviceFilterRule"
                    },
                    "mapping": {
                        "$ref": "#/definitions/DeviceServiceMapping"
                    },
                    "triggers": {
                        "items": {
                            "$ref": "#/definitions/DevicePropertyTrigger"
                        },
                        "type": "array"
                    },
                    "newName": {
                        "type": "string"
                    },
                    "exclude": {
                        "type": "boolean",
                        "default": true
                    }
                },

                "type": "object"
            },
            "DevicePropertyTrigger": {
                "properties": {
                    "property": {
                        "type": "string"
                    },
                    "target": {
                        "properties": {
                            "address": {
                                "type": "string"
                            },
                            "command": {
                                "type": "string"
                            },
                            "name": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    },
                    "value": {
                        "type": "string"
                    }
                },
                "type": "object"
            },
            "DeviceServiceMapping": {
                "properties": {
                    "properties": {
                        "items": {
                            "$ref": "#/definitions/PropertyCharacteristicMapping"
                        },
                        "type": "array"
                    },
                    "service": {
                        "type": "string"
                    }
                },
                "type": "object"
            },

            "DeviceFilterRule": {
                "properties": {
                    "filterType": {
                        "type": "string",
                        "enum": ["address", "family", "folder", "name", "nodeDef", "typeCode", "function"]
                    },
                    "address": {
                        "type": "string"
                    },
                    "family": {
                        "type": "string",
                        "enum": ["Scene", "Elk", "Insteon", "ZWave", "ZigBee", "UPB", "UDI", "Poly"]
                    },
                    "folder": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "nodeDef": {
                        "type": "string"
                    },
                    "typeCode": {
                        "type": "string"
                    },
                    "lastAddressDigit": {
                        "type": "string"
                    },
                    "nodeServer": {
                        "type": "string"
                    }
                    ,
                    "function": {
                        "type": "string"
                    }
                },
                "type": "object"
            },
            "PropertyCharacteristicMapping": {
                "properties": {
                    "property": {
                        "type": "string"
                    },
                    "service": {
                        "type": "string"
                    },
                    "characteristic": {
                        "type": "string"
                    }
                },
                "type": "object"
            },
            "RenameDeviceRule": {
                "properties": {
                    "address": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "newName": {
                        "type": "string"
                    }
                },
                "type": "object"
            }
        },
        "properties": {
            "name": {
                "title": "Name",
                "type": "string",
                "required": true,
                "default": "ISY"
            },
            "host": {
                "title": "IP/Hostname of ISY",
                "type": "string",
                "format": "hostname",
                "required": true
            },
            "useHttps": {
                "title": "Use HTTPS",
                "type": "boolean",
                "default": true,
                "required": true,

                "oneOf": [{
                    "title": "HTTPS",
                    "enum": [true]
                }, {
                    "title": "HTTP",
                    "enum": [false]
                }]

            },
            "username": {
                "type": "string"
            },
            "password": {
                "type": "string"
            },
            "debugLoggingEnabled": {
                "title": "Enable Debug Logging",
                "type": "boolean"
            },

            "elkEnabled": {
                "title": "Enable Elk Devices",
                "type": "boolean"
            },


            "deviceNaming": {
                "title": "Device Naming",
                "type": "object",
                "properties": {
                    "format": {
                        "title": "Format",
                        "description": "Formatting for device name, using javascript string interpolation syntax.",
                        "type": "string",
                        "default": "${location ?? folder} ${spokenName ?? name}",
                        "examples": ["${location ?? folder} ${spokenName ?? name}", "${spokenName ?? name}"]
                    },
                    "remove": {
                        "title": "Text to Remove",
                        "items": {
                            "type": "string"
                        },
                        "type": "array"
                    },
                    "replace": {
                        "title": "Text to Replace",
                        "items": {
                            "properties": {
                                "replace": {
                                    "type": "string"
                                },
                                "with": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        },
                        "type": "array"
                    }

                }
            },
            "deviceDefaults": {
                "$ref": "#/definitions/DeviceConfig"
            },
            "devices": {
                "title": "Device List (Optional)",
                "items": {

                    "$ref": "#/definitions/DeviceConfig"


                },
                "type": "array"
            },

            "platform": {
                "type": "string",
                "default": "ISY"
            }
        }

    },
    "layout": [
        "name",
        {
            "type": "flex",
            "flex-flow": "row wrap",
            "items": [
                "host",
                {
                    "key": "useHttps",
                    "type": "select",
                    "title": "Protocol"
                }
            ]
        },
        {
            "type": "flex",
            "flex-flow": "row wrap",
            "items": [
                "username",
                {
                    "key": "password",
                    "type": "password"
                }
            ]
        },
        {
            "type": "flex",
            "flex-flow": "row wrap",
            "items": [
                "debugLoggingEnabled",
                "elkEnabled"
            ]
        },
        {
            "type": "fieldset",
            "expandable": "true",
            "expanded": "false",
            "title": "Defaults",
            "items": [{
                    "key": "deviceDefaults.exclude",
                    "type": "select",
                    "title": "Device Availability",
                    "required": true,
                    "default": false,
                    "titleMap": [{
                        "name": "Hidden by Default",
                        "value": true
                    }, {
                        "name": "Exposed by Default",
                        "value": false
                    }]
                },

                {


                    "description": "Rules used to render the device/accessory display name as seen by HomeKit.",
                    "key": "deviceNaming",
                    "items": [{
                            "key": "deviceNaming.format"
                        }, {
                            "description": "Text to Remove",
                            "key": "deviceNaming.remove",
                            "notitle": true,
                            "type": "array",
                            "items": "deviceNaming.remove[]"
                        },
                        {
                            "key": "deviceNaming.replace",
                            "description": "Text to Replace",
                            "notitle": true,
                            "type": "array",
                            "items": [{
                                "notitle": true,
                                "type": "flex",
                                "flex-flow": "row wrap",
                                "items": [{
                                        "key": "deviceNaming.replace[].replace",
                                        "notitle": true,
                                        "placeholder": "Text to substitute"
                                    },
                                    {
                                        "key": "deviceNaming.replace[].with",
                                        "notitle": true,
                                        "placeholder": "Replacement text"
                                    }
                                ]
                            }]
                        }
                    ]
                }
            ]
        },

        {
            "type": "fieldset",
            "expandable": "true",
            "expanded": "false",
            "title": "Device List (Optional)",
            "description": "Optional list of devices to explicitly exclude or include and rename/configure",
            "items": [

                {
                    "key": "devices",
                    "add": "new",
                    "buttonText": "Add Device",
                    "notitle": true,
                    "type": "array",
                    "items": [{
                            "key": "devices[].filter.filterType",
                            "placeholder": "Identify Using",
                            "titleMap": [{
                                    "value": "name",
                                    "name": "Name"
                                },
                                {
                                    "value": "address",
                                    "name": "Address"
                                },
                                {
                                    "value": "family",
                                    "name": "Family"
                                },
                                {
                                    "value": "folder",
                                    "name": "Folder"
                                },
                                {
                                    "value": "nodeDef",
                                    "name": "ISY Nodedef Code (Advanced)"
                                },
                                {
                                    "value": "typeCode",
                                    "name": "ISY Type Code (Advanced)"
                                },
                                {
                                    "value": "custom",
                                    "name": "Custom Function (Advanced)"
                                }
                            ],
                            "required": "true"
                        },
                        {
                            "key": "devices[].filter.name",
                            "required": true,
                            "notitle": true,
                            "condition": "model.devices[arrayIndex].filter.filterType=='name'",
                            "placeholder": "Device/Scene Name (any part)"

                        },
                        {
                            "key": "devices[].filter.folder",
                            "notitle": true,
                            "required": true,
                            "condition": "model.devices[arrayIndex].filter.filterType=='folder'",
                            "placeholder": "Parent Folder"
                        },
                        {
                            "key": "devices[].filter.family",

                            "required": true,
                            "notitle": true,
                            "condition": "model.devices[arrayIndex].filter.filterType=='family'",
                            "placeholder": "Device Family",
                            "default": "Scene",
                            "titleMap": [{
                                    "value": "Elk",
                                    "name": "Elk"
                                },
                                {
                                    "value": "Insteon",
                                    "name": "Insteon"
                                },
                                {
                                    "value": "UPB",
                                    "name": "UPB"
                                },
                                {
                                    "value": "ZigBee",
                                    "name": "ZigBee/RCS"
                                },
                                {
                                    "value": "ZWave",
                                    "name": "Z-Wave"
                                },
                                {
                                    "value": "Scene",
                                    "name": "Scene"
                                },
                                {
                                    "value": "Poly",
                                    "name": "Poly/NodeServer"
                                }
                            ]

                        },
                        {
                            "key": "devices[].filter.address",
                            "required": true,
                            "notitle": true,
                            "condition": "model.devices[arrayIndex].filter.filterType=='address'"
                        },
                        {
                            "key": "devices[].filter.nodeDef",

                            "required": true,
                            "notitle": true,
                            "condition": "model.devices[arrayIndex].filter.filterType=='nodeDef'"
                        },
                        {
                            "key": "devices[].filter.typeCode",
                            "required": true,
                            "notitle": true,
                            "condition": "model.devices[arrayIndex].filter.filterType=='typeCode'"
                        },
                        {
                            "key": "devices[].filter.lastAddressDigit",
                            "placeholder": "Last Digit of Address",
                            "notitle": true,
                            "flex": "1 1 50px",
                            "condition": "model.devices[arrayIndex].filter.filterType=='name'"
                        },
                        {
                            "key": "devices[].filter.nodeServer",
                            "title": "NodeServer",
                            "flex": "1 1 50px",
                            "condition": "model.devices[arrayIndex].filter.family=='Poly'"
                        },
                        {
                            "key": "devices[].filter.function",
                            "notitle": true,
                            "description": "body of function which returns true or false",
                            "flex": "1 1 100px",
                            "condition": "model.devices[arrayIndex].filter.filterType=='function'"
                        },
                        {
                            "key": "devices[].exclude",
                            "title": "Exclude",
                            "flex": "1 1 50px",
                            "required": true
                        },
                        {
                            "key": "devices[].newName",
                            "title": "New Name",
                            "flex": "1 1 50px",
                            "required": false,
                            "condition": "model.devices[arrayIndex].filter.filterType=='name'"
                        }
                    ]

                }
            ]
        }
    ],
    "data": {
        "platform": "ISY",
        "name": "ISY",
        "host": "<<IP Address>>",
        "username": "admin",
        "password": "<<Password>>",
        "useHttps": true,
        "elkEnabled": true,
        "debugLoggingEnabled": false,
        "deviceDefaults":
        {
            "exclude":false
        },
        "deviceNaming": {
            "format": "${location ?? folder} ${spokenName ?? name}",
            "remove": [
                "Dimmer",
                "Switch",
                "Fan "
            ],
            "replace": [{
                "replace": ".",
                "with": " "
            }]
        },
        "devices": [{
                "filter": {
                    "filterType": "family",
                    "family": "Scene"
                },
                "exclude": true
            },
            {
                "filter": {
                    "filterType": "nodeDef",
                    "nodeDef": "KeypadButton"
                },
                "exclude": true
            },
            {
                "filter": {
                    "filterType": "name"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "ApplianceLinc",
                    "filterType": "name"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "S -",
                    "filterType": "name"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "ApplianceLink",
                    "filterType": "name"
                },
                "exclude": true
            },
            {
                "filter": {
                    "address": "1 24 A5 1",
                    "filterType": "address"
                },
                "exclude": true
            },
            {
                "filter": {
                    "filterType": "family"
                },
                "exclude": true
            },
            {
                "filter": {
                    "folder": "Old Stuff",
                    "filterType": "folder"
                },
                "exclude": true
            },
            {
                "filter": {
                    "nodeDef": "KeypadButton",
                    "filterType": "nodeDef"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Unused",
                    "filterType": "name"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Remote",
                    "filterType": "name"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Keypad",
                    "filterType": "name",
                    "lastAddressDigit": "2"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Keypad",
                    "filterType": "name",
                    "lastAddressDigit": "3"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Keypad",
                    "filterType": "name",
                    "lastAddressDigit": "4"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Keypad",
                    "filterType": "name",
                    "lastAddressDigit": "5"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Keypad",
                    "filterType": "name",
                    "lastAddressDigit": "6"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Keypad",
                    "filterType": "name",
                    "lastAddressDigit": "7"
                },
                "exclude": true
            },
            {
                "filter": {
                    "name": "Keypad",
                    "filterType": "name",
                    "lastAddressDigit": "8"
                },
                "exclude": true
            }
        ]
    }
}