[blockly] add context info block (#1227)
Signed-off-by: Stefan Höhn <stefan@andreaundstefanhoehn.de> Also-by: Yannick Schaus <github@schaus.net>pull/1231/head
parent
2ed7e8d8b7
commit
13cd3003b1
|
@ -26,7 +26,46 @@ export default function (f7) {
|
|||
const eventType = block.getFieldValue('eventType')
|
||||
const itemName = Blockly.JavaScript.valueToCode(block, 'itemName', Blockly.JavaScript.ORDER_ATOMIC)
|
||||
const value = Blockly.JavaScript.valueToCode(block, 'value', Blockly.JavaScript.ORDER_ATOMIC)
|
||||
let code = 'events.' + eventType + '(' + itemName + ', ' + value + ');\n'
|
||||
return code
|
||||
return 'events.' + eventType + '(' + itemName + ', ' + value + ');\n'
|
||||
}
|
||||
|
||||
Blockly.Blocks['oh_context_info'] = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField('contextual info')
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
['rule UID', 'ruleUID'],
|
||||
['event type', 'type'],
|
||||
['new state of item', 'itemState'],
|
||||
['previous state of item', 'oldItemState'],
|
||||
['triggering item name', 'itemName'],
|
||||
['received command', 'itemCommand'],
|
||||
['triggered channel', 'channel']]),
|
||||
'contextInfo')
|
||||
this.setInputsInline(true)
|
||||
this.setOutput(true, null)
|
||||
this.setColour(0)
|
||||
let thisBlock = this
|
||||
this.setTooltip(function () {
|
||||
const contextData = thisBlock.getFieldValue('contextInfo')
|
||||
const TIP = {
|
||||
'ruleUID': 'The current rule\'s UID',
|
||||
'type': 'the event type name',
|
||||
'itemState': 'the new item state (only applicable for rules with triggers related to changed and updated items)',
|
||||
'oldItemState': 'the old item state (only applicable for rules with triggers related to changed and updated items)',
|
||||
'itemName': 'the item name that caused the event (if relevant)',
|
||||
'itemCommand': 'the command name that triggered the event',
|
||||
'channel': 'the channel UID that triggered the event (only applicable for rules including a "trigger channel fired" event)'
|
||||
}
|
||||
return TIP[contextData]
|
||||
})
|
||||
this.setHelpUrl('https://www.openhab.org/docs/developer/utils/events.html')
|
||||
}
|
||||
}
|
||||
|
||||
Blockly.JavaScript['oh_context_info'] = function (block) {
|
||||
const contextInfo = block.getFieldValue('contextInfo')
|
||||
if (contextInfo === 'ruleUID') return ['ctx.ruleUID', Blockly.JavaScript.ORDER_ATOMIC]
|
||||
return [`event.${contextInfo}`, Blockly.JavaScript.ORDER_ATOMIC]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ export default function defineOHBlocks_Timers (f7) {
|
|||
Blockly.Blocks['oh_sleep'] = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField('thread sleep (ms)')
|
||||
.appendField('wait for')
|
||||
.appendField(new Blockly.FieldNumber(1000), 'milliseconds')
|
||||
.appendField('ms')
|
||||
this.setPreviousStatement(true, null)
|
||||
this.setNextStatement(true, null)
|
||||
this.setColour(0)
|
||||
|
|
|
@ -348,6 +348,7 @@
|
|||
<shadow type="oh_thing" />
|
||||
</value>
|
||||
</block>
|
||||
<block type="oh_context_info" />
|
||||
</category>
|
||||
|
||||
<category name="Timers & Delays">
|
||||
|
|
Loading…
Reference in New Issue