Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules: add item state update to action module wizard #675

Merged
merged 1 commit into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,43 @@
</f7-list>
</f7-block>
<f7-block class="no-margin no-padding" v-else-if="category === 'item'">
<f7-list>
<f7-list-item radio :checked="itemEventType === 'command'" name="MediaEventType" title="send a command to" @click="updateItemEventType('command')" />
<f7-list-item radio :checked="itemEventType === 'update'" name="MediaEventType" title="update the state of" @click="updateItemEventType('update')" />
</f7-list>
<f7-list>
<item-picker :value="currentModule.configuration.itemName" title="Item" @input="(val) => $set(currentModule.configuration, 'itemName', val)" @itemSelected="(value) => { $set(this, 'currentItem', value); updateItemEventType('command') }" />
</f7-list>
<f7-list>
<f7-list-input
v-if="itemEventType === 'command'"
label="Command to send"
name="command"
type="text"
:value="currentModule.configuration.command"
@blur="(evt) => $set(currentModule.configuration, 'command', evt.target.value)"
/>
<f7-list-input
v-else-if="itemEventType === 'update'"
label="to state"
name="state"
type="text"
:value="currentModule.configuration.state"
@blur="(evt) => $set(currentModule.configuration, 'state', evt.target.value)"
/>
</f7-list>
<f7-list v-if="commandSuggestions.length">
<f7-list v-if="itemEventType === 'command' && commandSuggestions.length">
<f7-list-item radio :checked="currentModule.configuration.command === suggestion.command" v-for="suggestion in commandSuggestions" :key="suggestion.command"
:title="suggestion.label" @click="$set(currentModule.configuration, 'command', suggestion.command)" />
</f7-list>
<!-- <f7-block v-if="currentItem && (currentItem.type === 'Dimmer' || currentItem.type === 'Rollershutter' || (currentItem.type === 'Number' && currentItem.stateDescription && currentItem.stateDescription.minimum !== undefined))">
<!-- <f7-block v-if="itemEventType === 'command' && currentItem && (currentItem.type === 'Dimmer' || currentItem.type === 'Rollershutter' || (currentItem.type === 'Number' && currentItem.stateDescription && currentItem.stateDescription.minimum !== undefined))">
<f7-range :value="currentModule.configuration.command" @range:changed="(val) => $set(currentModule.configuration, 'command', val)"
:min="(currentItem.stateDescription && currentItem.stateDescription.minimum) ? currentItem.stateDescription.minimum : 0"
:max="(currentItem.stateDescription && currentItem.stateDescription.maximum) ? currentItem.stateDescription.maximum : 100"
:step="(currentItem.stateDescription && currentItem.stateDescription.step) ? currentItem.stateDescription.step : 1"
:scale="true" :label="true" :scaleSubSteps="5" />
</f7-block> -->
<f7-list v-if="currentItem && currentItem.type === 'Color'" media-list>
<f7-list v-if="itemEventType === 'command' && currentItem && currentItem.type === 'Color'" media-list>
<f7-list-input media-item type="colorpicker" label="Pick a color" :color-picker-params="{
targetEl: '#color-picker-value',
targetElSetBackgroundColor: true,
Expand Down Expand Up @@ -206,29 +219,34 @@ export default {
this.itemEventType = type
switch (type) {
case 'command':
this.$emit('typeSelect', 'core.ItemCommandAction')
this.$emit('typeSelect', 'core.ItemCommandAction', true)
if (this.currentItem) this.$set(this.currentModule, 'configuration', Object.assign({}, { itemName: this.currentItem.name }))
break
case 'update':
this.$emit('typeSelect', 'core.ItemStateUpdateAction', true)
if (this.currentItem) this.$set(this.currentModule, 'configuration', Object.assign({}, { itemName: this.currentItem.name }))
break
}
},
updateRulesEventType (type) {
this.rulesEventType = type
switch (type) {
case 'run':
this.$emit('typeSelect', 'core.RunRuleAction')
this.$emit('typeSelect', 'core.RunRuleAction', true)
break
case 'enable':
this.$emit('typeSelect', 'core.RuleEnablementAction')
this.$emit('typeSelect', 'core.RuleEnablementAction', true)
break
}
},
updateMediaEventType (type) {
this.mediaEventType = type
switch (type) {
case 'say':
this.$emit('typeSelect', 'media.SayAction')
this.$emit('typeSelect', 'media.SayAction', true)
break
case 'play':
this.$emit('typeSelect', 'media.PlayAction')
this.$emit('typeSelect', 'media.PlayAction', true)
break
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export default {
case 'core.ItemCommandAction':
if (!config.itemName || !config.command) return moduleType.label
return 'Send command ' + config.command + ' to ' + config.itemName
case 'core.ItemStateUpdateAction':
if (!config.itemName || !config.state) return moduleType.label
return 'Update the state of ' + config.itemName + ' to ' + config.state
case 'media.SayAction':
if (!config.text) return moduleType.label
return 'Say "' + config.text + '"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export default {
},
startEventSource () {
this.eventSource = this.$oh.sse.connect('/rest/events?topics=openhab/rules/*/*', null, (event) => {
console.log(event)
const topicParts = event.topic.split('/')
switch (topicParts[3]) {
case 'added':
Expand All @@ -191,8 +190,11 @@ export default {
break
case 'state':
const rule = this.rules.find((r) => r.uid === topicParts[2])
const newStatus = JSON.parse(event.payload)
if (!rule) break
this.$set(rule, 'status', JSON.parse(event.payload))
if (rule.status.status !== newStatus.status) rule.status.status = newStatus.status
if (rule.status.statusDetail !== newStatus.statusDetail) rule.status.statusDetail = newStatus.statusDetail
if (rule.status.description !== newStatus.description) rule.status.description = newStatus.description
}
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@
<script-general-settings v-else-if="createMode" :createMode="true" :rule="rule" />
<f7-block class="block-narrow" v-if="newScript">
<f7-col>
<f7-block-title medium class="margin-bottom">Script Language</f7-block-title>
<f7-list media-list>
<f7-block-title medium class="margin-bottom">Scripting Method</f7-block-title>
<f7-list-item media-item radio radio-icon="start"
title="Design with Blockly"
footer="A beginner-friendly way to build scripts visually by assembling blocks"
:value="'application/javascript+blockly'" :checked="mode === 'application/javascript+blockly'"
@change="mode = 'application/javascript+blockly'">
<img src="res/img/blockly.svg" height="32" width="32" slot="media" />
</f7-list-item>
</f7-list>
<f7-block-footer class="margin-vertical">or choose the scripting language:</f7-block-footer>
<f7-list media-list>
<f7-list-item media-item radio radio-icon="start"
:value="mode" :checked="mode === language.contentType" @change="mode = language.contentType"
v-for="language in languages" :key="language.contentType"
:title="language.name" :after="language.version" :footer="language.contentType"></f7-list-item>
<!-- <f7-list-item media-item radio radio-icon="start"
:value="mode" :checked="mode === 'application/vnd.openhab.blockly.rule'" @change="mode = 'application/vnd.openhab.blockly.rule'"
:title="'Blockly editor'"></f7-list-item> -->
</f7-list>
</f7-col>
</f7-block>
Expand Down Expand Up @@ -169,7 +176,7 @@ export default {
actions: [],
tags: ['Script']
}
this.mode = 'application/javascript'
this.mode = 'application/javascript+blockly'
this.$oh.api.get('/rest/module-types/script.ScriptAction').then((data) => {
this.$set(this, 'scriptModuleType', data)
this.$set(this, 'languages',
Expand Down Expand Up @@ -203,7 +210,7 @@ export default {
script: ''
}
}
if (this.mode === 'application/vnd.openhab.blockly.rule') {
if (this.mode === 'application/javascript+blockly') {
actionModule.configuration.type = 'application/javascript'
actionModule.configuration.blockSource = '<xml xmlns="https://developers.google.com/blockly/xml"></xml>'
}
Expand Down Expand Up @@ -348,7 +355,6 @@ export default {
},
startEventSource () {
this.eventSource = this.$oh.sse.connect('/rest/events?topics=openhab/rules/' + this.ruleId + '/*', null, (event) => {
console.log(event)
const topicParts = event.topic.split('/')
switch (topicParts[3]) {
case 'state':
Expand Down