Skip to content

Commit d7976dc

Browse files
authored
Rules: add item state update to action module wizard (openhab#675)
Depends on openhab/openhab-core#1970. Also: - Add abiilty to create a Blockly script directly. - Only update statuses that changed in the rules list (might help with openhab#673 and similar to openhab#466/openhab#439). Signed-off-by: Yannick Schaus <[email protected]>
1 parent 5fde929 commit d7976dc

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

bundles/org.openhab.ui/web/src/components/rule/action-module-wizard.vue

+26-8
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,43 @@
3333
</f7-list>
3434
</f7-block>
3535
<f7-block class="no-margin no-padding" v-else-if="category === 'item'">
36+
<f7-list>
37+
<f7-list-item radio :checked="itemEventType === 'command'" name="MediaEventType" title="send a command to" @click="updateItemEventType('command')" />
38+
<f7-list-item radio :checked="itemEventType === 'update'" name="MediaEventType" title="update the state of" @click="updateItemEventType('update')" />
39+
</f7-list>
3640
<f7-list>
3741
<item-picker :value="currentModule.configuration.itemName" title="Item" @input="(val) => $set(currentModule.configuration, 'itemName', val)" @itemSelected="(value) => { $set(this, 'currentItem', value); updateItemEventType('command') }" />
3842
</f7-list>
3943
<f7-list>
4044
<f7-list-input
45+
v-if="itemEventType === 'command'"
4146
label="Command to send"
4247
name="command"
4348
type="text"
4449
:value="currentModule.configuration.command"
4550
@blur="(evt) => $set(currentModule.configuration, 'command', evt.target.value)"
4651
/>
52+
<f7-list-input
53+
v-else-if="itemEventType === 'update'"
54+
label="to state"
55+
name="state"
56+
type="text"
57+
:value="currentModule.configuration.state"
58+
@blur="(evt) => $set(currentModule.configuration, 'state', evt.target.value)"
59+
/>
4760
</f7-list>
48-
<f7-list v-if="commandSuggestions.length">
61+
<f7-list v-if="itemEventType === 'command' && commandSuggestions.length">
4962
<f7-list-item radio :checked="currentModule.configuration.command === suggestion.command" v-for="suggestion in commandSuggestions" :key="suggestion.command"
5063
:title="suggestion.label" @click="$set(currentModule.configuration, 'command', suggestion.command)" />
5164
</f7-list>
52-
<!-- <f7-block v-if="currentItem && (currentItem.type === 'Dimmer' || currentItem.type === 'Rollershutter' || (currentItem.type === 'Number' && currentItem.stateDescription && currentItem.stateDescription.minimum !== undefined))">
65+
<!-- <f7-block v-if="itemEventType === 'command' && currentItem && (currentItem.type === 'Dimmer' || currentItem.type === 'Rollershutter' || (currentItem.type === 'Number' && currentItem.stateDescription && currentItem.stateDescription.minimum !== undefined))">
5366
<f7-range :value="currentModule.configuration.command" @range:changed="(val) => $set(currentModule.configuration, 'command', val)"
5467
:min="(currentItem.stateDescription && currentItem.stateDescription.minimum) ? currentItem.stateDescription.minimum : 0"
5568
:max="(currentItem.stateDescription && currentItem.stateDescription.maximum) ? currentItem.stateDescription.maximum : 100"
5669
:step="(currentItem.stateDescription && currentItem.stateDescription.step) ? currentItem.stateDescription.step : 1"
5770
:scale="true" :label="true" :scaleSubSteps="5" />
5871
</f7-block> -->
59-
<f7-list v-if="currentItem && currentItem.type === 'Color'" media-list>
72+
<f7-list v-if="itemEventType === 'command' && currentItem && currentItem.type === 'Color'" media-list>
6073
<f7-list-input media-item type="colorpicker" label="Pick a color" :color-picker-params="{
6174
targetEl: '#color-picker-value',
6275
targetElSetBackgroundColor: true,
@@ -206,29 +219,34 @@ export default {
206219
this.itemEventType = type
207220
switch (type) {
208221
case 'command':
209-
this.$emit('typeSelect', 'core.ItemCommandAction')
222+
this.$emit('typeSelect', 'core.ItemCommandAction', true)
223+
if (this.currentItem) this.$set(this.currentModule, 'configuration', Object.assign({}, { itemName: this.currentItem.name }))
224+
break
225+
case 'update':
226+
this.$emit('typeSelect', 'core.ItemStateUpdateAction', true)
227+
if (this.currentItem) this.$set(this.currentModule, 'configuration', Object.assign({}, { itemName: this.currentItem.name }))
210228
break
211229
}
212230
},
213231
updateRulesEventType (type) {
214232
this.rulesEventType = type
215233
switch (type) {
216234
case 'run':
217-
this.$emit('typeSelect', 'core.RunRuleAction')
235+
this.$emit('typeSelect', 'core.RunRuleAction', true)
218236
break
219237
case 'enable':
220-
this.$emit('typeSelect', 'core.RuleEnablementAction')
238+
this.$emit('typeSelect', 'core.RuleEnablementAction', true)
221239
break
222240
}
223241
},
224242
updateMediaEventType (type) {
225243
this.mediaEventType = type
226244
switch (type) {
227245
case 'say':
228-
this.$emit('typeSelect', 'media.SayAction')
246+
this.$emit('typeSelect', 'media.SayAction', true)
229247
break
230248
case 'play':
231-
this.$emit('typeSelect', 'media.PlayAction')
249+
this.$emit('typeSelect', 'media.PlayAction', true)
232250
break
233251
}
234252
},

bundles/org.openhab.ui/web/src/pages/settings/rules/module-description-suggestions.js

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export default {
6767
case 'core.ItemCommandAction':
6868
if (!config.itemName || !config.command) return moduleType.label
6969
return 'Send command ' + config.command + ' to ' + config.itemName
70+
case 'core.ItemStateUpdateAction':
71+
if (!config.itemName || !config.state) return moduleType.label
72+
return 'Update the state of ' + config.itemName + ' to ' + config.state
7073
case 'media.SayAction':
7174
if (!config.text) return moduleType.label
7275
return 'Say "' + config.text + '"'

bundles/org.openhab.ui/web/src/pages/settings/rules/rules-list.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ export default {
181181
},
182182
startEventSource () {
183183
this.eventSource = this.$oh.sse.connect('/rest/events?topics=openhab/rules/*/*', null, (event) => {
184-
console.log(event)
185184
const topicParts = event.topic.split('/')
186185
switch (topicParts[3]) {
187186
case 'added':
@@ -191,8 +190,11 @@ export default {
191190
break
192191
case 'state':
193192
const rule = this.rules.find((r) => r.uid === topicParts[2])
193+
const newStatus = JSON.parse(event.payload)
194194
if (!rule) break
195-
this.$set(rule, 'status', JSON.parse(event.payload))
195+
if (rule.status.status !== newStatus.status) rule.status.status = newStatus.status
196+
if (rule.status.statusDetail !== newStatus.statusDetail) rule.status.statusDetail = newStatus.statusDetail
197+
if (rule.status.description !== newStatus.description) rule.status.description = newStatus.description
196198
}
197199
})
198200
},

bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue

+13-7
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,22 @@
3131
<script-general-settings v-else-if="createMode" :createMode="true" :rule="rule" />
3232
<f7-block class="block-narrow" v-if="newScript">
3333
<f7-col>
34-
<f7-block-title medium class="margin-bottom">Script Language</f7-block-title>
34+
<f7-list media-list>
35+
<f7-block-title medium class="margin-bottom">Scripting Method</f7-block-title>
36+
<f7-list-item media-item radio radio-icon="start"
37+
title="Design with Blockly"
38+
footer="A beginner-friendly way to build scripts visually by assembling blocks"
39+
:value="'application/javascript+blockly'" :checked="mode === 'application/javascript+blockly'"
40+
@change="mode = 'application/javascript+blockly'">
41+
<img src="res/img/blockly.svg" height="32" width="32" slot="media" />
42+
</f7-list-item>
43+
</f7-list>
44+
<f7-block-footer class="margin-vertical">or choose the scripting language:</f7-block-footer>
3545
<f7-list media-list>
3646
<f7-list-item media-item radio radio-icon="start"
3747
:value="mode" :checked="mode === language.contentType" @change="mode = language.contentType"
3848
v-for="language in languages" :key="language.contentType"
3949
:title="language.name" :after="language.version" :footer="language.contentType"></f7-list-item>
40-
<!-- <f7-list-item media-item radio radio-icon="start"
41-
:value="mode" :checked="mode === 'application/vnd.openhab.blockly.rule'" @change="mode = 'application/vnd.openhab.blockly.rule'"
42-
:title="'Blockly editor'"></f7-list-item> -->
4350
</f7-list>
4451
</f7-col>
4552
</f7-block>
@@ -169,7 +176,7 @@ export default {
169176
actions: [],
170177
tags: ['Script']
171178
}
172-
this.mode = 'application/javascript'
179+
this.mode = 'application/javascript+blockly'
173180
this.$oh.api.get('/rest/module-types/script.ScriptAction').then((data) => {
174181
this.$set(this, 'scriptModuleType', data)
175182
this.$set(this, 'languages',
@@ -203,7 +210,7 @@ export default {
203210
script: ''
204211
}
205212
}
206-
if (this.mode === 'application/vnd.openhab.blockly.rule') {
213+
if (this.mode === 'application/javascript+blockly') {
207214
actionModule.configuration.type = 'application/javascript'
208215
actionModule.configuration.blockSource = '<xml xmlns="https://developers.google.com/blockly/xml"></xml>'
209216
}
@@ -348,7 +355,6 @@ export default {
348355
},
349356
startEventSource () {
350357
this.eventSource = this.$oh.sse.connect('/rest/events?topics=openhab/rules/' + this.ruleId + '/*', null, (event) => {
351-
console.log(event)
352358
const topicParts = event.topic.split('/')
353359
switch (topicParts[3]) {
354360
case 'state':

0 commit comments

Comments
 (0)