Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mkmannmanny committed Dec 24, 2024
2 parents 49b9025 + 7e99669 commit 0d1cb0b
Show file tree
Hide file tree
Showing 96 changed files with 4,203 additions and 1,707 deletions.
2 changes: 1 addition & 1 deletion bundles/create_openhab_binding_skeleton.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ IF %ARGC% NEQ 3 (
exit /B 1
)

SET OpenhabVersion="4.3.0-SNAPSHOT"
SET OpenhabVersion="5.0.0-SNAPSHOT"

SET BindingIdInCamelCase=%~1
SET BindingIdInLowerCase=%BindingIdInCamelCase%
Expand Down
2 changes: 1 addition & 1 deletion bundles/create_openhab_binding_skeleton.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ $# -lt 3 ] && { echo "Usage: $0 <BindingIdInCamelCase> <Author> <GitHub Username>"; exit 1; }

openHABVersion=4.3.0-SNAPSHOT
openHABVersion=5.0.0-SNAPSHOT

camelcaseId=$1
id=`echo $camelcaseId | tr '[:upper:]' '[:lower:]'`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.util.Objects;

import javax.script.Bindings;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
Expand All @@ -37,7 +35,9 @@
* @author Jimmy Tanagra - Initial contribution
*/
@NonNullByDefault
public class JRubyEngineWrapper implements Compilable, Invocable, ScriptEngine {
public class JRubyEngineWrapper implements Invocable, ScriptEngine {
// Don't implement Compilable because there is a bug
// in JRuby's compiled scripts: https://github.com/jruby/jruby/issues/8346

private final JRubyEngine engine;

Expand All @@ -48,16 +48,6 @@ public class JRubyEngineWrapper implements Compilable, Invocable, ScriptEngine {
this.engine = Objects.requireNonNull(engine);
}

@Override
public CompiledScript compile(@Nullable String script) throws ScriptException {
return new JRubyCompiledScriptWrapper(engine.compile(script));
}

@Override
public CompiledScript compile(@Nullable Reader reader) throws ScriptException {
return new JRubyCompiledScriptWrapper(engine.compile(reader));
}

@Override
public Object eval(@Nullable String script, @Nullable ScriptContext context) throws ScriptException {
Object ctx = Objects.requireNonNull(context).getBindings(ScriptContext.ENGINE_SCOPE).get(CONTEXT_VAR_NAME);
Expand Down
47 changes: 28 additions & 19 deletions bundles/org.openhab.automation.jsscripting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,37 @@
!jdk.vm.ci.services
</bnd.importpackage>
<!-- Remember to check if the fix https://github.com/openhab/openhab-core/pull/4437 still works when upgrading GraalJS -->
<graal.version>22.0.0.2</graal.version> <!-- DO NOT UPGRADE: 22.0.0.2 is the latest version working on armv7l / OpenJDK 11.0.16 & armv7l / Zulu 17.0.5+8 -->
<graaljs.version>24.1.1</graaljs.version>
<oh.version>${project.version}</oh.version>
<ohjs.version>[email protected]</ohjs.version>
</properties>

<build>
<plugins>
<!-- exclude META-INF/services/com.oracle.truffle.api.TruffleLanguage$Provider when unpacking dependencies -->
<!-- bundle the modular dependencies into an uber-JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>embed-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
<goal>shade</goal>
</goals>
<configuration>
<excludes>META-INF/services/com.oracle.truffle.api.TruffleLanguage$Provider</excludes> <!-- we'll provide this -->
<artifactSet>
<excludes>
<exclude>org.lastnpe.eea:eea-all</exclude>
<exclude>org.apache.karaf.features:framework</exclude>
</excludes>
</artifactSet>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<!-- Transformer to merge module-info.class files, if needed -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -130,32 +142,29 @@

<dependencies>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graal.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>${graal.version}</version>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>polyglot</artifactId>
<version>${graaljs.version}</version>
</dependency>
<!-- Graal JavaScript ScriptEngine JSR 223 support -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>${graal.version}</version>
<version>${graaljs.version}</version>
</dependency>
<!-- Graal TRegex engine (internally used by Graal JavaScript engine) -->
<dependency>
<groupId>org.graalvm.regex</groupId>
<artifactId>regex</artifactId>
<version>${graal.version}</version>
<version>${graaljs.version}</version>
</dependency>
<!-- Graal JavaScript engine (depends on Graal TRegex engine, must be added after it) -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graal.version}</version>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>js-community</artifactId>
<version>${graaljs.version}</version>
<type>pom</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public OpenhabGraalJSScriptEngine(boolean injectionEnabled, boolean injectionCac
.option("js.nashorn-compat", "true") // Enable Nashorn compat mode as openhab-js relies on
// accessors, see
// https://github.com/oracle/graaljs/blob/master/docs/user/NashornMigrationGuide.md#accessors
.option("js.ecmascript-version", "2022") // If Nashorn compat is enabled, it will enforce ES5
// compatibility, we want ECMA2022
.option("js.ecmascript-version", "2024") // If Nashorn compat is enabled, it will enforce ES5
// compatibility, we want ECMA2024
.option("js.commonjs-require", "true") // Enable CommonJS module support
.hostClassLoader(getClass().getClassLoader())
.fileSystem(new DelegatingFileSystem(FileSystems.getDefault().provider()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonSmartHomeCapabilities.SmartHomeCapability;
import org.openhab.binding.amazonechocontrol.internal.jsons.JsonSmartHomeDevices.SmartHomeDevice;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.DefaultSystemChannelTypeProvider;
import org.openhab.core.thing.type.ChannelTypeUID;
import org.openhab.core.types.Command;
Expand Down Expand Up @@ -130,15 +132,21 @@ public boolean handleCommand(Connection connection, SmartHomeDevice shd, String
if (channelId.equals(COLOR_TEMPERATURE_IN_KELVIN.channelId)) {
// WRITING TO THIS CHANNEL DOES CURRENTLY NOT WORK, BUT WE LEAVE THE CODE FOR FUTURE USE!
if (containsCapabilityProperty(capabilities, COLOR_TEMPERATURE_IN_KELVIN.propertyName)) {
if (command instanceof DecimalType) {
int intValue = ((DecimalType) command).intValue();
if (intValue < 1000) {
intValue = 1000;
QuantityType<?> kelvinQuantity = null;
if (command instanceof QuantityType<?> genericQuantity) {
kelvinQuantity = genericQuantity.toInvertibleUnit(Units.KELVIN);
} else if (command instanceof DecimalType decimal) {
kelvinQuantity = QuantityType.valueOf(decimal.intValue(), Units.KELVIN);
}
if (kelvinQuantity != null) {
int kelvin = kelvinQuantity.intValue();
if (kelvin < 1000) {
kelvin = 1000;
}
if (intValue > 10000) {
intValue = 10000;
if (kelvin > 10000) {
kelvin = 10000;
}
connection.smartHomeCommand(entityId, "setColorTemperature", "colorTemperatureInKelvin", intValue);
connection.smartHomeCommand(entityId, "setColorTemperature", "colorTemperatureInKelvin", kelvin);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import static org.openhab.binding.deconz.internal.BindingConstants.*;
import static org.openhab.binding.deconz.internal.Util.constrainToRange;
import static org.openhab.binding.deconz.internal.Util.kelvinToMired;

import java.util.Collection;
import java.util.Map;
Expand All @@ -36,7 +35,9 @@
import org.openhab.core.library.types.HSBType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
Expand Down Expand Up @@ -139,9 +140,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
case CHANNEL_COLOR_TEMPERATURE -> {
if (command instanceof DecimalType decimalCommand) {
int miredValue = kelvinToMired(decimalCommand.intValue());
newGroupAction.ct = constrainToRange(miredValue, ZCL_CT_MIN, ZCL_CT_MAX);
QuantityType<?> miredQuantity = null;
if (command instanceof QuantityType<?> genericQuantity) {
miredQuantity = genericQuantity.toInvertibleUnit(Units.MIRED);
} else if (command instanceof DecimalType decimal) {
miredQuantity = QuantityType.valueOf(decimal.intValue(), Units.KELVIN)
.toInvertibleUnit(Units.MIRED);
}
if (miredQuantity != null) {
newGroupAction.ct = constrainToRange(miredQuantity.intValue(), ZCL_CT_MIN, ZCL_CT_MAX);
newGroupAction.on = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,15 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
case CHANNEL_COLOR_TEMPERATURE -> {
if (command instanceof DecimalType) {
int miredValue = kelvinToMired(((DecimalType) command).intValue());
newLightState.ct = constrainToRange(miredValue, ctMin, ctMax);
QuantityType<?> miredQuantity = null;
if (command instanceof QuantityType<?> genericQuantity) {
miredQuantity = genericQuantity.toInvertibleUnit(Units.MIRED);
} else if (command instanceof DecimalType decimal) {
miredQuantity = QuantityType.valueOf(decimal.intValue(), Units.KELVIN)
.toInvertibleUnit(Units.MIRED);
}
if (miredQuantity != null) {
newLightState.ct = constrainToRange(miredQuantity.intValue(), ctMin, ctMax);
newLightState.on = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.exec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Please note that if the transformation failed or returned `null`, the original d
Thing exec:command:uniquename [command="/command/to/execute here", interval=15, timeout=5, autorun=false]
```

The `command` itself can be enhanced using the well known syntax of the [Java formatter class syntax](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Formatter.html#syntax).
The `command` itself can be enhanced using the well known syntax of the [Java formatter class syntax](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Formatter.html#syntax).
The following parameters are automatically added:

- the current date (as java.util.Date, example: `%1$tY-%1$tm-%1$td`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ public void setDatapointOnWebsocketFeedback(String receivedText) {

if (deviceHandler != null) {
deviceHandler.onDeviceStateChanged(eventDatapointID, value);
logger.debug("Socket event processed: event-datapoint-ID {} value {}", eventDatapointID, value);
} else {
logger.debug("Socket event not processed: event-datapoint-ID {} value {}", eventDatapointID, value);
}

logger.debug("Socket event processed: event-datapoint-ID {} value {}", eventDatapointID, value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if (dpg == null) {
logger.debug("Handle command for device (but invalid datapointgroup) {} - at channel {} - full command {}",
device.getDeviceId(), channelUID.getAsString(), command.toFullString());

updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"@text/conf-error.invalid-deviceconfig");
} else {
Expand Down Expand Up @@ -480,8 +479,7 @@ public void updateChannels() throws FreeAtHomeGeneralException {
channelTypeUID = createChannelTypeForDatapointgroup(dpg, channelTypeUID);
}

ChannelUID channelUID = new ChannelUID(thingUID, channel.getChannelId(),
dpg.getLabel().substring(4));
ChannelUID channelUID = createChannelUID(thingUID, channel.getChannelId(), dpg.getLabel());

String channelLabel = String.format("%s",
i18nProvider.getText(bundle, dpg.getLabel(), "-", locale));
Expand Down Expand Up @@ -568,7 +566,7 @@ private void reloadChannelTypes() throws FreeAtHomeGeneralException {
channelTypeUID = createChannelTypeForDatapointgroup(dpg, channelTypeUID);
}

ChannelUID channelUID = new ChannelUID(thingUID, channel.getChannelId());
ChannelUID channelUID = createChannelUID(thingUID, channel.getChannelId(), dpg.getLabel());

FreeAtHomeDatapoint outputDatapoint = dpg.getOutputDatapoint();

Expand All @@ -589,6 +587,11 @@ private void reloadChannelTypes() throws FreeAtHomeGeneralException {
}
}

// Create a channel UID. Makes sure that the channel UID is unique and generated the same way every time
private ChannelUID createChannelUID(ThingUID thingUID, String channelID, String dpgLabel) {
return new ChannelUID(thingUID, channelID, dpgLabel.substring(4));
}

public void removeChannels() {
Bridge bridge = this.getBridge();

Expand Down
Loading

0 comments on commit 0d1cb0b

Please sign in to comment.