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

Blockly enhancements 2 - scripts, ephemeris, persistence #1212

Merged
merged 13 commits into from
Dec 5, 2021
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export default function (f7, sinks, voices) {
* Code part
*/
Blockly.JavaScript['oh_playmedia_sink'] = function (block) {
addAudio()
const audio = addAudio()
let fileName = Blockly.JavaScript.valueToCode(block, 'fileName', Blockly.JavaScript.ORDER_ATOMIC)
let sinkName = Blockly.JavaScript.valueToCode(block, 'sinkName', Blockly.JavaScript.ORDER_ATOMIC).replace('(', '').replace(/[()]/g, '')

let code = `audio.playSound(${sinkName}, ${fileName});\n`
let code = `${audio}.playSound(${sinkName}, ${fileName});\n`
return code
}

Expand Down Expand Up @@ -92,12 +92,12 @@ export default function (f7, sinks, voices) {
* Code part
*/
Blockly.JavaScript['oh_playmedia_sink_volume'] = function (block) {
addAudio()
const audio = addAudio()
let fileName = Blockly.JavaScript.valueToCode(block, 'fileName', Blockly.JavaScript.ORDER_ATOMIC)
let sinkName = Blockly.JavaScript.valueToCode(block, 'sinkName', Blockly.JavaScript.ORDER_ATOMIC).replace('(', '').replace(/[()]/g, '')
let volume = Blockly.JavaScript.valueToCode(block, 'volume', Blockly.JavaScript.ORDER_ATOMIC).replace(/'/g, '')

let code = `audio.playSound(${sinkName}, ${fileName}, new PercentType(${volume}));\n`
let code = `${audio}.playSound(${sinkName}, ${fileName}, new PercentType(${volume}));\n`
return code
}

Expand Down Expand Up @@ -127,10 +127,10 @@ export default function (f7, sinks, voices) {
* Blockly part
*/
Blockly.JavaScript['oh_playstream_sink'] = function (block) {
addAudio()
const audio = addAudio()
let url = Blockly.JavaScript.valueToCode(block, 'url', Blockly.JavaScript.ORDER_ATOMIC)
let sinkName = Blockly.JavaScript.valueToCode(block, 'sinkName', Blockly.JavaScript.ORDER_ATOMIC).replace('(', '').replace(/[()]/g, '')
let code = `audio.playStream(${sinkName}, ${url});\n`
let code = `${audio}.playStream(${sinkName}, ${url});\n`
return code
}

Expand All @@ -157,10 +157,10 @@ export default function (f7, sinks, voices) {
* Blockly part
*/
Blockly.JavaScript['oh_stopstream_sink'] = function (block) {
addAudio()
const audio = addAudio()
let url = block.getFieldValue('url')
let sinkName = Blockly.JavaScript.valueToCode(block, 'sinkName', Blockly.JavaScript.ORDER_ATOMIC).replace('(', '').replace(/[()]/g, '')
let code = `audio.playStream(${sinkName}, null);\n`
let code = `${audio}.playStream(${sinkName}, null);\n`
return code
}

Expand Down Expand Up @@ -192,15 +192,15 @@ export default function (f7, sinks, voices) {
* Code part
*/
Blockly.JavaScript['oh_say'] = function (block) {
const voiceName = Blockly.JavaScript.provideFunction_(
const voice = Blockly.JavaScript.provideFunction_(
'voice',
['var ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = Java.type(\'org.openhab.core.model.script.actions.Voice\');'])

const textToSay = Blockly.JavaScript.valueToCode(block, 'textToSay', Blockly.JavaScript.ORDER_ATOMIC)
const voice = Blockly.JavaScript.valueToCode(block, 'voice', Blockly.JavaScript.ORDER_ATOMIC).replace('(', '').replace(/[()]/g, '')
const voiceName = Blockly.JavaScript.valueToCode(block, 'voice', Blockly.JavaScript.ORDER_ATOMIC).replace('(', '').replace(/[()]/g, '')
const deviceSink = Blockly.JavaScript.valueToCode(block, 'deviceSink', Blockly.JavaScript.ORDER_ATOMIC).replace('(', '').replace(/[()]/g, '')

const code = `voice.say(${textToSay}, ${voice}, ${deviceSink});\n`
const code = `${voice}.say(${textToSay}, ${voiceName}, ${deviceSink});\n`
return code
}

Expand Down Expand Up @@ -264,7 +264,7 @@ export default function (f7, sinks, voices) {
}

function addAudio () {
Blockly.JavaScript.provideFunction_(
return Blockly.JavaScript.provideFunction_(
'audio',
['var ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = Java.type(\'org.openhab.core.model.script.actions.Audio\');'])
}
Expand Down
Loading