-
-
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
377251a
Tell the script context to use the classloader of the current class.
digitaldan 394de63
Protoype of merging OHJ with jsscripting
digitaldan 18237a1
Load OH JS file directly from resource, use @oh namespace
digitaldan 74be917
Remove debug statement
digitaldan 57d4c80
add allItems
digitaldan ed51c5d
JS changes
digitaldan 1a14a3d
Adds injection code and makes this a configurable service
digitaldan 831bb7f
revert small typor
digitaldan 2e0152d
Merge branch 'main' into jsscripting-ohj
digitaldan 91e1033
adds global vars, cleans up local library loading
digitaldan f99e8af
Typo
digitaldan 003f650
Use npm supplied `openhab` scripting library
digitaldan ba9c5a9
Update author headers
digitaldan fce7efc
Revert unattended change
digitaldan b622b44
adds setInterval and supports arguments for timers
digitaldan f299e2b
change console logging to "org.openhab.automation.script'
digitaldan 7073421
Wrap logic in function for safety, apply callback in safer way
digitaldan 2465d92
Change scripting logger name
digitaldan d149195
Add lifecyle and bundle context support, cleans up global scripting a…
digitaldan 52dcb72
Bump openhab-js version
digitaldan d60e071
spotless
digitaldan e268143
Merge branch 'main' into jsscripting-ohj
digitaldan 5d0ff0a
Merge branch 'main' into HEAD
digitaldan 88a712c
remove unessesary binding provider classes, updated class docs
digitaldan 4afd5c9
Bump openhab NPM version
digitaldan 2054bca
Update bundles/org.openhab.automation.jsscripting/src/main/java/org/o…
kaikreuzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...java/org/openhab/automation/jsscripting/internal/fs/ReadOnlySeekableByteArrayChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.openhab.automation.jsscripting.internal.fs; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.ClosedChannelException; | ||
import java.nio.channels.SeekableByteChannel; | ||
|
||
/** | ||
* Simple wrapper around a byte array to provide a SeekableByteChannel for consumption | ||
* | ||
* @author Dan Cunningham - Initial contribution | ||
*/ | ||
public class ReadOnlySeekableByteArrayChannel implements SeekableByteChannel { | ||
private byte[] data; | ||
private int position; | ||
private boolean closed; | ||
|
||
public ReadOnlySeekableByteArrayChannel(byte[] data) { | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public long position() { | ||
return position; | ||
} | ||
|
||
@Override | ||
public SeekableByteChannel position(long newPosition) throws IOException { | ||
ensureOpen(); | ||
position = (int) Math.max(0, Math.min(newPosition, size())); | ||
return this; | ||
} | ||
|
||
@Override | ||
public long size() { | ||
return data.length; | ||
} | ||
|
||
@Override | ||
public int read(ByteBuffer buf) throws IOException { | ||
ensureOpen(); | ||
int remaining = (int) size() - position; | ||
if (remaining <= 0) { | ||
return -1; | ||
} | ||
int readBytes = buf.remaining(); | ||
if (readBytes > remaining) { | ||
readBytes = remaining; | ||
} | ||
buf.put(data, position, readBytes); | ||
position += readBytes; | ||
return readBytes; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
closed = true; | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return !closed; | ||
} | ||
|
||
@Override | ||
public int write(ByteBuffer b) throws IOException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public SeekableByteChannel truncate(long newSize) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
private void ensureOpen() throws ClosedChannelException { | ||
if (!isOpen()) { | ||
throw new ClosedChannelException(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
bundles/org.openhab.automation.jsscripting/src/main/resources/OH-INF/config/config.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<config-description:config-descriptions | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:config-description="https://openhab.org/schemas/config-description/v1.0.0" | ||
xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0 | ||
https://openhab.org/schemas/config-description-1.0.0.xsd"> | ||
<config-description uri="automation:jsscripting"> | ||
<parameter name="injectionEnabled" type="boolean" required="true"> | ||
<label>Use Built-in Global Variables </label> | ||
digitaldan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<description><![CDATA[ Import all variables from the OH scripting library into all rules for common services like items, things, actions, log, etc... <br> | ||
If disabled, the OH scripting library can be imported manually using "<i>require('openhab')</i>" | ||
]]></description> | ||
<options> | ||
<option value="true">Use Built-in Variables</option> | ||
<option value="false">Do Not Use Built-in Variables</option> | ||
</options> | ||
<default>true</default> | ||
</parameter> | ||
</config-description> | ||
</config-description:config-descriptions> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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>
.