-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[jsscripting] openhab-js integration #11656
Conversation
Fixes openhab#11222 Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
.../main/java/org/openhab/binding/venstarthermostat/internal/dto/VenstarAwayModeSerializer.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
} | ||
}; | ||
|
||
function setTimeout(cb, delay) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we probably should also have a polyfill for setInterval
!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added this in, also i changed both types of timers to support arguments to better confirm with standards.
globalThis.setTimeout = setTimeout; | ||
globalThis.clearTimeout = clearTimeout; | ||
globalThis.global = globalThis; | ||
globalThis.process = { env: { NODE_ENV: '' } }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I added this in my scripts, this was to prevent npm libraries from crashing when they access process.env.NODE_ENV
. For which this is enough. But most often this is used to check if it equals 'production'
, in which case libraries often emit less/no debug logging, type checks, or do other shortcuts to optimize performance.
So there is a tradeoff here basically between DX and performance. I would tend to favor DX in our case, but should we want to prioritize perf, then this could be changed to:
globalThis.process = { env: { NODE_ENV: '' } }; | |
globalThis.process = { env: { NODE_ENV: 'production' } }; |
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
… bit. This also includes an upcoming PR for cache support, which i will remove from here after it gets merged. Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
554626e
to
d60e071
Compare
bundles/org.openhab.automation.jsscripting/src/main/resources/OH-INF/config/config.xml
Outdated
Show resolved
Hide resolved
.../src/main/java/org/openhab/automation/jsscripting/internal/scope/binding/BindingSupport.java
Outdated
Show resolved
Hide resolved
...penhab/automation/jsscripting/internal/scope/binding/BindingItemProviderDelegateFactory.java
Outdated
Show resolved
Hide resolved
...a/org/openhab/automation/jsscripting/internal/scope/binding/BindingItemProviderDelegate.java
Outdated
Show resolved
Hide resolved
...penhab/automation/jsscripting/internal/scope/ScriptDisposalAwareScriptExtensionProvider.java
Outdated
Show resolved
Hide resolved
...n.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scope/Lifecycle.java
Outdated
Show resolved
Hide resolved
.../java/org/openhab/automation/jsscripting/internal/scope/AbstractScriptExtensionProvider.java
Outdated
Show resolved
Hide resolved
...a/org/openhab/automation/jsscripting/internal/scope/binding/BindingItemProviderDelegate.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Hello everyone, this is no longer a WIP and is ready for review. All required core changes have been made. There is still openhab/openhab-core#2595 that should be merged as well (but this PR does not depend on it). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thank you!
*/ | ||
@Component(service = ScriptEngineFactory.class) | ||
@Component(service = ScriptEngineFactory.class, configurationPid = "org.openhab.automation.jsscripting", property = Constants.SERVICE_PID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our configuration pids follow the pattern org.openhab.<serviceid>
.
...ng/src/main/java/org/openhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java
Outdated
Show resolved
Hide resolved
…penhab/automation/jsscripting/internal/OpenhabGraalJSScriptEngine.java
Fixes openhab#11222 Signed-off-by: Dan Cunningham <dan@digitaldan.com> Signed-off-by: Nick Waterton <n.waterton@outlook.com>
Fixes openhab#11222 Signed-off-by: Dan Cunningham <dan@digitaldan.com> Signed-off-by: Michael Schmidt <mi.schmidt.83@gmail.com>
Fixes openhab#11222 Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Fixes openhab#11222 Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Fixes openhab#11222 Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Fixes openhab#11222 Signed-off-by: Dan Cunningham <dan@digitaldan.com> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
This PR integrates @jpg0 excellent OHJ helper library, which is now part of https://github.com/openhab/openhab-js and provides an out of the box environment for users to write Javascript based rules without needing to access raw Java types. Scripts can now be written like
without any other imports or logic
This pr also enables node.js style console logging (console.log, console.debug...) as well as common javascript setTimeout support .
Todo