{
  "pluginAlias": "HomebridgeDummy",
  "pluginType": "platform",
  "singular": true,
  "customUi": true,
  "customUiPath": "./dist/homebridge-ui",
  "schema": {
    "type": "object",
    "definitions": {
      "units": {
        "type": "string",
        "title": "${config.title.units}",
        "enum": [ "MILLISECONDS", "SECONDS", "MINUTES", "HOURS"],
        "enumNames": ["${config.enumNames.milliseconds}", "${config.enumNames.seconds}", "${config.enumNames.minutes}", "${config.enumNames.hours}"]
      },
      "sensor": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "title": "${config.title.sensor}",
            "enum": ["CarbonDioxideSensor", "CarbonMonoxideSensor", "ContactSensor", "LeakSensor", "MotionSensor", "OccupancySensor", "SmokeSensor"],
            "enumNames": ["${config.enumNames.carbonDioxideSensor}", "${config.enumNames.carbonMonoxideSensor}", "${config.enumNames.contactSensor}", "${config.enumNames.leakSensor}", "${config.enumNames.motionSensor}", "${config.enumNames.occupancySensor}", "${config.enumNames.smokeSensor}"]
          },
          "timerControlled": {
            "type": "boolean",
            "title": "${config.title.timerControlled}",
            "description": "${config.description.timerControlled}"
          }
        }
      },
      "timer": {
        "type": "object",
        "properties": {
          "delay": {
            "type": "integer",
            "title": "${config.title.delay}",
            "minimum": 1
          },
          "units": { "$ref": "#/definitions/units" },
          "random": {
            "type": "boolean",
            "title": "${config.title.random}",
            "description": "${config.description.random}"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "delay": {
                }
              },
              "required": ["delay"]
            },
            "then": {
              "required": ["units"]
            }
          },
          {
            "if": {
              "properties": {
                "units" : {
                }
              },
              "required": [ "units" ]
            },
            "then": {
              "required": [ "delay"]
            }
          }
        ]
      },
      "schedule": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "title": "${config.title.type}",
            "enum": [ "INTERVAL", "CRON"],
            "enumNames": ["${config.enumNames.interval}", "${config.enumNames.cron}"]
          },
          "interval": {
            "type": "integer",
            "title": "${config.title.interval}",
            "minimum": 1
          },
          "units": { "$ref": "#/definitions/units" },
          "random": {
            "type": "boolean",
            "title": "${config.title.random}",
            "description": "${config.description.random}"
          },
          "cron": {
            "type": "string",
            "title": "${config.title.preset}",
            "enum": [ "@secondly", "@minutely", "@hourly", "@daily", "@weekly", "@weekdays", "@weekends", "@monthly", "@yearly", "CRON_CUSTOM"],
            "enumNames": ["${config.enumNames.secondly}", "${config.enumNames.minutely}", "${config.enumNames.hourly}", "${config.enumNames.daily}", "${config.enumNames.weekly}", "${config.enumNames.weekdays}", "${config.enumNames.weekends}", "${config.enumNames.monthly}", "${config.enumNames.yearly}", "${config.enumNames.custom}"]
          },
          "cronCustom": {
            "type": "string",
            "title": "${config.title.cronCustom}",
            "placeholder": "* * * * * *",
            "pattern": "(^((\\*\\/)?([0-5]?[0-9])((,|-|\\/)([0-5]?[0-9]))*|\\*)\\s((\\*\\/)?((2[0-3]|1[0-9]|[0-9]|00))((,|-|\\/)(2[0-3]|1[0-9]|[0-9]|00))*|\\*)\\s((\\*\\/)?([1-9]|[12][0-9]|3[01])((,|-|\\/)([1-9]|[12][0-9]|3[01]))*|\\*)\\s((\\*\\/)?([1-9]|1[0-2])((,|-|\\/)([1-9]|1[0-2]))*|\\*|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec))\\s((\\*\\/)?[0-6]((,|-|\\/)[0-6])*|\\*|00|(sun|mon|tue|wed|thu|fri|sat))$)"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "type": {
                  "const": "INTERVAL"
                }
              }
            },
            "then": {
              "required": ["interval", "units"]
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "const": "CRON"
                }
              }
            },
            "then": {
              "required": ["cron"]
            }
          },
          {
            "if": {
              "required": ["cron"],
              "properties": {
                "cron": {
                  "const": "CRON_CUSTOM"
                }
              }
            },
            "then": {
              "required": ["cronCustom"]
            }
          }
        ]
      },
      "limiter": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "limit": {
            "type": "number",
            "title": "${config.title.limit}"
          },
          "units": {
            "type": "string",
            "title": "${config.title.units}",
            "enum": [ "SECONDS", "MINUTES", "HOURS"],
            "enumNames": ["${config.enumNames.seconds}", "${config.enumNames.minutes}", "${config.enumNames.hours}"]
          },
          "period": {
            "type": "string",
            "title": "${config.title.period}",
            "enum": [ "HOUR", "DAY", "WEEK", "MONTH"],
            "enumNames": ["${config.enumNames.hour}", "${config.enumNames.day}", "${config.enumNames.week}", "${config.enumNames.month}"]
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "limit": {
                }
              },
              "required": ["limit"]
            },
            "then": {
              "required": ["units", "period"]
            }
          },
          {
            "if": {
              "properties": {
                "units" : {
                }
              },
              "required": [ "units" ]
            },
            "then": {
              "required": [ "limit"]
            }
          },
          {
            "if": {
              "properties": {
                "period" : {
                }
              },
              "required": [ "period" ]
            },
            "then": {
              "required": [ "limit"]
            }
          }
        ]
      }
    },
    "properties": {
      "name": {
        "type": "string",
        "default": "Homebridge Dummy"
      },
      "accessories": {
        "type": "array",
        "items": {
          "type": "object",
          "required": ["name", "type"],
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": "string",
              "title": "${config.title.name}"
            },
            "type": {
              "type": "string",
              "title": "${config.title.type}",
              "enum": ["Door", "GarageDoorOpener", "Lightbulb", "LockMechanism", "Outlet", "Switch", "Thermostat", "Window", "WindowCovering"],
              "enumNames": ["${config.enumNames.door}", "${config.enumNames.garageDoorOpener}", "${config.enumNames.lightbulb}", "${config.enumNames.lockMechanism}", "${config.enumNames.outlet}", "${config.enumNames.switch}", "${config.enumNames.thermostat}", "${config.enumNames.window}", "${config.enumNames.windowCovering}"]
            },
            "groupName": {
              "type": "string",
              "title": "${config.title.groupName}"
            },
            "sensor": { "$ref": "#/definitions/sensor" },
            "timer": { "$ref": "#/definitions/timer" },
            "schedule": { "$ref": "#/definitions/schedule" },
            "limiter": { "$ref": "#/definitions/limiter" },
            "temperatureUnits": {
              "type": "string",
              "title": "${config.title.units}",
              "enum": ["C", "F"],
              "enumNames": ["${config.enumNames.celsius}", "${config.enumNames.fahrenheit}"]
            },
            "defaultBrightness": {
              "type": "number",
              "title": "${config.title.defaultBrightness}",
              "minimum": 0,
              "maximum": 100
            },
            "defaultHue": {
              "type": "number",
              "title": "${config.title.defaultHue}",
              "minimum": 0,
              "maximum": 360
            },
            "defaultSaturation": {
              "type": "number",
              "title": "${config.title.defaultSaturation}",
              "minimum": 0,
              "maximum": 100
            },
            "defaultColorTemperature": {
              "type": "number",
              "title": "${config.title.defaultColorTemperature}",
              "minimum": 0,
              "maximum": 10000
            },
            "defaultOn": {
              "type": "number",
              "title": "${config.title.defaultState}",
              "enum": [1, 0],
              "enumNames": ["${config.enumNames.on}", "${config.enumNames.off}"]
            },
            "defaultLockState": {
              "type": "string",
              "title": "${config.title.defaultState}",
              "enum": ["locked", "unlocked"],
              "enumNames": ["${config.enumNames.secured}", "${config.enumNames.unsecured}"]
            },
            "defaultPosition": {
              "type": "string",
              "title": "${config.title.defaultPosition}",
              "enum": ["open", "closed"],
              "enumNames": ["${config.enumNames.open}", "${config.enumNames.closed}"]
            },
            "defaultThermostatState": {
              "type": "string",
              "title": "${config.title.defaultState}",
              "enum": ["auto", "heat", "cool", "off"],
              "enumNames": ["${config.enumNames.auto}", "${config.enumNames.heat}", "${config.enumNames.cool}", "${config.enumNames.off}"]
            },
            "defaultTemperature": {
              "type": "number",
              "title": "${config.title.defaultTemperature}"
            },
            "commandOn": {
              "type": "string",
              "title": "${config.title.commandOn}"
            },
            "commandOff": {
              "type": "string",
              "title": "${config.title.commandOff}"
            },
            "commandLock": {
              "type": "string",
              "title": "${config.title.commandLock}"
            },
            "commandUnlock": {
              "type": "string",
              "title": "${config.title.commandUnlock}"
            },
            "commandOpen": {
              "type": "string",
              "title": "${config.title.commandOpen}"
            },
            "commandClose": {
              "type": "string",
              "title": "${config.title.commandClose}"
            },
            "commandTemperature": {
              "type": "string",
              "title": "${config.title.commandTemperature}"
            },
            "resetOnRestart": {
              "type": "boolean",
              "title": "${config.title.resetOnRestart}"
            },
            "enableWebook": {
              "type": "boolean",
              "title": "${config.title.enableWebook}"
            },
            "disableLogging": {
              "type": "boolean",
              "title": "${config.title.disableLogging}"
            }
          }
        }
      },
      "verbose": {
        "type": "boolean"
      },
      "webhookPort": {
        "type": "number"
      }
    }
  },
    "layout": [
    {
      "type": "array",
      "key": "accessories",
      "notitle": true,
      "items": [
        {
          "type": "fieldset",
          "expandable": true,
          "title": "${config.title.accessory}",
          "items": [
            {
              "type": "div",
              "displayFlex": true,
              "flex-direction": "row",
              "items": [
                {
                  "key": "accessories[].name",
                  "flex": "1 1 33%"
                },
                {
                  "key": "accessories[].type",
                  "flex": "1 1 33%"
                },
                {
                  "key": "accessories[].groupName",
                  "flex": "1 1 33%"
                }
              ]
            },
            {
              "type": "fieldset",
              "notitle": true,
              "condition": {
                "functionBody": "return model.accessories?.[arguments[1]]?.type !== undefined;"
              },
              "items": [
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "condition": {
                    "functionBody": "return ['Lightbulb','Outlet','Switch'].includes(model.accessories?.[arguments[1]]?.type);"
                  },
                  "items": [
                    {
                      "key": "accessories[].defaultOn",
                      "flex": "0 0 33%"
                    },
                    {
                      "key": "accessories[].sensor.type",
                      "flex": "0 0 33%"
                    },
                    {
                      "key": "accessories[].defaultBrightness",
                      "flex": "0 0 33%",
                      "condition": {
                        "functionBody": "return ['Lightbulb'].includes(model.accessories?.[arguments[1]]?.type);"
                      }
                    }
                  ]
                },
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "condition": {
                    "functionBody": "return ['LockMechanism'].includes(model.accessories?.[arguments[1]]?.type);"
                  },
                  "items": [
                    {
                      "key": "accessories[].defaultLockState",
                      "flex": "0 0 33%"
                    },
                    {
                      "key": "accessories[].sensor.type",
                      "flex": "0 0 33%"
                    }
                  ]
                },
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "condition": {
                    "functionBody": "return ['Door', 'GarageDoorOpener', 'Window', 'WindowCovering'].includes(model.accessories?.[arguments[1]]?.type);"
                  },
                  "items": [
                    {
                      "key": "accessories[].defaultPosition",
                      "flex": "0 0 33%"
                    },
                    {
                      "key": "accessories[].sensor.type",
                      "flex": "0 0 33%"
                    }
                  ]
                },
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "condition": {
                    "functionBody": "return ['Thermostat'].includes(model.accessories?.[arguments[1]]?.type);"
                  },
                  "items": [
                    {
                      "key": "accessories[].temperatureUnits",
                      "flex": "0 0 33%"
                    },
                    {
                      "key": "accessories[].defaultThermostatState",
                      "flex": "0 0 33%"
                    },
                    {
                      "key": "accessories[].defaultTemperature",
                      "flex": "0 0 33%"
                    }
                  ]
                },
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "items": [
                    {
                      "key": "accessories[].enableWebook",
                      "flex": "0 1 33%"
                    },
                    {
                      "key": "accessories[].disableLogging",
                      "flex": "0 1 33%"
                    },
                    {
                      "key": "accessories[].resetOnRestart",
                      "flex": "0 1 33%",
                      "condition": {
                        "functionBody": "return model.accessories?.[arguments[1]]?.schedule?.type === undefined && model.accessories?.[arguments[1]]?.timer?.delay === undefined;"
                      }
                    }
                  ]
                }
              ]
            },
            {
              "type": "fieldset",
              "title": "${config.title.schedule}",
              "description": "${config.description.schedule}",
              "condition": {
                "functionBody": "const type = model.accessories?.[arguments[1]]?.type; return type !== undefined && type !== 'Thermostat';"
              },
              "items": [
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "items": [
                    {
                      "key": "accessories[].schedule.type",
                      "flex": "1 1 33%"
                    },
                    {
                      "key": "accessories[].schedule.interval",
                      "flex": "1 1 33%",
                      "condition": {
                          "functionBody": "return model.accessories?.[arguments[1]]?.schedule?.type === 'INTERVAL';"
                      }
                    },
                    {
                      "key": "accessories[].schedule.units",
                      "flex": "1 1 33%",
                      "condition": {
                          "functionBody": "return model.accessories?.[arguments[1]]?.schedule?.type === 'INTERVAL';"
                      }
                    }
                  ]
                },
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "condition": {
                      "functionBody": "return model.accessories?.[arguments[1]]?.schedule?.type === 'CRON';"
                  },
                  "items": [
                    {
                      "key": "accessories[].schedule.cron",
                      "flex": "1 1 33%"
                    },
                    {
                      "key": "accessories[].schedule.cronCustom",
                      "flex": "1 1 67%",
                      "condition": {
                          "functionBody": "return model.accessories?.[arguments[1]]?.schedule?.cron === 'CRON_CUSTOM';"
                      }
                    }
                  ]
                },
                {
                  "key": "accessories[].schedule.random",
                  "condition": {
                      "functionBody": "const schedule = model.accessories?.[arguments[1]]?.schedule; return schedule?.type === 'INTERVAL' && schedule?.interval !== undefined;"
                  }
                }
              ]
            },
            {
              "type": "fieldset",
              "title": "${config.title.timer}",
              "description": "${config.description.timer}",
              "condition": {
                "functionBody": "const type = model.accessories?.[arguments[1]]?.type; return type !== undefined && type !== 'Thermostat';"
              },
              "items": [
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "items": [
                    {
                      "key": "accessories[].timer.delay",
                      "flex": "1 1 33%"
                    },
                    {
                      "key": "accessories[].timer.units",
                      "flex": "1 1 33%"
                    }
                  ]
                },
                {
                  "type": "fieldset",
                  "notitle": true,
                  "condition": {
                    "functionBody": "return model.accessories?.[arguments[1]]?.timer?.delay !== undefined;"
                  },
                  "items": [
                    "accessories[].timer.random",
                    {
                      "key": "accessories[].sensor.timerControlled",
                      "condition": {
                          "functionBody": "return model.accessories?.[arguments[1]]?.sensor?.type !== undefined;"
                      }
                    }
                  ]
                }
              ]
            },
            {
              "type": "fieldset",
              "title": "${config.title.limiter}",
              "description": "${config.description.limiter}",
              "condition": {
                "functionBody": "const type = model.accessories?.[arguments[1]]?.type; return type !== undefined && type !== 'Thermostat';"
              },
              "items": [
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "items": [
                    {
                      "key": "accessories[].limiter.limit",
                      "flex": "1 1 33%"
                    },
                    {
                      "key": "accessories[].limiter.units",
                      "flex": "1 1 33%"
                    },
                    {
                      "key": "accessories[].limiter.period",
                      "flex": "1 1 33%"
                    }
                  ]
                }
              ]
            },
            {
              "type": "fieldset",
              "title": "${config.title.commands}",
              "description": "${config.description.commands}",
              "condition": {
                "functionBody": "return model.accessories?.[arguments[1]]?.type !== undefined;"
              },
              "items": [
                {
                  "key": "accessories[].commandOn",
                  "condition": {
                    "functionBody": "return ['Lightbulb','Outlet','Switch','Thermostat'].includes(model.accessories?.[arguments[1]]?.type);"
                  }
                },
                {
                  "key": "accessories[].commandOff",
                  "condition": {
                    "functionBody": "return ['Lightbulb','Outlet','Switch','Thermostat'].includes(model.accessories?.[arguments[1]]?.type);"
                  }
                },
                {
                  "key": "accessories[].commandLock",
                  "condition": {
                    "functionBody": "return ['LockMechanism'].includes(model.accessories?.[arguments[1]]?.type);"
                  }
                },
                {
                  "key": "accessories[].commandUnlock",
                  "condition": {
                    "functionBody": "return ['LockMechanism'].includes(model.accessories?.[arguments[1]]?.type);"
                  }
                },
                {
                  "key": "accessories[].commandOpen",
                  "condition": {
                    "functionBody": "return ['Door', 'GarageDoorOpener', 'Window', 'WindowCovering'].includes(model.accessories?.[arguments[1]]?.type);"
                  }
                },
                {
                  "key": "accessories[].commandClose",
                  "condition": {
                    "functionBody": "return ['Door', 'GarageDoorOpener', 'Window', 'WindowCovering'].includes(model.accessories?.[arguments[1]]?.type);"
                  }
                },
                {
                  "key": "accessories[].commandTemperature",
                  "condition": {
                    "functionBody": "return ['Thermostat'].includes(model.accessories?.[arguments[1]]?.type);"
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}