Skip to content

Commit

Permalink
Merge pull request #93 from nielsfaber/update_configuration
Browse files Browse the repository at this point in the history
Update configuration
  • Loading branch information
nielsfaber committed Sep 30, 2020
2 parents d518553 + 8659b1f commit f9b9e51
Show file tree
Hide file tree
Showing 14 changed files with 1,044 additions and 680 deletions.
393 changes: 137 additions & 256 deletions README.md

Large diffs are not rendered by default.

380 changes: 245 additions & 135 deletions dist/scheduler-card.js

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ function extendActionVariables(cfg: IActionConfig, entity: IHassEntity) {

if ('options' in variableCfg) {
let optionCfg = [...variableCfg.options!];

let hasValueTemplates = typeof optionCfg == "object" ? Object.values(optionCfg).map(e => e.value.match(/^attribute:(\w+):\w+$/)).find(e => e) : null;
optionCfg = optionCfg.map(e => {
if (typeof e != "object") return <IListVariableOption>{ value: e };
return <IListVariableOption>extend(e, { value: replaceAttributeTemplate(e.value, entity) });
}).filter(e => e.value);
if (hasValueTemplates !== null) {
let discoveredOptions: IListVariableOption[] = entity.attributes[hasValueTemplates![1]].filter(e => Object.values(optionCfg).every(el => el.value != e)).map(e => <IListVariableOption>{ value: e });
optionCfg = optionCfg.concat(discoveredOptions);
}

optionCfg.sort((a, b) => {
let val_a = a.name ? a.name : a.value;
let val_b = b.name ? b.name : b.value;
return val_a > val_b ? 1 : -1
})
variableCfg = extend(variableCfg, { options: optionCfg }, { overwrite: true });

let listCfg = <IListVariableConfig>extend(DefaultListVariableConfig, variableCfg);
Expand Down
185 changes: 185 additions & 0 deletions src/config-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"type": "object",
"properties": {
"type": {
"type": "string"
},
"style": {},
"discover_existing": {
"type": "boolean"
},
"standard_configuration": {
"type": "boolean"
},
"title": {
"type": [
"boolean",
"string"
]
},
"am_pm": {
"type": "boolean"
},
"time_step": {
"type": "integer",
"minimum": 1,
"maximum": 60
},
"include": {
"type": "array",
"items": {
"type": "string"
}
},
"exclude": {
"type": "array",
"items": {
"type": "string"
}
},
"groups": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"icon": {
"type": "string"
},
"include": {
"type": "array",
"items": {
"type": "string"
}
},
"exclude": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"name"
],
"additionalProperties": false
}
},
"customize": {
"type": "object",
"additionalProperties": {
"type": [
"object"
],
"properties": {
"icon": {
"type": "string"
},
"name": {
"type": "string"
},
"actions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"icon": {
"type": "string"
},
"name": {
"type": "string"
},
"service": {
"type": "string"
},
"service_data": {
"type": "object"
},
"variable": {
"type": "object",
"oneOf": [
{
"properties": {
"field": {
"type": "string"
},
"name": {
"type": "string"
},
"unit": {
"type": "string"
},
"min": {
"type": "number",
"minimum": 0
},
"max": {
"type": "number",
"minimum": 1
},
"step": {
"type": "number",
"minimum": 0.1
},
"optional": {
"type": "boolean"
}
},
"required": [
"field"
],
"additionalProperties": false
},
{
"properties": {
"field": {
"type": "string"
},
"name": {
"type": "string"
},
"options": {
"type": "array",
"items": {
"type": "object",
"properties": {
"value": {
"type": "string"
},
"name": {
"type": "string"
},
"icon": {
"type": "string"
}
},
"required": [
"value"
],
"additionalProperties": false
}
}
},
"required": [
"field"
],
"additionalProperties": false
}
]
}
},
"required": [
"service"
],
"additionalProperties": false
}
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
Loading

0 comments on commit f9b9e51

Please sign in to comment.