diff --git a/gulp/tasks/rollup.js b/gulp/tasks/rollup.js index b554296e8d..27b4464574 100644 --- a/gulp/tasks/rollup.js +++ b/gulp/tasks/rollup.js @@ -6,7 +6,8 @@ gulp.task('run_rollup', () => { return gulp.src([ 'js/core.js', 'js/compatibility.js', - 'js/editor/editor.js', + 'js/automation-editor/automation-editor.js', + 'js/script-editor/script-editor.js', 'demo_data/demo_data.js', ]) .pipe(rollupEach(rollupConfig)) diff --git a/js/editor/editor.js b/js/automation-editor/automation-editor.js similarity index 100% rename from js/editor/editor.js rename to js/automation-editor/automation-editor.js diff --git a/js/editor/automation.js b/js/automation-editor/automation.js similarity index 97% rename from js/editor/automation.js rename to js/automation-editor/automation.js index 08c4f1c36a..12108f46e2 100644 --- a/js/editor/automation.js +++ b/js/automation-editor/automation.js @@ -1,8 +1,8 @@ import { h, Component } from 'preact'; import Trigger from './trigger'; -import Condition from './condition'; -import Script from './script'; +import Condition from '../common/component/condition'; +import Script from '../common/component/script'; export default class Automation extends Component { constructor() { diff --git a/js/editor/trigger/event.js b/js/automation-editor/trigger/event.js similarity index 88% rename from js/editor/trigger/event.js rename to js/automation-editor/trigger/event.js index 11d032206d..1c270233f0 100644 --- a/js/editor/trigger/event.js +++ b/js/automation-editor/trigger/event.js @@ -1,8 +1,8 @@ import { h, Component } from 'preact'; -import JSONTextArea from '../json_textarea'; +import JSONTextArea from '../../common/component/json_textarea'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../common/util/event'; export default class EventTrigger extends Component { constructor() { diff --git a/js/editor/trigger/homeassistant.js b/js/automation-editor/trigger/homeassistant.js similarity index 100% rename from js/editor/trigger/homeassistant.js rename to js/automation-editor/trigger/homeassistant.js diff --git a/js/editor/trigger/index.js b/js/automation-editor/trigger/index.js similarity index 100% rename from js/editor/trigger/index.js rename to js/automation-editor/trigger/index.js diff --git a/js/editor/trigger/mqtt.js b/js/automation-editor/trigger/mqtt.js similarity index 92% rename from js/editor/trigger/mqtt.js rename to js/automation-editor/trigger/mqtt.js index 59540ea92c..ba50998ac2 100644 --- a/js/editor/trigger/mqtt.js +++ b/js/automation-editor/trigger/mqtt.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../common/util/event'; export default class MQTTTrigger extends Component { constructor() { diff --git a/js/editor/trigger/numeric_state.js b/js/automation-editor/trigger/numeric_state.js similarity index 95% rename from js/editor/trigger/numeric_state.js rename to js/automation-editor/trigger/numeric_state.js index ff7f4e5c41..0f212f53ca 100644 --- a/js/editor/trigger/numeric_state.js +++ b/js/automation-editor/trigger/numeric_state.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../common/util/event'; export default class NumericStateTrigger extends Component { constructor() { diff --git a/js/editor/trigger/state.js b/js/automation-editor/trigger/state.js similarity index 94% rename from js/editor/trigger/state.js rename to js/automation-editor/trigger/state.js index 5537f6ecaf..32ae9a3c46 100644 --- a/js/editor/trigger/state.js +++ b/js/automation-editor/trigger/state.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../common/util/event'; export default class StateTrigger extends Component { constructor() { diff --git a/js/editor/trigger/sun.js b/js/automation-editor/trigger/sun.js similarity index 95% rename from js/editor/trigger/sun.js rename to js/automation-editor/trigger/sun.js index 88a4a55224..4beb94d2d4 100644 --- a/js/editor/trigger/sun.js +++ b/js/automation-editor/trigger/sun.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../common/util/event'; export default class SunTrigger extends Component { constructor() { diff --git a/js/editor/trigger/template.js b/js/automation-editor/trigger/template.js similarity index 91% rename from js/editor/trigger/template.js rename to js/automation-editor/trigger/template.js index 701ca05f27..6cfc310bf1 100644 --- a/js/editor/trigger/template.js +++ b/js/automation-editor/trigger/template.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../common/util/event'; export default class TemplateTrigger extends Component { constructor() { diff --git a/js/editor/trigger/time.js b/js/automation-editor/trigger/time.js similarity index 89% rename from js/editor/trigger/time.js rename to js/automation-editor/trigger/time.js index 0cc8487f24..723d36244b 100644 --- a/js/editor/trigger/time.js +++ b/js/automation-editor/trigger/time.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../common/util/event'; export default class TimeTrigger extends Component { constructor() { diff --git a/js/editor/trigger/trigger_edit.js b/js/automation-editor/trigger/trigger_edit.js similarity index 100% rename from js/editor/trigger/trigger_edit.js rename to js/automation-editor/trigger/trigger_edit.js diff --git a/js/editor/trigger/trigger_row.js b/js/automation-editor/trigger/trigger_row.js similarity index 100% rename from js/editor/trigger/trigger_row.js rename to js/automation-editor/trigger/trigger_row.js diff --git a/js/editor/trigger/zone.js b/js/automation-editor/trigger/zone.js similarity index 95% rename from js/editor/trigger/zone.js rename to js/automation-editor/trigger/zone.js index 86fbc38b03..38db36d6ac 100644 --- a/js/editor/trigger/zone.js +++ b/js/automation-editor/trigger/zone.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../common/util/event'; export default class ZoneTrigger extends Component { constructor() { diff --git a/js/editor/condition/condition_edit.js b/js/common/component/condition/condition_edit.js similarity index 100% rename from js/editor/condition/condition_edit.js rename to js/common/component/condition/condition_edit.js diff --git a/js/editor/condition/condition_row.js b/js/common/component/condition/condition_row.js similarity index 100% rename from js/editor/condition/condition_row.js rename to js/common/component/condition/condition_row.js diff --git a/js/editor/condition/index.js b/js/common/component/condition/index.js similarity index 100% rename from js/editor/condition/index.js rename to js/common/component/condition/index.js diff --git a/js/editor/condition/numeric_state.js b/js/common/component/condition/numeric_state.js similarity index 95% rename from js/editor/condition/numeric_state.js rename to js/common/component/condition/numeric_state.js index 7849c8a9db..0597d62c4b 100644 --- a/js/editor/condition/numeric_state.js +++ b/js/common/component/condition/numeric_state.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class NumericStateCondition extends Component { constructor() { diff --git a/js/editor/condition/state.js b/js/common/component/condition/state.js similarity index 94% rename from js/editor/condition/state.js rename to js/common/component/condition/state.js index 0eafaca80d..5312559325 100644 --- a/js/editor/condition/state.js +++ b/js/common/component/condition/state.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class StateCondition extends Component { constructor() { diff --git a/js/editor/condition/sun.js b/js/common/component/condition/sun.js similarity index 97% rename from js/editor/condition/sun.js rename to js/common/component/condition/sun.js index 23064c6b0d..e8dbdaa127 100644 --- a/js/editor/condition/sun.js +++ b/js/common/component/condition/sun.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class SunCondition extends Component { constructor() { diff --git a/js/editor/condition/template.js b/js/common/component/condition/template.js similarity index 92% rename from js/editor/condition/template.js rename to js/common/component/condition/template.js index 2427879d34..34c3bac498 100644 --- a/js/editor/condition/template.js +++ b/js/common/component/condition/template.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class TemplateCondition extends Component { constructor() { diff --git a/js/editor/condition/time.js b/js/common/component/condition/time.js similarity index 93% rename from js/editor/condition/time.js rename to js/common/component/condition/time.js index b6efe42aa7..1e8bc3355e 100644 --- a/js/editor/condition/time.js +++ b/js/common/component/condition/time.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class StateCondition extends Component { constructor() { diff --git a/js/editor/condition/zone.js b/js/common/component/condition/zone.js similarity index 93% rename from js/editor/condition/zone.js rename to js/common/component/condition/zone.js index 10a2da8c04..c0c27ce2dc 100644 --- a/js/editor/condition/zone.js +++ b/js/common/component/condition/zone.js @@ -1,6 +1,6 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class ZoneCondition extends Component { constructor() { diff --git a/js/editor/json_textarea.js b/js/common/component/json_textarea.js similarity index 100% rename from js/editor/json_textarea.js rename to js/common/component/json_textarea.js diff --git a/js/editor/script/action_edit.js b/js/common/component/script/action_edit.js similarity index 100% rename from js/editor/script/action_edit.js rename to js/common/component/script/action_edit.js diff --git a/js/editor/script/action_row.js b/js/common/component/script/action_row.js similarity index 100% rename from js/editor/script/action_row.js rename to js/common/component/script/action_row.js diff --git a/js/editor/script/call_service.js b/js/common/component/script/call_service.js similarity index 95% rename from js/editor/script/call_service.js rename to js/common/component/script/call_service.js index 2112c3b84f..17d20ba200 100644 --- a/js/editor/script/call_service.js +++ b/js/common/component/script/call_service.js @@ -1,7 +1,7 @@ import { h, Component } from 'preact'; import JSONTextArea from '../json_textarea'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class CallServiceAction extends Component { constructor() { diff --git a/js/editor/script/condition.js b/js/common/component/script/condition.js similarity index 100% rename from js/editor/script/condition.js rename to js/common/component/script/condition.js diff --git a/js/editor/script/delay.js b/js/common/component/script/delay.js similarity index 91% rename from js/editor/script/delay.js rename to js/common/component/script/delay.js index a20d29722b..cb7ea2ddb4 100644 --- a/js/editor/script/delay.js +++ b/js/common/component/script/delay.js @@ -1,5 +1,5 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class DelayAction extends Component { constructor() { diff --git a/js/editor/script/event.js b/js/common/component/script/event.js similarity index 94% rename from js/editor/script/event.js rename to js/common/component/script/event.js index c554a1a579..67cb438291 100644 --- a/js/editor/script/event.js +++ b/js/common/component/script/event.js @@ -1,7 +1,7 @@ import { h, Component } from 'preact'; import JSONTextArea from '../json_textarea'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class EventAction extends Component { constructor() { diff --git a/js/editor/script/index.js b/js/common/component/script/index.js similarity index 100% rename from js/editor/script/index.js rename to js/common/component/script/index.js diff --git a/js/editor/script/wait.js b/js/common/component/script/wait.js similarity index 95% rename from js/editor/script/wait.js rename to js/common/component/script/wait.js index a473d2277b..27cec6d3cd 100644 --- a/js/editor/script/wait.js +++ b/js/common/component/script/wait.js @@ -1,5 +1,5 @@ import { h, Component } from 'preact'; -import { onChangeEvent } from '../util'; +import { onChangeEvent } from '../../util/event'; export default class WaitAction extends Component { constructor() { diff --git a/js/common/util/entity.js b/js/common/util/entity.js new file mode 100644 index 0000000000..50670c8a33 --- /dev/null +++ b/js/common/util/entity.js @@ -0,0 +1,3 @@ +export function validEntityId(entityId) { + return /^(\w+)\.(\w+)$/.test(entityId); +} diff --git a/js/editor/util.js b/js/common/util/event.js similarity index 78% rename from js/editor/util.js rename to js/common/util/event.js index 939cf78d88..42c05f3fcf 100644 --- a/js/editor/util.js +++ b/js/common/util/event.js @@ -1,7 +1,3 @@ -export function validEntityId(entityId) { - return /^(\w+)\.(\w+)$/.test(entityId); -} - export function onChangeEvent(prop, ev) { const data = { ...this.props[prop] }; diff --git a/js/script-editor/script-editor.js b/js/script-editor/script-editor.js new file mode 100644 index 0000000000..4c5663e227 --- /dev/null +++ b/js/script-editor/script-editor.js @@ -0,0 +1,10 @@ +import { h, render } from 'preact'; +import Script from './script'; + +window.ScriptEditor = function (mountEl, props, mergeEl) { + return render(h(Script, props), mountEl, mergeEl); +}; + +window.unmountPreact = function (mountEl, mergeEl) { + render(() => null, mountEl, mergeEl); +}; diff --git a/js/script-editor/script.js b/js/script-editor/script.js new file mode 100644 index 0000000000..c3e0a268e8 --- /dev/null +++ b/js/script-editor/script.js @@ -0,0 +1,62 @@ +import { h, Component } from 'preact'; + +import Script from '../common/component/script'; + +export default class ScriptEditor extends Component { + constructor() { + super(); + + this.onChange = this.onChange.bind(this); + this.sequenceChanged = this.sequenceChanged.bind(this); + } + + onChange(ev) { + this.props.onChange({ + ...this.props.script, + [ev.target.name]: ev.target.value, + }); + } + + sequenceChanged(sequence) { + this.props.onChange({ + ...this.props.script, + sequence, + }); + } + + render({ script, isWide }) { + const { alias, sequence } = script; + + return ( +
+ + {alias} + + Use scripts to execute a sequence of actions. + + +
+ +
+
+
+ + + Sequence + + The sequence of actions of this script. +

+ Learn more about available actions. +

+
+ + diff --git a/panels/config/dashboard/ha-config-navigation.html b/panels/config/dashboard/ha-config-navigation.html index ecdd373ac3..68ae696c86 100644 --- a/panels/config/dashboard/ha-config-navigation.html +++ b/panels/config/dashboard/ha-config-navigation.html @@ -57,16 +57,21 @@ Polymer({ pages: { type: Array, value: [ + { + domain: 'core', + caption: 'General', + description: 'Validate your configuration file and control the server.', + loaded: true, + }, { domain: 'automation', caption: 'Automation', description: 'Create and edit automations.', }, { - domain: 'core', - caption: 'Configuration.yaml', - description: 'Manage your configuration file and the server.', - loaded: true, + domain: 'script', + caption: 'Script', + description: 'Create and edit scripts.', }, { domain: 'zwave', diff --git a/panels/config/ha-panel-config.html b/panels/config/ha-panel-config.html index 3a413a4937..d45dd75884 100644 --- a/panels/config/ha-panel-config.html +++ b/panels/config/ha-panel-config.html @@ -8,6 +8,7 @@ + @@ -48,6 +49,13 @@ is-wide='[[isWide]]' > + + + + + + + + + + + + diff --git a/panels/config/script/ha-script-editor.html b/panels/config/script/ha-script-editor.html new file mode 100644 index 0000000000..a24f1feef0 --- /dev/null +++ b/panels/config/script/ha-script-editor.html @@ -0,0 +1,265 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/panels/config/script/ha-script-picker.html b/panels/config/script/ha-script-picker.html new file mode 100644 index 0000000000..7aae6fa95d --- /dev/null +++ b/panels/config/script/ha-script-picker.html @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + diff --git a/src/util/hass-util.html b/src/util/hass-util.html index 07c9385116..c95314b84f 100644 --- a/src/util/hass-util.html +++ b/src/util/hass-util.html @@ -430,6 +430,14 @@ window.hassUtil.computeDomain = function (stateObj) { return stateObj._domain; }; +window.hassUtil.computeObjectId = function (stateObj) { + if (!stateObj._object_id) { + stateObj._object_id = window.HAWS.extractObjectId(stateObj.entity_id); + } + + return stateObj._object_id; +}; + window.hassUtil.computeStateName = function (stateObj) { if (stateObj._entityDisplay === undefined) { stateObj._entityDisplay = (