├── .github └── workflows │ └── maven.yaml ├── .gitignore ├── LICENSE ├── MIGRATE.md ├── NOTICE ├── README.md ├── doc ├── CHANGELOG.md ├── CONFIGURATION.md └── EXAMPLES.md ├── enable_disable_rule.png ├── img └── logo.png ├── jitpack.yml ├── pom.xml ├── rules_ui.png ├── src ├── main │ ├── feature │ │ └── feature.xml │ ├── history │ │ └── dependencies.xml │ ├── java │ │ └── org │ │ │ └── openhab │ │ │ └── automation │ │ │ └── jrule │ │ │ ├── actions │ │ │ ├── JRuleAbstractAction.java │ │ │ └── JRuleActionClassGenerator.java │ │ │ ├── exception │ │ │ ├── JRuleExecutionException.java │ │ │ ├── JRuleItemNotFoundException.java │ │ │ └── JRuleRuntimeException.java │ │ │ ├── internal │ │ │ ├── JRuleConfig.java │ │ │ ├── JRuleConstants.java │ │ │ ├── JRuleDelayedDebouncingExecutor.java │ │ │ ├── JRuleFactory.java │ │ │ ├── JRuleLog.java │ │ │ ├── JRuleUtil.java │ │ │ ├── compiler │ │ │ │ ├── JRuleCompiler.java │ │ │ │ └── JRuleJarExtractor.java │ │ │ ├── engine │ │ │ │ ├── JRuleBuilder.java │ │ │ │ ├── JRuleEngine.java │ │ │ │ ├── JRuleInvocationCallback.java │ │ │ │ ├── JRuleLoadingStatistics.java │ │ │ │ ├── excutioncontext │ │ │ │ │ ├── JRuleChannelExecutionContext.java │ │ │ │ │ ├── JRuleExecutionContext.java │ │ │ │ │ ├── JRuleItemChangeExecutionContext.java │ │ │ │ │ ├── JRuleItemExecutionContext.java │ │ │ │ │ ├── JRuleItemReceivedCommandExecutionContext.java │ │ │ │ │ ├── JRuleItemReceivedUpdateExecutionContext.java │ │ │ │ │ ├── JRuleLocalTimerExecutionContext.java │ │ │ │ │ ├── JRulePreconditionContext.java │ │ │ │ │ ├── JRuleThingExecutionContext.java │ │ │ │ │ ├── JRuleTimeTimerExecutionContext.java │ │ │ │ │ ├── JRuleTimedCronExecutionContext.java │ │ │ │ │ └── JRuleTimedExecutionContext.java │ │ │ │ └── timer │ │ │ │ │ └── JRuleTimerExecutor.java │ │ │ ├── events │ │ │ │ └── JRuleEventSubscriber.java │ │ │ ├── generator │ │ │ │ └── JRuleAbstractClassGenerator.java │ │ │ ├── handler │ │ │ │ ├── JRuleActionHandler.java │ │ │ │ ├── JRuleAddonActionHandler.java │ │ │ │ ├── JRuleEventHandler.java │ │ │ │ ├── JRuleHandler.java │ │ │ │ ├── JRuleItemHandler.java │ │ │ │ ├── JRuleThingHandler.java │ │ │ │ ├── JRuleTimerHandler.java │ │ │ │ ├── JRuleTransformationHandler.java │ │ │ │ └── JRuleVoiceHandler.java │ │ │ ├── items │ │ │ │ ├── JRuleInternalCallGroupItem.java │ │ │ │ ├── JRuleInternalCallItem.java │ │ │ │ ├── JRuleInternalColorGroupItem.java │ │ │ │ ├── JRuleInternalColorItem.java │ │ │ │ ├── JRuleInternalContactGroupItem.java │ │ │ │ ├── JRuleInternalContactItem.java │ │ │ │ ├── JRuleInternalDateTimeGroupItem.java │ │ │ │ ├── JRuleInternalDateTimeItem.java │ │ │ │ ├── JRuleInternalDimmerGroupItem.java │ │ │ │ ├── JRuleInternalDimmerItem.java │ │ │ │ ├── JRuleInternalImageGroupItem.java │ │ │ │ ├── JRuleInternalImageItem.java │ │ │ │ ├── JRuleInternalItem.java │ │ │ │ ├── JRuleInternalLocationGroupItem.java │ │ │ │ ├── JRuleInternalLocationItem.java │ │ │ │ ├── JRuleInternalNumberGroupItem.java │ │ │ │ ├── JRuleInternalNumberItem.java │ │ │ │ ├── JRuleInternalPlayerGroupItem.java │ │ │ │ ├── JRuleInternalPlayerItem.java │ │ │ │ ├── JRuleInternalQuantityGroupItem.java │ │ │ │ ├── JRuleInternalQuantityItem.java │ │ │ │ ├── JRuleInternalRollershutterGroupItem.java │ │ │ │ ├── JRuleInternalRollershutterItem.java │ │ │ │ ├── JRuleInternalStringGroupItem.java │ │ │ │ ├── JRuleInternalStringItem.java │ │ │ │ ├── JRuleInternalSwitchGroupItem.java │ │ │ │ ├── JRuleInternalSwitchItem.java │ │ │ │ └── JRuleInternalUnspecifiedGroupItem.java │ │ │ ├── module │ │ │ │ ├── JRuleEventFactory.java │ │ │ │ ├── JRuleModuleEntry.java │ │ │ │ ├── JRuleModuleHandlerFactory.java │ │ │ │ ├── JRuleModuleTypeProvider.java │ │ │ │ ├── JRuleModuleUtil.java │ │ │ │ ├── JRuleRuleProvider.java │ │ │ │ ├── JRuleTriggerHandler.java │ │ │ │ └── JRuleTriggerType.java │ │ │ ├── test │ │ │ │ ├── JRuleMockedEventBus.java │ │ │ │ ├── JRuleMockedItemStateChangedEvent.java │ │ │ │ └── JRuleTestEventLogParser.java │ │ │ └── watch │ │ │ │ └── JRuleRulesWatcher.java │ │ │ ├── items │ │ │ ├── JRuleCallGroupItem.java │ │ │ ├── JRuleCallItem.java │ │ │ ├── JRuleColorGroupItem.java │ │ │ ├── JRuleColorItem.java │ │ │ ├── JRuleContactGroupItem.java │ │ │ ├── JRuleContactItem.java │ │ │ ├── JRuleDateTimeGroupItem.java │ │ │ ├── JRuleDateTimeItem.java │ │ │ ├── JRuleDimmerGroupItem.java │ │ │ ├── JRuleDimmerItem.java │ │ │ ├── JRuleGroupItem.java │ │ │ ├── JRuleImageGroupItem.java │ │ │ ├── JRuleImageItem.java │ │ │ ├── JRuleItem.java │ │ │ ├── JRuleItemClassGenerator.java │ │ │ ├── JRuleItemNameClassGenerator.java │ │ │ ├── JRuleItemRegistry.java │ │ │ ├── JRuleLocationGroupItem.java │ │ │ ├── JRuleLocationItem.java │ │ │ ├── JRuleNumberGroupItem.java │ │ │ ├── JRuleNumberItem.java │ │ │ ├── JRulePlayerGroupItem.java │ │ │ ├── JRulePlayerItem.java │ │ │ ├── JRuleQuantityGroupItem.java │ │ │ ├── JRuleQuantityItem.java │ │ │ ├── JRuleRollershutterGroupItem.java │ │ │ ├── JRuleRollershutterItem.java │ │ │ ├── JRuleStringGroupItem.java │ │ │ ├── JRuleStringItem.java │ │ │ ├── JRuleSwitchGroupItem.java │ │ │ ├── JRuleSwitchItem.java │ │ │ ├── JRuleUnspecifiedGroupItem.java │ │ │ └── metadata │ │ │ │ ├── JRuleItemMetadata.java │ │ │ │ └── JRuleMetadataRegistry.java │ │ │ ├── persistence │ │ │ ├── JRuleHistoricState.java │ │ │ └── JRulePersistence.java │ │ │ ├── rules │ │ │ ├── JRule.java │ │ │ ├── JRuleCondition.java │ │ │ ├── JRuleDebounce.java │ │ │ ├── JRuleDelayed.java │ │ │ ├── JRuleEventState.java │ │ │ ├── JRuleLogName.java │ │ │ ├── JRuleMemberOf.java │ │ │ ├── JRuleName.java │ │ │ ├── JRulePrecondition.java │ │ │ ├── JRulePreconditions.java │ │ │ ├── JRuleState.java │ │ │ ├── JRuleTag.java │ │ │ ├── JRuleTrigger.java │ │ │ ├── JRuleWhenChannelTrigger.java │ │ │ ├── JRuleWhenChannelTriggers.java │ │ │ ├── JRuleWhenCronTrigger.java │ │ │ ├── JRuleWhenCronTriggers.java │ │ │ ├── JRuleWhenItemChange.java │ │ │ ├── JRuleWhenItemChanges.java │ │ │ ├── JRuleWhenItemReceivedCommand.java │ │ │ ├── JRuleWhenItemReceivedCommands.java │ │ │ ├── JRuleWhenItemReceivedUpdate.java │ │ │ ├── JRuleWhenItemReceivedUpdates.java │ │ │ ├── JRuleWhenThingTrigger.java │ │ │ ├── JRuleWhenThingTriggers.java │ │ │ ├── JRuleWhenTimeTrigger.java │ │ │ ├── JRuleWhenTimeTriggers.java │ │ │ ├── event │ │ │ │ ├── JRuleChannelEvent.java │ │ │ │ ├── JRuleEvent.java │ │ │ │ ├── JRuleItemEvent.java │ │ │ │ ├── JRuleThingEvent.java │ │ │ │ └── JRuleTimerEvent.java │ │ │ └── value │ │ │ │ ├── JRuleDateTimeValue.java │ │ │ │ ├── JRuleDecimalValue.java │ │ │ │ ├── JRuleHsbValue.java │ │ │ │ ├── JRuleIncreaseDecreaseValue.java │ │ │ │ ├── JRuleNextPreviousValue.java │ │ │ │ ├── JRuleOnOffValue.java │ │ │ │ ├── JRuleOpenClosedValue.java │ │ │ │ ├── JRulePercentValue.java │ │ │ │ ├── JRulePlayPauseValue.java │ │ │ │ ├── JRulePointValue.java │ │ │ │ ├── JRuleQuantityValue.java │ │ │ │ ├── JRuleRawValue.java │ │ │ │ ├── JRuleRefreshValue.java │ │ │ │ ├── JRuleRewindFastforwardValue.java │ │ │ │ ├── JRuleStopMoveValue.java │ │ │ │ ├── JRuleStringListValue.java │ │ │ │ ├── JRuleStringValue.java │ │ │ │ ├── JRuleUpDownValue.java │ │ │ │ ├── JRuleValue.java │ │ │ │ └── JRuleValueBase.java │ │ │ ├── things │ │ │ ├── JRuleAbstractThing.java │ │ │ ├── JRuleBridgeThing.java │ │ │ ├── JRuleChannel.java │ │ │ ├── JRuleStandaloneThing.java │ │ │ ├── JRuleSubThing.java │ │ │ ├── JRuleThingClassGenerator.java │ │ │ ├── JRuleThingRegistry.java │ │ │ └── JRuleThingStatus.java │ │ │ └── trigger │ │ │ ├── JRuleContactTrigger.java │ │ │ └── JRulePlayerTrigger.java │ └── resources │ │ ├── OH-INF │ │ └── addon │ │ │ └── addon.xml │ │ ├── jrule.conf.default │ │ └── templates │ │ ├── CommonLicense.ftlh │ │ ├── actions │ │ ├── Action.ftlh │ │ ├── ActionConstructor.ftlh │ │ ├── ActionJavadoc.ftlh │ │ ├── ActionMethod.ftlh │ │ └── Actions.ftlh │ │ ├── items │ │ ├── CommonJavadoc.ftlh │ │ ├── CommonMethods.ftlh │ │ ├── ItemNames.ftlh │ │ └── Items.ftlh │ │ └── things │ │ ├── BridgeThing.ftlh │ │ ├── Standalone.ftlh │ │ ├── SubThing.ftlh │ │ ├── ThingJavadoc.ftlh │ │ ├── ThingMethods.ftlh │ │ └── Things.ftlh └── test │ ├── java │ └── org │ │ └── openhab │ │ └── automation │ │ └── jrule │ │ ├── internal │ │ ├── JRuleUtilTest.java │ │ ├── QuantityTypeParsingTest.java │ │ ├── codegenerator │ │ │ ├── JRuleActionClassGeneratorTest.java │ │ │ ├── JRuleItemClassGeneratorTest.java │ │ │ ├── JRuleItemNameClassGeneratorTest.java │ │ │ └── JRuleThingClassGeneratorTest.java │ │ ├── engine │ │ │ └── JRuleBuilderTest.java │ │ ├── rules │ │ │ ├── CollectingEventPublisher.java │ │ │ ├── JRuleAbstractTest.java │ │ │ ├── delayed │ │ │ │ ├── JRuleDelayedTest.java │ │ │ │ └── JRuleDelayedTestRules.java │ │ │ ├── timers │ │ │ │ ├── JRuleTimerTest.java │ │ │ │ ├── JRuleTimerTestRules.java │ │ │ │ └── TargetItem.java │ │ │ └── triggers │ │ │ │ ├── itemchange │ │ │ │ ├── JRuleItemChangeRules.java │ │ │ │ └── JRuleItemChangeTest.java │ │ │ │ └── itemchangecondition │ │ │ │ ├── JRuleItemChangeConditionRules.java │ │ │ │ └── JRuleItemChangeConditionTest.java │ │ ├── thingaction │ │ │ └── MyThingActions.java │ │ └── triggers │ │ │ └── itemchange │ │ │ ├── JRuleGroupItemChangeRules.java │ │ │ └── JRuleGroupItemChangeTest.java │ │ ├── items │ │ ├── JRuleCallGroupItemTest.java │ │ ├── JRuleCallItemTest.java │ │ ├── JRuleColorGroupItemTest.java │ │ ├── JRuleColorItemTest.java │ │ ├── JRuleContactGroupItemTest.java │ │ ├── JRuleContactItemTest.java │ │ ├── JRuleDateTimeGroupItemTest.java │ │ ├── JRuleDateTimeItemTest.java │ │ ├── JRuleDimmerGroupItemTest.java │ │ ├── JRuleDimmerItemTest.java │ │ ├── JRuleImageGroupItemTest.java │ │ ├── JRuleImageItemTest.java │ │ ├── JRuleItemTest.java │ │ ├── JRuleItemTestBase.java │ │ ├── JRuleLocationGroupItemTest.java │ │ ├── JRuleLocationItemTest.java │ │ ├── JRuleNumberGroupItemTest.java │ │ ├── JRuleNumberItemTest.java │ │ ├── JRulePlayerGroupItemTest.java │ │ ├── JRulePlayerItemTest.java │ │ ├── JRuleQuantityGroupItemTest.java │ │ ├── JRuleQuantityItemTest.java │ │ ├── JRuleRollershutterGroupItemTest.java │ │ ├── JRuleRollershutterItemTest.java │ │ ├── JRuleStringGroupItemTest.java │ │ ├── JRuleStringItemTest.java │ │ ├── JRuleSwitchGroupItemTest.java │ │ ├── JRuleSwitchItemTest.java │ │ └── JRuleUnspecifiedGroupItemTest.java │ │ ├── rules │ │ ├── JRuleHttpTest.java │ │ ├── integration_test │ │ │ ├── ITJRule.java │ │ │ ├── ITJRuleHttpActions.java │ │ │ ├── ITJRulePersistence.java │ │ │ ├── ITJRuleReceiveCommands.java │ │ │ └── JRuleITBase.java │ │ ├── user │ │ │ ├── TestPersistence.java │ │ │ ├── TestReceiveCommands.java │ │ │ ├── TestRules.java │ │ │ └── TestRulesHttpActions.java │ │ └── value │ │ │ ├── JRuleDateTimeValueTest.java │ │ │ ├── JRuleDecimalValueTest.java │ │ │ ├── JRuleHsbValueTest.java │ │ │ ├── JRuleIncreaseDecreaseValueTest.java │ │ │ ├── JRuleOnOffValueTest.java │ │ │ ├── JRuleOpenClosedValueTest.java │ │ │ ├── JRulePercentValueTest.java │ │ │ ├── JRulePlayPauseValueTest.java │ │ │ ├── JRulePointValueTest.java │ │ │ ├── JRuleQuantityValueTest.java │ │ │ ├── JRuleRawValueTest.java │ │ │ ├── JRuleStopMoveValueTest.java │ │ │ ├── JRuleStringValueTest.java │ │ │ └── JRuleUpDownValueTest.java │ │ └── test_utils │ │ └── JRuleItemTestUtils.java │ ├── maven-resources │ └── version │ └── resources │ ├── docker │ ├── conf │ │ ├── items │ │ │ └── default.items │ │ ├── persistence │ │ │ └── influxdb.persist │ │ ├── services │ │ │ ├── addons.cfg │ │ │ ├── influxdb.cfg │ │ │ ├── rrd4j.cfg │ │ │ └── runtime.cfg │ │ └── things │ │ │ └── mqtt.things │ ├── log4j2.xml │ ├── mosquitto │ │ ├── default.acl │ │ └── mosquitto.conf │ ├── users.json │ └── users.properties │ └── logback-test.xml └── tools └── static-code-analysis ├── checkstyle ├── ruleset.properties └── suppressions.xml └── spotbugs └── suppressions.xml /.github/workflows/maven.yaml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | on: [ push,pull_request ] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v3 8 | - name: Set up JDK 17 9 | uses: actions/setup-java@v3 10 | with: 11 | java-version: '17' 12 | distribution: 'adopt' 13 | cache: 'maven' 14 | - name: Build with Maven 15 | run: mvn --batch-mode --update-snapshots install 16 | - run: mkdir staging && cp target/org.openhab.automation.jrule*SNAPSHOT.jar staging 17 | - uses: actions/upload-artifact@v4 18 | with: 19 | name: JRule-jar-zipped_build_${{ github.run_id }} 20 | path: staging 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /tmp/ 3 | .classpath 4 | .project 5 | .settings/ 6 | bin/ 7 | 8 | *.iml 9 | */.lck 10 | 11 | .idea/* -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | This content is produced and maintained by the openHAB project. 2 | 3 | * Project home: https://www.openhab.org 4 | 5 | == Declared Project Licenses 6 | 7 | This program and the accompanying materials are made available under the terms 8 | of the Eclipse Public License 2.0 which is available at 9 | https://www.eclipse.org/legal/epl-2.0/. 10 | 11 | == Source Code 12 | 13 | https://github.com/openhab/openhab-addons 14 | -------------------------------------------------------------------------------- /doc/CONFIGURATION.md: -------------------------------------------------------------------------------- 1 | # JRule Configuration 2 | 3 | JRule can be configured by adding 4 | a file called [OPENHAB_INSTALL_FOLDER]/conf/automation/jrule/jrule.conf 5 | 6 | The parameters available for configuration can be found here: 7 | 8 | https://github.com/seaside1/jrule/blob/main/src/main/resources/jrule.conf.default 9 | -------------------------------------------------------------------------------- /enable_disable_rule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seaside1/jrule/f4d5a4e3c351123d4cd8cd41763e4801b9be63b0/enable_disable_rule.png -------------------------------------------------------------------------------- /img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seaside1/jrule/f4d5a4e3c351123d4cd8cd41763e4801b9be63b0/img/logo.png -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 3 | -------------------------------------------------------------------------------- /rules_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seaside1/jrule/f4d5a4e3c351123d4cd8cd41763e4801b9be63b0/rules_ui.png -------------------------------------------------------------------------------- /src/main/feature/feature.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features 4 | 5 | 6 | openhab-runtime-base 7 | mvn:org.openhab.addons.bundles/org.openhab.automation.jrule/${project.version} 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/main/history/dependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | openhab-runtime-base 5 | wrap 6 | mvn:javax.el/javax.el-api/2.2.4 7 | mvn:org.freemarker/freemarker/2.3.32 8 | mvn:org.openhab.addons.bundles/org.openhab.automation.jrule/4.2.1-SNAPSHOT 9 | wrap:mvn:javax.servlet/jsp-api/2.0 10 | wrap:mvn:javax.servlet/servlet-api/2.4 11 | wrap:mvn:org.lastnpe.eea/eea-all/2.2.1 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/actions/JRuleAbstractAction.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.actions; 14 | 15 | import java.lang.reflect.InvocationTargetException; 16 | import java.lang.reflect.Method; 17 | import java.util.Objects; 18 | 19 | import org.openhab.core.model.script.actions.Things; 20 | import org.openhab.core.thing.binding.ThingActions; 21 | 22 | /** 23 | * The {@link JRuleAbstractAction} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | public abstract class JRuleAbstractAction { 28 | private final ThingActions thingActions; 29 | private final String scope; 30 | private final String thingUID; 31 | 32 | protected JRuleAbstractAction(String scope, String thingUID) { 33 | this.scope = scope; 34 | this.thingUID = thingUID; 35 | thingActions = Objects.requireNonNull(Things.getActions(scope, thingUID), 36 | String.format("action for '%s' with uid '%s' could not be found", scope, thingUID)); 37 | } 38 | 39 | protected Object invokeMethod(String methodName, Class[] classes, Object... args) { 40 | try { 41 | Method method = thingActions.getClass().getDeclaredMethod(methodName, classes); 42 | return method.invoke(thingActions, args); 43 | } catch (NoSuchMethodException e) { 44 | throw new RuntimeException("method not found", e); 45 | } catch (InvocationTargetException e) { 46 | throw new RuntimeException("error invoking method", e); 47 | } catch (IllegalAccessException e) { 48 | throw new RuntimeException("cannot access method", e); 49 | } 50 | } 51 | 52 | public String getThingUID() { 53 | return thingUID; 54 | } 55 | 56 | public String getScope() { 57 | return scope; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/exception/JRuleExecutionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.exception; 14 | 15 | /** 16 | * The {@link JRuleExecutionException} wraps underlying openHAB exceptions 17 | * 18 | * @author Arne Seime - Initial contribution 19 | */ 20 | public class JRuleExecutionException extends Exception { 21 | public JRuleExecutionException(String message) { 22 | super(message); 23 | } 24 | 25 | public JRuleExecutionException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/exception/JRuleItemNotFoundException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.exception; 14 | 15 | /** 16 | * The {@link JRuleItemNotFoundException} rethrows internal ItemNotFoundException's 17 | * 18 | * @author Robert Delbrück 19 | */ 20 | public class JRuleItemNotFoundException extends JRuleRuntimeException { 21 | public JRuleItemNotFoundException(String message) { 22 | super(message); 23 | } 24 | 25 | public JRuleItemNotFoundException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/exception/JRuleRuntimeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.exception; 14 | 15 | /** 16 | * The {@link JRuleRuntimeException} is for throwing internal runtime exceptions 17 | * 18 | * @author Robert Delbrück 19 | */ 20 | public class JRuleRuntimeException extends RuntimeException { 21 | public JRuleRuntimeException(String message) { 22 | super(message); 23 | } 24 | 25 | public JRuleRuntimeException(String message, Throwable cause) { 26 | super(message, cause); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/JRuleConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal; 14 | 15 | import org.eclipse.jdt.annotation.NonNullByDefault; 16 | 17 | /** 18 | * The {@link JRuleConstants} class defines common constants, which are 19 | * used across the Java Rule automation. 20 | * 21 | * @author Joseph (Seaside) Hagberg - Initial contribution 22 | */ 23 | @NonNullByDefault 24 | public class JRuleConstants { 25 | public static final String JAVA_FILE_TYPE = ".java"; 26 | public static final String CLASS_FILE_TYPE = ".class"; 27 | public static final String EMPTY = ""; 28 | public static final String JAR_FILE_TYPE = ".jar"; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/engine/JRuleInvocationCallback.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.engine; 14 | 15 | import org.openhab.automation.jrule.rules.event.JRuleEvent; 16 | 17 | /** 18 | * The {@link JRuleInvocationCallback} 19 | * 20 | * @author Rüdiger Sopp - Initial contribution 21 | */ 22 | @FunctionalInterface 23 | public interface JRuleInvocationCallback { 24 | void accept(JRuleEvent event); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/engine/excutioncontext/JRuleLocalTimerExecutionContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.engine.excutioncontext; 14 | 15 | import org.openhab.automation.jrule.rules.event.JRuleEvent; 16 | import org.openhab.core.events.AbstractEvent; 17 | 18 | /** 19 | * The {@link JRuleLocalTimerExecutionContext} is used to provide context information when executing local timers 20 | * created inside rules 21 | * 22 | * @author Arne Seime - Initial contribution 23 | */ 24 | public class JRuleLocalTimerExecutionContext extends JRuleExecutionContext { 25 | 26 | private JRuleExecutionContext parentContext; 27 | private String timerName; 28 | 29 | public JRuleLocalTimerExecutionContext(JRuleExecutionContext parentContext, String timerName) { 30 | super(parentContext.getUid(), parentContext.getLogName(), parentContext.getLoggingTags(), 31 | parentContext.getInvocationCallback(), parentContext.getPreconditionContextList(), null, null); 32 | this.parentContext = parentContext; 33 | this.timerName = timerName; 34 | } 35 | 36 | @Override 37 | public JRuleEvent createJRuleEvent(AbstractEvent event) { 38 | return null; 39 | } 40 | 41 | @Override 42 | public String getLogName() { 43 | return parentContext.getLogName() + " / " + timerName; 44 | } 45 | 46 | @Override 47 | public boolean match(AbstractEvent event, JRuleAdditionalCheckData checkData) { 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/engine/excutioncontext/JRuleTimedExecutionContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.engine.excutioncontext; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.internal.engine.JRuleInvocationCallback; 18 | 19 | /** 20 | * The {@link JRuleTimedExecutionContext} 21 | * 22 | * @author Robert Delbrück - Initial contribution 23 | */ 24 | public abstract class JRuleTimedExecutionContext extends JRuleExecutionContext { 25 | public JRuleTimedExecutionContext(String uid, String logName, String[] loggingTags, 26 | JRuleInvocationCallback invocationCallback, List preconditionContextList) { 27 | super(uid, logName, loggingTags, invocationCallback, preconditionContextList, null, null); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalCallGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleCallGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalCallGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalCallGroupItem extends JRuleInternalCallItem implements JRuleCallGroupItem { 26 | 27 | public JRuleInternalCallGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalCallItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleCallItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalCallItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalCallItem extends JRuleInternalItem implements JRuleCallItem { 26 | 27 | public JRuleInternalCallItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalColorGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleColorGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalColorGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalColorGroupItem extends JRuleInternalColorItem implements JRuleColorGroupItem { 26 | 27 | public JRuleInternalColorGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalColorItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleColorItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalColorItem} Items 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | public class JRuleInternalColorItem extends JRuleInternalDimmerItem implements JRuleColorItem { 26 | 27 | public JRuleInternalColorItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalContactGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleContactGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalContactGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalContactGroupItem extends JRuleInternalContactItem implements JRuleContactGroupItem { 26 | 27 | public JRuleInternalContactGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalContactItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleContactItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalContactItem} Items 22 | * 23 | * @author Timo Litzius - Initial contribution 24 | */ 25 | public class JRuleInternalContactItem extends JRuleInternalItem implements JRuleContactItem { 26 | 27 | public JRuleInternalContactItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalDateTimeGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleDateTimeGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalDateTimeGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalDateTimeGroupItem extends JRuleInternalDateTimeItem implements JRuleDateTimeGroupItem { 26 | 27 | public JRuleInternalDateTimeGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalDateTimeItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleDateTimeItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalDateTimeItem} Items 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | public class JRuleInternalDateTimeItem extends JRuleInternalItem implements JRuleDateTimeItem { 26 | 27 | public JRuleInternalDateTimeItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalDimmerGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleDimmerGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalDimmerGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalDimmerGroupItem extends JRuleInternalDimmerItem implements JRuleDimmerGroupItem { 26 | public JRuleInternalDimmerGroupItem(String name, String label, String type, String id, 27 | JRuleMetadataRegistry metadataRegistry, List tags) { 28 | super(name, label, type, id, metadataRegistry, tags); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalDimmerItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleDimmerItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalDimmerItem} Items 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | public class JRuleInternalDimmerItem extends JRuleInternalSwitchItem implements JRuleDimmerItem { 26 | public JRuleInternalDimmerItem(String name, String label, String type, String id, 27 | JRuleMetadataRegistry metadataRegistry, List tags) { 28 | super(name, label, type, id, metadataRegistry, tags); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalImageGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleImageGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalImageGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalImageGroupItem extends JRuleInternalImageItem implements JRuleImageGroupItem { 26 | 27 | public JRuleInternalImageGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalImageItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleImageItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalImageItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalImageItem extends JRuleInternalItem implements JRuleImageItem { 26 | public JRuleInternalImageItem(String name, String label, String type, String id, 27 | JRuleMetadataRegistry metadataRegistry, List tags) { 28 | super(name, label, type, id, metadataRegistry, tags); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalLocationGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleLocationGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalLocationGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalLocationGroupItem extends JRuleInternalLocationItem implements JRuleLocationGroupItem { 26 | 27 | public JRuleInternalLocationGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalLocationItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleLocationItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalLocationItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalLocationItem extends JRuleInternalItem implements JRuleLocationItem { 26 | public JRuleInternalLocationItem(String name, String label, String type, String id, 27 | JRuleMetadataRegistry metadataRegistry, List tags) { 28 | super(name, label, type, id, metadataRegistry, tags); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalNumberGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleNumberGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalNumberGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalNumberGroupItem extends JRuleInternalNumberItem implements JRuleNumberGroupItem { 26 | 27 | public JRuleInternalNumberGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalNumberItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleNumberItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalNumberItem} Items 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | public class JRuleInternalNumberItem extends JRuleInternalItem implements JRuleNumberItem { 26 | 27 | public JRuleInternalNumberItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalPlayerGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRulePlayerGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalPlayerGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalPlayerGroupItem extends JRuleInternalPlayerItem implements JRulePlayerGroupItem { 26 | 27 | public JRuleInternalPlayerGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalPlayerItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRulePlayerItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalPlayerItem} Items 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | public class JRuleInternalPlayerItem extends JRuleInternalItem implements JRulePlayerItem { 26 | 27 | public JRuleInternalPlayerItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalQuantityGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleQuantityGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalColorGroupItem} Items 22 | * 23 | * @author Robert Delbrück - Initial contribution 24 | */ 25 | public class JRuleInternalQuantityGroupItem extends JRuleInternalQuantityItem implements JRuleQuantityGroupItem { 26 | 27 | public JRuleInternalQuantityGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalQuantityItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleQuantityItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalQuantityItem} Items 22 | * 23 | * @author Robert Delbrück - Initial contribution 24 | */ 25 | public class JRuleInternalQuantityItem extends JRuleInternalItem implements JRuleQuantityItem { 26 | 27 | public JRuleInternalQuantityItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalRollershutterGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleRollershutterGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalRollershutterGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalRollershutterGroupItem extends JRuleInternalRollershutterItem 26 | implements JRuleRollershutterGroupItem { 27 | 28 | public JRuleInternalRollershutterGroupItem(String name, String label, String type, String id, 29 | JRuleMetadataRegistry metadataRegistry, List tags) { 30 | super(name, label, type, id, metadataRegistry, tags); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalRollershutterItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleRollershutterItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalRollershutterItem} Items 22 | * 23 | * @author Timo Litzius - Initial contribution 24 | */ 25 | public class JRuleInternalRollershutterItem extends JRuleInternalItem implements JRuleRollershutterItem { 26 | 27 | public JRuleInternalRollershutterItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalStringGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleStringGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalStringGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalStringGroupItem extends JRuleInternalStringItem implements JRuleStringGroupItem { 26 | 27 | public JRuleInternalStringGroupItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalStringItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleStringItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalStringItem} Items 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | public class JRuleInternalStringItem extends JRuleInternalItem implements JRuleStringItem { 26 | 27 | public JRuleInternalStringItem(String name, String label, String type, String id, 28 | JRuleMetadataRegistry metadataRegistry, List tags) { 29 | super(name, label, type, id, metadataRegistry, tags); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalSwitchGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleSwitchGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalSwitchGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalSwitchGroupItem extends JRuleInternalSwitchItem implements JRuleSwitchGroupItem { 26 | public JRuleInternalSwitchGroupItem(String name, String label, String type, String id, 27 | JRuleMetadataRegistry metadataRegistry, List tags) { 28 | super(name, label, type, id, metadataRegistry, tags); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalSwitchItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleSwitchItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalSwitchItem} Items 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | public class JRuleInternalSwitchItem extends JRuleInternalItem implements JRuleSwitchItem { 26 | public JRuleInternalSwitchItem(String name, String label, String type, String id, 27 | JRuleMetadataRegistry metadataRegistry, List tags) { 28 | super(name, label, type, id, metadataRegistry, tags); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/items/JRuleInternalUnspecifiedGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.items; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.items.JRuleUnspecifiedGroupItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * The {@link JRuleInternalUnspecifiedGroupItem} Items 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleInternalUnspecifiedGroupItem extends JRuleInternalItem implements JRuleUnspecifiedGroupItem { 26 | public JRuleInternalUnspecifiedGroupItem(String name, String label, String type, String id, 27 | JRuleMetadataRegistry metadataRegistry, List tags) { 28 | super(name, label, type, id, metadataRegistry, tags); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/module/JRuleModuleUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.module; 14 | 15 | /** 16 | * 17 | * @author Arne Seime - Initial Contribution 18 | */ 19 | public class JRuleModuleUtil { 20 | 21 | public static String toTriggerModuleUID(Class annotation) { 22 | return JRuleTriggerHandler.TRIGGER_PREFIX + annotation.getSimpleName(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/module/JRuleTriggerHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.module; 14 | 15 | import org.openhab.core.automation.ModuleHandlerCallback; 16 | import org.openhab.core.automation.Trigger; 17 | import org.openhab.core.automation.handler.BaseTriggerModuleHandler; 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | /** 22 | * 23 | * @author Arne Seime - Initial Contribution 24 | */ 25 | public class JRuleTriggerHandler extends BaseTriggerModuleHandler { 26 | 27 | public static final String TRIGGER_PREFIX = JRuleRuleProvider.MODULE_PREFIX + "trigger."; 28 | private JRuleRuleProvider jRuleRuleProvider; 29 | private String ruleUID; 30 | 31 | private final Logger logger = LoggerFactory.getLogger(JRuleTriggerHandler.class); 32 | 33 | public JRuleTriggerHandler(Trigger module, JRuleRuleProvider jRuleRuleProvider, String ruleUID) { 34 | super(module); 35 | this.jRuleRuleProvider = jRuleRuleProvider; 36 | this.ruleUID = ruleUID; 37 | } 38 | 39 | @Override 40 | public void setCallback(ModuleHandlerCallback callback) { 41 | JRuleModuleEntry rule = jRuleRuleProvider.getRule(ruleUID); 42 | if (rule != null) { 43 | rule.ruleEnabled(); 44 | } else { 45 | logger.error("Did not find rule {}, unable to enable", ruleUID); 46 | } 47 | } 48 | 49 | @Override 50 | public void dispose() { 51 | super.dispose(); 52 | JRuleModuleEntry rule = jRuleRuleProvider.getRule(ruleUID); 53 | if (rule != null) { 54 | rule.ruleDisabled(); 55 | } else { 56 | logger.error("Did not find rule {}, unable to disable", ruleUID); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/module/JRuleTriggerType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.module; 14 | 15 | import java.util.List; 16 | 17 | import org.eclipse.jdt.annotation.NonNullByDefault; 18 | import org.openhab.core.automation.Visibility; 19 | import org.openhab.core.automation.type.TriggerType; 20 | 21 | /** 22 | * 23 | * @author Arne Seime - Initial Contribution 24 | */ 25 | @NonNullByDefault 26 | public class JRuleTriggerType extends TriggerType { 27 | 28 | public JRuleTriggerType(Class annotation) { 29 | super(JRuleModuleUtil.toTriggerModuleUID(annotation), List.of(), "@" + annotation.getSimpleName(), null, null, 30 | Visibility.VISIBLE, List.of()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/test/JRuleMockedEventBus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.test; 14 | 15 | import java.util.List; 16 | import java.util.concurrent.Executor; 17 | import java.util.concurrent.Executors; 18 | 19 | import org.openhab.automation.jrule.internal.events.JRuleEventSubscriber; 20 | import org.openhab.core.events.Event; 21 | 22 | /** 23 | * The {@link JRuleMockedEventBus} 24 | * 25 | * @author Joseph (Seaside) Hagberg - Initial contribution 26 | */ 27 | public class JRuleMockedEventBus extends JRuleEventSubscriber { 28 | private final Executor executor = Executors.newFixedThreadPool(10); 29 | 30 | public JRuleMockedEventBus() { 31 | } 32 | 33 | public void start() { 34 | startSubscriber(); 35 | } 36 | 37 | public void fire(boolean async, List events) { 38 | if (async) { 39 | events.forEach(event -> executor.execute(() -> super.receive(event))); 40 | } else { 41 | events.forEach(super::receive); 42 | } 43 | } 44 | 45 | public void fire(String eventBusResourceName) { 46 | JRuleTestEventLogParser parser = new JRuleTestEventLogParser(eventBusResourceName); 47 | fire(false, parser.parse()); 48 | } 49 | 50 | public void stop() { 51 | stopSubscriber(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/internal/test/JRuleMockedItemStateChangedEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.test; 14 | 15 | import org.openhab.core.items.events.ItemStateChangedEvent; 16 | import org.openhab.core.types.State; 17 | 18 | /** 19 | * The {@link JRuleMockedItemStateChangedEvent} 20 | * 21 | * @author Joseph (Seaside) Hagberg - Initial contribution 22 | */ 23 | public class JRuleMockedItemStateChangedEvent extends ItemStateChangedEvent { 24 | 25 | protected JRuleMockedItemStateChangedEvent(String topic, String payload, String itemName, State newItemState, 26 | State oldItemState) { 27 | super(topic, payload, itemName, newItemState, oldItemState); 28 | } 29 | 30 | @Override 31 | public String getType() { 32 | return ItemStateChangedEvent.class.getSimpleName(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/JRuleCallGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.Optional; 16 | import java.util.Set; 17 | import java.util.stream.Collectors; 18 | 19 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 20 | import org.openhab.automation.jrule.internal.JRuleUtil; 21 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 22 | import org.openhab.automation.jrule.internal.items.JRuleInternalCallGroupItem; 23 | import org.openhab.automation.jrule.rules.value.JRuleStringListValue; 24 | 25 | /** 26 | * The {@link JRuleCallGroupItem} Items 27 | * 28 | * @author Robert Delbrück - Initial contribution 29 | */ 30 | public interface JRuleCallGroupItem extends JRuleCallItem, JRuleGroupItem { 31 | static JRuleCallGroupItem forName(String itemName) throws JRuleItemNotFoundException { 32 | return JRuleItemRegistry.get(itemName, JRuleInternalCallGroupItem.class); 33 | } 34 | 35 | static Optional forNameOptional(String itemName) { 36 | return Optional.ofNullable(JRuleUtil.forNameWrapExceptionAsNull(() -> forName(itemName))); 37 | } 38 | 39 | default Set memberItems() { 40 | return memberItems(false); 41 | } 42 | 43 | default Set memberItems(boolean recursive) { 44 | return JRuleEventHandler.get().getGroupMemberItems(getName(), recursive).stream() 45 | .map(jRuleItem -> (JRuleCallItem) jRuleItem).collect(Collectors.toSet()); 46 | } 47 | 48 | default void postUpdate(JRuleStringListValue state) { 49 | JRuleEventHandler.get().postUpdate(getName(), state); 50 | JRuleEventHandler.get().getGroupMemberItems(getName(), false).forEach(i -> i.postUncheckedUpdate(state)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/JRuleCallItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.Optional; 16 | 17 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 18 | import org.openhab.automation.jrule.internal.JRuleUtil; 19 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 20 | import org.openhab.automation.jrule.internal.items.JRuleInternalCallItem; 21 | import org.openhab.automation.jrule.rules.value.JRuleStringListValue; 22 | 23 | /** 24 | * The {@link JRuleCallItem} JRule Item 25 | * 26 | * @author Robert Delbrück - Initial contribution 27 | */ 28 | public interface JRuleCallItem extends JRuleItem { 29 | static JRuleCallItem forName(String itemName) throws JRuleItemNotFoundException { 30 | return JRuleItemRegistry.get(itemName, JRuleInternalCallItem.class); 31 | } 32 | 33 | static Optional forNameOptional(String itemName) { 34 | return Optional.ofNullable(JRuleUtil.forNameWrapExceptionAsNull(() -> forName(itemName))); 35 | } 36 | 37 | /** 38 | * Sends a string-list update 39 | * 40 | * @param state update to send 41 | */ 42 | default void postUpdate(JRuleStringListValue state) { 43 | postUncheckedUpdate(state); 44 | } 45 | 46 | default JRuleStringListValue getStateAsStringList() { 47 | return JRuleEventHandler.get().getValue(getName(), JRuleStringListValue.class); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/JRuleColorItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.Optional; 16 | 17 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 18 | import org.openhab.automation.jrule.internal.JRuleUtil; 19 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 20 | import org.openhab.automation.jrule.internal.items.JRuleInternalColorItem; 21 | import org.openhab.automation.jrule.rules.value.*; 22 | 23 | /** 24 | * The {@link JRuleColorItem} JRule Item 25 | * 26 | * @author Robert Delbrück - Initial contribution 27 | */ 28 | public interface JRuleColorItem extends JRuleDimmerItem { 29 | static JRuleColorItem forName(String itemName) throws JRuleItemNotFoundException { 30 | return JRuleItemRegistry.get(itemName, JRuleInternalColorItem.class); 31 | } 32 | 33 | static Optional forNameOptional(String itemName) { 34 | return Optional.ofNullable(JRuleUtil.forNameWrapExceptionAsNull(() -> forName(itemName))); 35 | } 36 | 37 | /** 38 | * Sends a hsb command 39 | * 40 | * @param command command to send. 41 | */ 42 | default void sendCommand(JRuleHsbValue command) { 43 | sendUncheckedCommand(command); 44 | } 45 | 46 | /** 47 | * Sends a hsb update 48 | * 49 | * @param state update to send 50 | */ 51 | default void postUpdate(JRuleHsbValue state) { 52 | postUncheckedUpdate(state); 53 | } 54 | 55 | default JRuleHsbValue getStateAsHsb() { 56 | return JRuleEventHandler.get().getValue(getName(), JRuleHsbValue.class); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/JRuleContactItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.Optional; 16 | 17 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 18 | import org.openhab.automation.jrule.internal.JRuleUtil; 19 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 20 | import org.openhab.automation.jrule.internal.items.JRuleInternalContactItem; 21 | import org.openhab.automation.jrule.rules.value.JRuleOpenClosedValue; 22 | 23 | /** 24 | * The {@link JRuleContactItem} JRule Item 25 | * 26 | * @author Robert Delbrück - Initial contribution 27 | */ 28 | public interface JRuleContactItem extends JRuleItem { 29 | String OPEN = "OPEN"; 30 | String CLOSED = "CLOSED"; 31 | 32 | static JRuleContactItem forName(String itemName) throws JRuleItemNotFoundException { 33 | return JRuleItemRegistry.get(itemName, JRuleInternalContactItem.class); 34 | } 35 | 36 | static Optional forNameOptional(String itemName) { 37 | return Optional.ofNullable(JRuleUtil.forNameWrapExceptionAsNull(() -> forName(itemName))); 38 | } 39 | 40 | /** 41 | * Sends a open/close update 42 | * 43 | * @param state update to send 44 | */ 45 | default void postUpdate(JRuleOpenClosedValue state) { 46 | postUncheckedUpdate(state); 47 | } 48 | 49 | default JRuleOpenClosedValue getStateAsOpenClose() { 50 | return JRuleEventHandler.get().getValue(getName(), JRuleOpenClosedValue.class); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/JRuleImageGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.Optional; 16 | import java.util.Set; 17 | import java.util.stream.Collectors; 18 | 19 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 20 | import org.openhab.automation.jrule.internal.JRuleUtil; 21 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 22 | import org.openhab.automation.jrule.internal.items.JRuleInternalImageGroupItem; 23 | import org.openhab.automation.jrule.rules.value.JRuleRawValue; 24 | 25 | /** 26 | * The {@link JRuleImageGroupItem} Items 27 | * 28 | * @author Robert Delbrück - Initial contribution 29 | */ 30 | public interface JRuleImageGroupItem extends JRuleImageItem, JRuleGroupItem { 31 | static JRuleImageGroupItem forName(String itemName) throws JRuleItemNotFoundException { 32 | return JRuleItemRegistry.get(itemName, JRuleInternalImageGroupItem.class); 33 | } 34 | 35 | static Optional forNameOptional(String itemName) { 36 | return Optional.ofNullable(JRuleUtil.forNameWrapExceptionAsNull(() -> forName(itemName))); 37 | } 38 | 39 | default Set memberItems() { 40 | return memberItems(false); 41 | } 42 | 43 | default Set memberItems(boolean recursive) { 44 | return JRuleEventHandler.get().getGroupMemberItems(getName(), recursive).stream() 45 | .map(jRuleItem -> (JRuleImageItem) jRuleItem).collect(Collectors.toSet()); 46 | } 47 | 48 | default void postUpdate(JRuleRawValue state) { 49 | JRuleEventHandler.get().postUpdate(getName(), state); 50 | JRuleEventHandler.get().getGroupMemberItems(getName(), false).forEach(i -> i.postUncheckedUpdate(state)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/JRuleImageItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.Optional; 16 | 17 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 18 | import org.openhab.automation.jrule.internal.JRuleUtil; 19 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 20 | import org.openhab.automation.jrule.internal.items.JRuleInternalImageItem; 21 | import org.openhab.automation.jrule.rules.value.JRuleRawValue; 22 | 23 | /** 24 | * The {@link JRuleImageItem} JRule Item 25 | * 26 | * @author Robert Delbrück - Initial contribution 27 | */ 28 | public interface JRuleImageItem extends JRuleItem { 29 | static JRuleImageItem forName(String itemName) throws JRuleItemNotFoundException { 30 | return JRuleItemRegistry.get(itemName, JRuleInternalImageItem.class); 31 | } 32 | 33 | static Optional forNameOptional(String itemName) { 34 | return Optional.ofNullable(JRuleUtil.forNameWrapExceptionAsNull(() -> forName(itemName))); 35 | } 36 | 37 | /** 38 | * Sends a on/off update 39 | * 40 | * @param state update to send 41 | */ 42 | default void postUpdate(JRuleRawValue state) { 43 | postUncheckedUpdate(state); 44 | } 45 | 46 | default JRuleRawValue getStateAsRaw() { 47 | return JRuleEventHandler.get().getValue(getName(), JRuleRawValue.class); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/JRuleLocationItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.Optional; 16 | 17 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 18 | import org.openhab.automation.jrule.internal.JRuleUtil; 19 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 20 | import org.openhab.automation.jrule.internal.items.JRuleInternalLocationItem; 21 | import org.openhab.automation.jrule.rules.value.JRulePointValue; 22 | 23 | /** 24 | * The {@link JRuleLocationItem} JRule Item 25 | * 26 | * @author Robert Delbrück - Initial contribution 27 | */ 28 | public interface JRuleLocationItem extends JRuleItem { 29 | static JRuleLocationItem forName(String itemName) throws JRuleItemNotFoundException { 30 | return JRuleItemRegistry.get(itemName, JRuleInternalLocationItem.class); 31 | } 32 | 33 | static Optional forNameOptional(String itemName) { 34 | return Optional.ofNullable(JRuleUtil.forNameWrapExceptionAsNull(() -> forName(itemName))); 35 | } 36 | 37 | /** 38 | * Sends a point command 39 | * 40 | * @param command command to send. 41 | */ 42 | default void sendCommand(JRulePointValue command) { 43 | sendUncheckedCommand(command); 44 | } 45 | 46 | /** 47 | * Sends a point update 48 | * 49 | * @param state update to send 50 | */ 51 | default void postUpdate(JRulePointValue state) { 52 | postUncheckedUpdate(state); 53 | } 54 | 55 | default JRulePointValue getStateAsPoint() { 56 | return JRuleEventHandler.get().getValue(getName(), JRulePointValue.class); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/JRuleUnspecifiedGroupItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.Optional; 16 | import java.util.Set; 17 | import java.util.stream.Collectors; 18 | 19 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 20 | import org.openhab.automation.jrule.internal.JRuleUtil; 21 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 22 | import org.openhab.automation.jrule.internal.items.JRuleInternalUnspecifiedGroupItem; 23 | 24 | /** 25 | * The {@link JRuleUnspecifiedGroupItem} Items 26 | * 27 | * @author Robert Delbrück - Initial contribution 28 | */ 29 | public interface JRuleUnspecifiedGroupItem extends JRuleItem, JRuleGroupItem { 30 | static JRuleUnspecifiedGroupItem forName(String itemName) throws JRuleItemNotFoundException { 31 | return JRuleItemRegistry.get(itemName, JRuleInternalUnspecifiedGroupItem.class); 32 | } 33 | 34 | static Optional forNameOptional(String itemName) { 35 | return Optional.ofNullable(JRuleUtil.forNameWrapExceptionAsNull(() -> forName(itemName))); 36 | } 37 | 38 | default Set memberItems() { 39 | return memberItems(false); 40 | } 41 | 42 | default Set memberItems(boolean recursive) { 43 | return JRuleEventHandler.get().getGroupMemberItems(getName(), recursive).stream().collect(Collectors.toSet()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/metadata/JRuleItemMetadata.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items.metadata; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | /** 19 | * The {@link JRuleItemMetadata} containing all metadata information. 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | public class JRuleItemMetadata { 24 | private final String value; 25 | private final Map configuration; 26 | 27 | public JRuleItemMetadata(String value, Map configuration) { 28 | this.value = value; 29 | this.configuration = configuration; 30 | } 31 | 32 | public JRuleItemMetadata(String value) { 33 | this(value, new HashMap<>()); 34 | } 35 | 36 | public String getValue() { 37 | return value; 38 | } 39 | 40 | public Map getConfiguration() { 41 | return configuration; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return String.format("%s, configuration=%s", value, configuration); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/items/metadata/JRuleMetadataRegistry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items.metadata; 14 | 15 | import java.util.Map; 16 | import java.util.stream.Collectors; 17 | 18 | import org.openhab.core.items.Metadata; 19 | import org.openhab.core.items.MetadataKey; 20 | import org.openhab.core.items.MetadataRegistry; 21 | 22 | /** 23 | * Used to handle metadata from openhab 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | public class JRuleMetadataRegistry { 28 | private final MetadataRegistry metadataRegistry; 29 | 30 | public JRuleMetadataRegistry(MetadataRegistry metadataRegistry) { 31 | this.metadataRegistry = metadataRegistry; 32 | } 33 | 34 | public Map getAllMetadata(String itemName) { 35 | return getAllMetadata(itemName, metadataRegistry); 36 | } 37 | 38 | public static Map getAllMetadata(String itemName, MetadataRegistry metadataRegistry) { 39 | return metadataRegistry.stream().filter(metadata -> metadata.getUID().getItemName().equals(itemName)) 40 | .collect(Collectors.toMap(metadata -> metadata.getUID().getNamespace(), 41 | metadata -> new JRuleItemMetadata(metadata.getValue(), metadata.getConfiguration()))); 42 | } 43 | 44 | public void addMetadata(String namespace, String itemName, JRuleItemMetadata metadata, boolean override) { 45 | MetadataKey key = new MetadataKey(namespace, itemName); 46 | Metadata foundMetadata = metadataRegistry.get(key); 47 | if (foundMetadata != null && override) { 48 | metadataRegistry.remove(key); 49 | } 50 | 51 | metadataRegistry.add(new Metadata(key, metadata.getValue(), metadata.getConfiguration())); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/persistence/JRuleHistoricState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | 14 | package org.openhab.automation.jrule.persistence; 15 | 16 | import java.time.ZonedDateTime; 17 | 18 | import org.openhab.automation.jrule.rules.value.JRuleValue; 19 | 20 | /** 21 | * The {@link JRuleHistoricState} class, which wraps {@link org.openhab.core.persistence.HistoricItem} from openHAB 22 | * core. 23 | * 24 | * @author Robert Delbrück - Initial contribution 25 | */ 26 | public class JRuleHistoricState { 27 | private final JRuleValue value; 28 | private final ZonedDateTime timestamp; 29 | 30 | public JRuleHistoricState(JRuleValue value, ZonedDateTime timestamp) { 31 | this.value = value; 32 | this.timestamp = timestamp; 33 | } 34 | 35 | public JRuleValue getValue() { 36 | return value; 37 | } 38 | 39 | public ZonedDateTime getTimestamp() { 40 | return timestamp; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | /** 16 | * The {@link JRuleCondition} 17 | * 18 | * @author Robert Delbrück 19 | */ 20 | public @interface JRuleCondition { 21 | double gt() default Double.MIN_VALUE; 22 | 23 | double lt() default Double.MIN_VALUE; 24 | 25 | double gte() default Double.MIN_VALUE; 26 | 27 | double lte() default Double.MIN_VALUE; 28 | 29 | String eq() default ""; 30 | 31 | String neq() default ""; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleDebounce.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | import java.time.temporal.ChronoUnit; 20 | 21 | /** 22 | * The {@link JRuleDebounce} type. 23 | * Default value unit is Seconds. 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRuleDebounce { 30 | /** 31 | * Default is seconds. Can be changed via unit(). 32 | * 33 | * @return value as long 34 | */ 35 | long value() default 0; 36 | 37 | /** 38 | * Time unit. Default is seconds. 39 | * 40 | * @return time unit. 41 | */ 42 | ChronoUnit unit() default ChronoUnit.SECONDS; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleDelayed.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | import java.time.temporal.ChronoUnit; 20 | 21 | /** 22 | * The {@link JRuleDelayed} type. 23 | * Default value unit is Seconds. 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRuleDelayed { 30 | /** 31 | * Default is seconds. Can be changed via unit(). 32 | * 33 | * @return value as long 34 | */ 35 | long value() default 0; 36 | 37 | /** 38 | * Time unit. Default is seconds. 39 | * 40 | * @return time unit. 41 | */ 42 | ChronoUnit unit() default ChronoUnit.SECONDS; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleLogName.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleLogName} 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleLogName { 28 | String value() default ""; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleMemberOf.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | /** 16 | * The {@link JRuleMemberOf} 17 | * 18 | * @author Robert Delbrück 19 | */ 20 | public enum JRuleMemberOf { 21 | /** 22 | * Not using memberOf 23 | */ 24 | None, 25 | /** 26 | * Listen on all child items 27 | */ 28 | All, 29 | /** 30 | * Just listen on child groups 31 | */ 32 | Groups, 33 | /** 34 | * Just listen on concrete Items (without groups) 35 | */ 36 | Items 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleName.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleName} 22 | * 23 | * @author Joseph (Seaside) Hagberg - Initial contribution 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleName { 28 | String value() default ""; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRulePrecondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Repeatable; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * The {@link JRulePrecondition} 23 | * 24 | * @author Arne Seime- Initial contribution 25 | */ 26 | @Repeatable(JRulePreconditions.class) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRulePrecondition { 30 | String item() default ""; 31 | 32 | JRuleCondition condition() default @JRuleCondition; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRulePreconditions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRulePreconditions} 22 | * 23 | * @author Arne Seime- Initial contribution 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRulePreconditions { 28 | JRulePrecondition[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | /** 16 | * The {@link JRuleState} JRule State 17 | * 18 | * @author Joseph (Seaside) Hagberg - Initial contribution 19 | */ 20 | public enum JRuleState { 21 | STATE_ON, 22 | STATE_OFF, 23 | UNDEF 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleTag.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleTag} 22 | * 23 | * @author Robert Delbrück 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleTag { 28 | String[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | /** 16 | * The {@link JRuleTrigger} 17 | * 18 | * @author Joseph (Seaside) Hagberg - Initial contribution 19 | */ 20 | public enum JRuleTrigger { 21 | UNDEF, 22 | CHANGED, 23 | RECEIVED_COMMAND, 24 | RECEIVED_UPDATE 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenChannelTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Repeatable; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * The {@link JRuleWhenChannelTriggers} 23 | * 24 | * @author Robert Delbrück 25 | */ 26 | @Repeatable(JRuleWhenChannelTriggers.class) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRuleWhenChannelTrigger { 30 | String channel() default ""; 31 | 32 | String event() default ""; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenChannelTriggers.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleWhenChannelTriggers} 22 | * 23 | * @author Robert Delbrück 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleWhenChannelTriggers { 28 | JRuleWhenChannelTrigger[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenCronTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Repeatable; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * The {@link JRuleWhenCronTriggers} 23 | * 24 | * @author Robert Delbrück 25 | */ 26 | @Repeatable(JRuleWhenCronTriggers.class) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRuleWhenCronTrigger { 30 | String cron() default ""; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenCronTriggers.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleWhenCronTriggers} 22 | * 23 | * @author Robert Delbrück 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleWhenCronTriggers { 28 | JRuleWhenCronTrigger[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenItemChange.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Repeatable; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * The {@link JRuleWhenItemChange} 23 | * 24 | * @author Robert Delbrück 25 | */ 26 | @Repeatable(JRuleWhenItemChanges.class) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRuleWhenItemChange { 30 | String item() default ""; 31 | 32 | String from() default ""; 33 | 34 | String to() default ""; 35 | 36 | JRuleMemberOf memberOf() default JRuleMemberOf.None; 37 | 38 | JRuleCondition condition() default @JRuleCondition; 39 | 40 | /** 41 | * 42 | * @return The condition of the previous state 43 | */ 44 | JRuleCondition previousCondition() default @JRuleCondition; 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenItemChanges.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleWhenItemChanges} 22 | * 23 | * @author Robert Delbrück 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleWhenItemChanges { 28 | JRuleWhenItemChange[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenItemReceivedCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Repeatable; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * The {@link JRuleWhenItemReceivedCommand} 23 | * 24 | * @author Robert Delbrück 25 | */ 26 | @Repeatable(JRuleWhenItemReceivedCommands.class) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRuleWhenItemReceivedCommand { 30 | String item() default ""; 31 | 32 | String command() default ""; 33 | 34 | JRuleMemberOf memberOf() default JRuleMemberOf.None; 35 | 36 | JRuleCondition condition() default @JRuleCondition; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenItemReceivedCommands.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleWhenItemReceivedCommands} 22 | * 23 | * @author Robert Delbrück 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleWhenItemReceivedCommands { 28 | JRuleWhenItemReceivedCommand[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenItemReceivedUpdate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Repeatable; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * The {@link JRuleWhenItemReceivedUpdate} 23 | * 24 | * @author Robert Delbrück 25 | */ 26 | @Repeatable(JRuleWhenItemReceivedUpdates.class) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRuleWhenItemReceivedUpdate { 30 | String item() default ""; 31 | 32 | String state() default ""; 33 | 34 | JRuleMemberOf memberOf() default JRuleMemberOf.None; 35 | 36 | JRuleCondition condition() default @JRuleCondition; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenItemReceivedUpdates.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleWhenItemReceivedUpdates} 22 | * 23 | * @author Robert Delbrück 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleWhenItemReceivedUpdates { 28 | JRuleWhenItemReceivedUpdate[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenThingTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Repeatable; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | import org.openhab.automation.jrule.things.JRuleThingStatus; 22 | 23 | /** 24 | * The {@link JRuleWhenThingTrigger} 25 | * 26 | * @author Robert Delbrück 27 | */ 28 | @Repeatable(JRuleWhenThingTriggers.class) 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target({ ElementType.METHOD }) 31 | public @interface JRuleWhenThingTrigger { 32 | String thing() default ""; 33 | 34 | JRuleThingStatus from() default JRuleThingStatus.THING_UNKNOWN; 35 | 36 | JRuleThingStatus to() default JRuleThingStatus.THING_UNKNOWN; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenThingTriggers.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleWhenThingTriggers} 22 | * 23 | * @author Robert Delbrück 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleWhenThingTriggers { 28 | JRuleWhenThingTrigger[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenTimeTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Repeatable; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * The {@link JRuleWhenTimeTrigger} 23 | * 24 | * @author Robert Delbrück 25 | */ 26 | @Repeatable(JRuleWhenTimeTriggers.class) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target({ ElementType.METHOD }) 29 | public @interface JRuleWhenTimeTrigger { 30 | int hours() default -1; 31 | 32 | int minutes() default -1; 33 | 34 | int seconds() default -1; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/JRuleWhenTimeTriggers.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * The {@link JRuleWhenTimeTriggers} 22 | * 23 | * @author Robert Delbrück 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target({ ElementType.METHOD }) 27 | public @interface JRuleWhenTimeTriggers { 28 | JRuleWhenTimeTrigger[] value(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/event/JRuleChannelEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.event; 14 | 15 | /** 16 | * The {@link JRuleChannelEvent} 17 | * 18 | * @author Robert Delbrück 19 | */ 20 | public class JRuleChannelEvent extends JRuleEvent { 21 | private String channel; 22 | private String event; 23 | 24 | public String getChannel() { 25 | return channel; 26 | } 27 | 28 | public String getEvent() { 29 | return event; 30 | } 31 | 32 | public JRuleChannelEvent(String channel, String event) { 33 | this.channel = channel; 34 | this.event = event; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return String.format("JRuleEvent [channel=%s]", channel); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/event/JRuleEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.event; 14 | 15 | /** 16 | * The {@link JRuleEvent} 17 | * 18 | * @author Joseph (Seaside) Hagberg - Initial contribution 19 | */ 20 | public abstract class JRuleEvent { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/event/JRuleThingEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.event; 14 | 15 | /** 16 | * The {@link JRuleThingEvent} 17 | * 18 | * @author Robert Delbrück 19 | */ 20 | public class JRuleThingEvent extends JRuleEvent { 21 | private String thing; 22 | private String status; 23 | 24 | private String oldStatus; 25 | 26 | public String getThing() { 27 | return thing; 28 | } 29 | 30 | public String getStatus() { 31 | return status; 32 | } 33 | 34 | public String getOldStatus() { 35 | return oldStatus; 36 | } 37 | 38 | public JRuleThingEvent(String thing, String status, String oldStatus) { 39 | this.thing = thing; 40 | this.status = status; 41 | this.oldStatus = oldStatus; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "JRuleThingEvent{" + "thing='" + thing + '\'' + ", status='" + status + '\'' + ", oldStatus='" 47 | + oldStatus + '\'' + '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/event/JRuleTimerEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.event; 14 | 15 | /** 16 | * The {@link JRuleTimerEvent} 17 | * 18 | * @author Robert Delbrück 19 | */ 20 | public class JRuleTimerEvent extends JRuleEvent { 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleDateTimeValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import java.time.ZoneId; 16 | import java.time.ZonedDateTime; 17 | import java.util.Date; 18 | import java.util.Objects; 19 | 20 | import org.openhab.core.library.types.DateTimeType; 21 | import org.openhab.core.types.State; 22 | 23 | /** 24 | * The {@link JRuleDateTimeValue} 25 | * 26 | * @author Joseph (Seaside) Hagberg - Initial contribution 27 | */ 28 | public class JRuleDateTimeValue extends JRuleValueBase implements JRuleValue { 29 | private final DateTimeType ohType; 30 | 31 | public JRuleDateTimeValue(ZonedDateTime value) { 32 | this.ohType = new DateTimeType(value); 33 | } 34 | 35 | public JRuleDateTimeValue(String fullString) { 36 | this.ohType = new DateTimeType(fullString); 37 | } 38 | 39 | public JRuleDateTimeValue(Date date) { 40 | this.ohType = new DateTimeType(ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault())); 41 | } 42 | 43 | public ZonedDateTime getValue() { 44 | return ohType.getZonedDateTime(); 45 | } 46 | 47 | @Override 48 | protected State getOhType() { 49 | return ohType; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (this == o) 55 | return true; 56 | if (o == null || getClass() != o.getClass()) 57 | return false; 58 | JRuleDateTimeValue that = (JRuleDateTimeValue) o; 59 | return ohType.equals(that.ohType); 60 | } 61 | 62 | @Override 63 | public int hashCode() { 64 | return Objects.hash(ohType); 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return ohType.toString(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleIncreaseDecreaseValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.library.types.IncreaseDecreaseType; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRuleIncreaseDecreaseValue} JRule Command 21 | * 22 | * @author Timo Litzius - Initial contribution 23 | */ 24 | public enum JRuleIncreaseDecreaseValue implements JRuleValue { 25 | INCREASE(IncreaseDecreaseType.INCREASE), 26 | DECREASE(IncreaseDecreaseType.DECREASE); 27 | 28 | private final IncreaseDecreaseType ohType; 29 | 30 | JRuleIncreaseDecreaseValue(IncreaseDecreaseType ohType) { 31 | this.ohType = ohType; 32 | } 33 | 34 | public static JRuleIncreaseDecreaseValue getValueFromString(String value) { 35 | if (value.equals("INCREASE")) { 36 | return INCREASE; 37 | } 38 | if (value.equals("DECREASE")) { 39 | return DECREASE; 40 | } 41 | return null; 42 | } 43 | 44 | @Override 45 | public String stringValue() { 46 | return name(); 47 | } 48 | 49 | @Override 50 | public Command toOhCommand() { 51 | return this.ohType; 52 | } 53 | 54 | @Override 55 | public State toOhState() { 56 | throw new IllegalStateException("not a state type"); 57 | } 58 | 59 | @Override 60 | public T as(Class target) { 61 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return ohType.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleNextPreviousValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.library.types.NextPreviousType; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRuleNextPreviousValue} JRule Command 21 | * 22 | * @author Robert Delbrück - Initial contribution 23 | */ 24 | public enum JRuleNextPreviousValue implements JRuleValue { 25 | NEXT(NextPreviousType.NEXT), 26 | PREVIOUS(NextPreviousType.PREVIOUS); 27 | 28 | private final NextPreviousType ohType; 29 | 30 | JRuleNextPreviousValue(NextPreviousType ohType) { 31 | this.ohType = ohType; 32 | } 33 | 34 | public static JRuleNextPreviousValue getValueFromString(String value) { 35 | if (value.equals(NEXT.name())) { 36 | return NEXT; 37 | } 38 | if (value.equals(PREVIOUS.name())) { 39 | return PREVIOUS; 40 | } 41 | return null; 42 | } 43 | 44 | @Override 45 | public String stringValue() { 46 | return name(); 47 | } 48 | 49 | @Override 50 | public Command toOhCommand() { 51 | return this.ohType; 52 | } 53 | 54 | @Override 55 | public State toOhState() { 56 | throw new IllegalStateException("not a state type"); 57 | } 58 | 59 | @Override 60 | public T as(Class target) { 61 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return ohType.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleOnOffValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.library.types.OnOffType; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRuleOnOffValue} JRule Command 21 | * 22 | * @author Joseph (Seaside) Hagberg - Initial contribution 23 | */ 24 | public enum JRuleOnOffValue implements JRuleValue { 25 | ON(OnOffType.ON), 26 | OFF(OnOffType.OFF); 27 | 28 | private final OnOffType ohType; 29 | 30 | JRuleOnOffValue(OnOffType ohType) { 31 | this.ohType = ohType; 32 | } 33 | 34 | public static JRuleOnOffValue getValueFromString(String value) { 35 | return switch (value) { 36 | case "ON" -> ON; 37 | case "OFF" -> OFF; 38 | default -> null; 39 | }; 40 | } 41 | 42 | public static JRuleValue valueOf(boolean command) { 43 | return command ? ON : OFF; 44 | } 45 | 46 | @Override 47 | public String stringValue() { 48 | return name(); 49 | } 50 | 51 | @Override 52 | public Command toOhCommand() { 53 | return this.ohType; 54 | } 55 | 56 | @Override 57 | public State toOhState() { 58 | return this.ohType; 59 | } 60 | 61 | @Override 62 | public T as(Class target) { 63 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return ohType.toString(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleOpenClosedValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.library.types.OpenClosedType; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRuleOpenClosedValue} JRule Command 21 | * 22 | * @author Timo Litzius - Initial contribution 23 | */ 24 | public enum JRuleOpenClosedValue implements JRuleValue { 25 | OPEN(OpenClosedType.OPEN), 26 | CLOSED(OpenClosedType.CLOSED); 27 | 28 | private final OpenClosedType ohType; 29 | 30 | JRuleOpenClosedValue(OpenClosedType ohType) { 31 | this.ohType = ohType; 32 | } 33 | 34 | public static JRuleOpenClosedValue getValueFromString(String value) { 35 | if (value.equals("OPEN")) { 36 | return OPEN; 37 | } 38 | if (value.equals("CLOSED")) { 39 | return CLOSED; 40 | } 41 | return null; 42 | } 43 | 44 | public static JRuleValue valueOf(boolean command) { 45 | return command ? OPEN : CLOSED; 46 | } 47 | 48 | @Override 49 | public String stringValue() { 50 | return name(); 51 | } 52 | 53 | @Override 54 | public Command toOhCommand() { 55 | return this.ohType; 56 | } 57 | 58 | @Override 59 | public State toOhState() { 60 | return this.ohType; 61 | } 62 | 63 | @Override 64 | public T as(Class target) { 65 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return ohType.toString(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRulePlayPauseValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.library.types.PlayPauseType; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRulePlayPauseValue} JRule Command 21 | * 22 | * @author Joseph (Seaside) Hagberg - Initial contribution 23 | */ 24 | public enum JRulePlayPauseValue implements JRuleValue { 25 | PLAY(PlayPauseType.PLAY), 26 | PAUSE(PlayPauseType.PAUSE); 27 | 28 | private final PlayPauseType ohType; 29 | 30 | JRulePlayPauseValue(PlayPauseType ohType) { 31 | this.ohType = ohType; 32 | } 33 | 34 | public static JRulePlayPauseValue getValueFromString(String value) { 35 | if (value.equals(PLAY.name())) { 36 | return PLAY; 37 | } 38 | if (value.equals(PAUSE.name())) { 39 | return PAUSE; 40 | } 41 | return null; 42 | } 43 | 44 | public static JRuleValue valueOf(boolean command) { 45 | return command ? PLAY : PAUSE; 46 | } 47 | 48 | @Override 49 | public String stringValue() { 50 | return name(); 51 | } 52 | 53 | @Override 54 | public Command toOhCommand() { 55 | return this.ohType; 56 | } 57 | 58 | @Override 59 | public State toOhState() { 60 | return this.ohType; 61 | } 62 | 63 | @Override 64 | public T as(Class target) { 65 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return ohType.toString(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleRawValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import java.util.Objects; 16 | 17 | import org.openhab.core.library.types.RawType; 18 | import org.openhab.core.types.State; 19 | 20 | /** 21 | * The {@link JRuleRawValue} JRule Command 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class JRuleRawValue extends JRuleValueBase implements JRuleValue { 26 | private final RawType ohType; 27 | 28 | public JRuleRawValue(String mimeType, byte[] data) { 29 | this.ohType = new RawType(data, mimeType); 30 | } 31 | 32 | public JRuleRawValue(String value) { 33 | this.ohType = RawType.valueOf(value); 34 | } 35 | 36 | public String getMimeType() { 37 | return this.ohType.getMimeType(); 38 | } 39 | 40 | public byte[] getData() { 41 | return this.ohType.getBytes(); 42 | } 43 | 44 | @Override 45 | public State getOhType() { 46 | return ohType; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object o) { 51 | if (this == o) 52 | return true; 53 | if (o == null || getClass() != o.getClass()) 54 | return false; 55 | JRuleRawValue that = (JRuleRawValue) o; 56 | return ohType.equals(that.ohType); 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return Objects.hash(ohType); 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return ohType.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleRefreshValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.types.Command; 16 | import org.openhab.core.types.RefreshType; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRuleRefreshValue} JRule Command 21 | * 22 | * @author Robert Delbrück - Initial contribution 23 | */ 24 | public enum JRuleRefreshValue implements JRuleValue { 25 | REFRESH(RefreshType.REFRESH); 26 | 27 | private final RefreshType ohType; 28 | 29 | JRuleRefreshValue(RefreshType ohType) { 30 | this.ohType = ohType; 31 | } 32 | 33 | public static JRuleRefreshValue getValueFromString(String value) { 34 | return switch (value) { 35 | case "REFRESH" -> REFRESH; 36 | default -> null; 37 | }; 38 | } 39 | 40 | @Override 41 | public String stringValue() { 42 | return name(); 43 | } 44 | 45 | @Override 46 | public Command toOhCommand() { 47 | return this.ohType; 48 | } 49 | 50 | @Override 51 | public State toOhState() { 52 | throw new IllegalStateException("not a state type"); 53 | } 54 | 55 | @Override 56 | public T as(Class target) { 57 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return ohType.toString(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleRewindFastforwardValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.library.types.RewindFastforwardType; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRuleRewindFastforwardValue} JRule Command 21 | * 22 | * @author Robert Delbrück - Initial contribution 23 | */ 24 | public enum JRuleRewindFastforwardValue implements JRuleValue { 25 | REWIND(RewindFastforwardType.REWIND), 26 | FASTFORWARD(RewindFastforwardType.FASTFORWARD); 27 | 28 | private final RewindFastforwardType ohType; 29 | 30 | JRuleRewindFastforwardValue(RewindFastforwardType ohType) { 31 | this.ohType = ohType; 32 | } 33 | 34 | public static JRuleRewindFastforwardValue getValueFromString(String value) { 35 | if (value.equals(REWIND.name())) { 36 | return REWIND; 37 | } 38 | if (value.equals(FASTFORWARD.name())) { 39 | return FASTFORWARD; 40 | } 41 | return null; 42 | } 43 | 44 | @Override 45 | public String stringValue() { 46 | return name(); 47 | } 48 | 49 | @Override 50 | public Command toOhCommand() { 51 | return this.ohType; 52 | } 53 | 54 | @Override 55 | public State toOhState() { 56 | return this.ohType; 57 | } 58 | 59 | @Override 60 | public T as(Class target) { 61 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return ohType.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleStopMoveValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.library.types.StopMoveType; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRuleStopMoveValue} JRule Command 21 | * 22 | * @author Timo Litzius- Initial contribution 23 | */ 24 | public enum JRuleStopMoveValue implements JRuleValue { 25 | STOP(StopMoveType.STOP), 26 | MOVE(StopMoveType.MOVE); 27 | 28 | private final StopMoveType ohType; 29 | 30 | JRuleStopMoveValue(StopMoveType ohType) { 31 | this.ohType = ohType; 32 | } 33 | 34 | public static JRuleStopMoveValue getValueFromString(String value) { 35 | if (value.equals("STOP")) { 36 | return STOP; 37 | } 38 | if (value.equals("MOVE")) { 39 | return MOVE; 40 | } 41 | return null; 42 | } 43 | 44 | @Override 45 | public String stringValue() { 46 | return name(); 47 | } 48 | 49 | @Override 50 | public Command toOhCommand() { 51 | return this.ohType; 52 | } 53 | 54 | @Override 55 | public State toOhState() { 56 | throw new IllegalStateException("not a state type"); 57 | } 58 | 59 | @Override 60 | public T as(Class target) { 61 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return ohType.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleStringListValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import java.util.List; 16 | import java.util.Objects; 17 | 18 | import org.openhab.core.library.types.StringListType; 19 | import org.openhab.core.types.State; 20 | 21 | /** 22 | * The {@link JRuleStringListValue} JRule Command 23 | * 24 | * @author Robert Delbrück - Initial contribution 25 | */ 26 | public class JRuleStringListValue extends JRuleValueBase implements JRuleValue { 27 | private final StringListType ohType; 28 | 29 | public JRuleStringListValue(String value) { 30 | this.ohType = new StringListType(value); 31 | } 32 | 33 | public JRuleStringListValue(List value) { 34 | this.ohType = new StringListType(value); 35 | } 36 | 37 | public JRuleStringListValue(String... value) { 38 | this.ohType = new StringListType(value); 39 | } 40 | 41 | public String getValue(int index) { 42 | return this.ohType.getValue(index); 43 | } 44 | 45 | @Override 46 | public State getOhType() { 47 | return ohType; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) 53 | return true; 54 | if (o == null || getClass() != o.getClass()) 55 | return false; 56 | JRuleStringListValue that = (JRuleStringListValue) o; 57 | return ohType.equals(that.ohType); 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return Objects.hash(ohType); 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return ohType.toString(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleStringValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import java.util.Objects; 16 | 17 | import org.openhab.core.library.types.StringType; 18 | import org.openhab.core.types.State; 19 | 20 | /** 21 | * The {@link JRuleStringValue} JRule Command 22 | * 23 | * @author Robert Delbrück - Initial contribution 24 | */ 25 | public class JRuleStringValue extends JRuleValueBase implements JRuleValue { 26 | private final StringType ohType; 27 | 28 | public JRuleStringValue(String value) { 29 | this.ohType = new StringType(value); 30 | } 31 | 32 | @Override 33 | public State getOhType() { 34 | return ohType; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object o) { 39 | if (this == o) 40 | return true; 41 | if (o == null || getClass() != o.getClass()) 42 | return false; 43 | JRuleStringValue that = (JRuleStringValue) o; 44 | return ohType.equals(that.ohType); 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | return Objects.hash(ohType); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return ohType.toString(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleUpDownValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.library.types.UpDownType; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | 19 | /** 20 | * The {@link JRuleUpDownValue} JRule Command 21 | * 22 | * @author Timo Litzius- Initial contribution 23 | */ 24 | public enum JRuleUpDownValue implements JRuleValue { 25 | UP(UpDownType.UP), 26 | DOWN(UpDownType.DOWN); 27 | 28 | private final UpDownType ohType; 29 | 30 | JRuleUpDownValue(UpDownType ohType) { 31 | this.ohType = ohType; 32 | } 33 | 34 | public static JRuleUpDownValue getValueFromString(String value) { 35 | if (value.equals("UP")) { 36 | return UP; 37 | } 38 | if (value.equals("DOWN")) { 39 | return DOWN; 40 | } 41 | return null; 42 | } 43 | 44 | public static JRuleValue valueOf(boolean command) { 45 | return command ? UP : DOWN; 46 | } 47 | 48 | @Override 49 | public String stringValue() { 50 | return name(); 51 | } 52 | 53 | @Override 54 | public Command toOhCommand() { 55 | return this.ohType; 56 | } 57 | 58 | @Override 59 | public State toOhState() { 60 | return this.ohType; 61 | } 62 | 63 | @Override 64 | public T as(Class target) { 65 | throw new IllegalStateException("cannot cast to '%s'".formatted(target)); 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return ohType.toString(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.core.types.Command; 16 | import org.openhab.core.types.State; 17 | 18 | /** 19 | * The {@link JRuleValue} JRule Command 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | public interface JRuleValue { 24 | String toString(); 25 | 26 | String stringValue(); 27 | 28 | Command toOhCommand(); 29 | 30 | State toOhState(); 31 | 32 | T as(Class target); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/rules/value/JRuleValueBase.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.openhab.automation.jrule.internal.handler.JRuleEventHandler; 16 | import org.openhab.core.types.Command; 17 | import org.openhab.core.types.State; 18 | import org.openhab.core.types.Type; 19 | 20 | /** 21 | * The {@link JRuleValueBase}. Base for all JRuleValues (sadly except enums) 22 | * 23 | * @author Robert Delbrück - Initial contribution 24 | */ 25 | public abstract class JRuleValueBase implements JRuleValue { 26 | @Override 27 | public String stringValue() { 28 | return this.getOhType().toFullString(); 29 | } 30 | 31 | @Override 32 | public Command toOhCommand() { 33 | Type ohType = this.getOhType(); 34 | if (ohType instanceof Command) { 35 | return (Command) ohType; 36 | } 37 | throw new IllegalStateException("not a command type"); 38 | } 39 | 40 | @Override 41 | public State toOhState() { 42 | Type ohType = this.getOhType(); 43 | if (ohType instanceof State) { 44 | return (State) ohType; 45 | } 46 | throw new IllegalStateException("not a state type"); 47 | } 48 | 49 | protected abstract Type getOhType(); 50 | 51 | @Override 52 | public T as(Class target) { 53 | // noinspection unchecked 54 | return (T) JRuleEventHandler.get().toValue(toOhState().as(JRuleEventHandler.mapJRuleToOhType(target))); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/things/JRuleAbstractThing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.things; 14 | 15 | import java.util.List; 16 | import java.util.Set; 17 | 18 | import org.openhab.automation.jrule.internal.handler.JRuleThingHandler; 19 | import org.openhab.automation.jrule.items.JRuleItem; 20 | 21 | /** 22 | * The {@link JRuleAbstractThing} represents a thing that is either a bridge, a bridged (sub thing of a bridge) or a 23 | * standalone thing not in need of a bridge 24 | * 25 | * @author Arne Seime - Initial contribution 26 | */ 27 | public abstract class JRuleAbstractThing { 28 | private String thingUID; 29 | 30 | protected JRuleAbstractThing(String thingUID) { 31 | this.thingUID = thingUID; 32 | } 33 | 34 | public String getThingUID() { 35 | return thingUID; 36 | } 37 | 38 | public abstract String getLabel(); 39 | 40 | public JRuleThingStatus getStatus() { 41 | return JRuleThingHandler.get().getStatus(thingUID); 42 | } 43 | 44 | public void disable() { 45 | JRuleThingHandler.get().disable(thingUID); 46 | } 47 | 48 | public void enable() { 49 | JRuleThingHandler.get().enable(thingUID); 50 | } 51 | 52 | public void restart() { 53 | disable(); 54 | enable(); 55 | } 56 | 57 | public List getChannels() { 58 | return JRuleThingHandler.get().getChannels(thingUID); 59 | } 60 | 61 | public Set getLinkedItems(JRuleChannel channel) { 62 | return JRuleThingHandler.get().getLinkedItems(channel); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/things/JRuleBridgeThing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.things; 14 | 15 | import java.util.List; 16 | import java.util.stream.Collectors; 17 | 18 | /** 19 | * The {@link JRuleBridgeThing} thing represents a bridge thing 20 | * 21 | * @author Arne Seime - Initial contribution 22 | */ 23 | public abstract class JRuleBridgeThing extends JRuleAbstractThing { 24 | 25 | public JRuleBridgeThing(String thingUID) { 26 | super(thingUID); 27 | } 28 | 29 | public abstract List getSubThingUIDs(); 30 | 31 | public List getChildThings() { 32 | return getSubThingUIDs().stream().map(e -> JRuleThingRegistry.get(e, JRuleSubThing.class)) 33 | .collect(Collectors.toList()); 34 | } 35 | 36 | public static JRuleBridgeThing forName(String thingUID) { 37 | return JRuleThingRegistry.get(thingUID, JRuleBridgeThing.class); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/things/JRuleChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.things; 14 | 15 | /** 16 | * The {@link JRuleChannel} represents a Thing channel, possibly linked to an Item. 17 | * 18 | * @author Arne Seime - Initial contribution 19 | */ 20 | public class JRuleChannel { 21 | private String channelUID; 22 | 23 | public JRuleChannel(String channelUID) { 24 | this.channelUID = channelUID; 25 | } 26 | 27 | public String getChannelUID() { 28 | return channelUID; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/things/JRuleStandaloneThing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.things; 14 | 15 | /** 16 | * The {@link JRuleStandaloneThing} thing represents a thing that is standalone (not a bridge nor connected to a bridge) 17 | * 18 | * @author Arne Seime - Initial contribution 19 | */ 20 | public abstract class JRuleStandaloneThing extends JRuleAbstractThing { 21 | public JRuleStandaloneThing(String thingUID) { 22 | super(thingUID); 23 | } 24 | 25 | public static JRuleStandaloneThing forName(String thingUID) { 26 | return JRuleThingRegistry.get(thingUID, JRuleStandaloneThing.class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/things/JRuleSubThing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.things; 14 | 15 | /** 16 | * The {@link JRuleSubThing} thing represents a thing that is connected to a bridge 17 | * 18 | * @author Arne Seime - Initial contribution 19 | */ 20 | public abstract class JRuleSubThing extends JRuleAbstractThing { 21 | 22 | public abstract String getBridgeUID(); 23 | 24 | public static JRuleSubThing forName(String thingUID) { 25 | return JRuleThingRegistry.get(thingUID, JRuleSubThing.class); 26 | } 27 | 28 | public JRuleSubThing(String thingUID) { 29 | super(thingUID); 30 | } 31 | 32 | public JRuleBridgeThing getBridge() { 33 | return JRuleThingRegistry.get(getBridgeUID(), JRuleBridgeThing.class); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/things/JRuleThingRegistry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.things; 14 | 15 | import java.lang.reflect.Constructor; 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | /** 20 | * The {@link JRuleThingRegistry} Local registry of JRuleThings 21 | * 22 | * @author Arne Seime - Initial contribution 23 | */ 24 | 25 | public class JRuleThingRegistry { 26 | private static final Map thingRegistry = new HashMap<>(); 27 | 28 | public static void clear() { 29 | thingRegistry.clear(); 30 | } 31 | 32 | public static T get(String thingName, Class jRuleThingClass) { 33 | JRuleAbstractThing jRuleThing = thingRegistry.get(thingName); 34 | if (jRuleThing == null) { 35 | try { 36 | Constructor constructor = jRuleThingClass.getDeclaredConstructor(String.class); 37 | constructor.setAccessible(true); 38 | jRuleThing = (JRuleAbstractThing) constructor.newInstance(thingName); 39 | thingRegistry.put(thingName, jRuleThing); 40 | } catch (Exception ex) { 41 | throw new RuntimeException(ex); 42 | } 43 | } 44 | return (T) jRuleThing; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/things/JRuleThingStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.things; 14 | 15 | /** 16 | * The {@link JRuleThingStatus} types of status 17 | * 18 | * @author Arne Seime - Initial contribution 19 | */ 20 | public enum JRuleThingStatus { 21 | UNINITIALIZED, 22 | INITIALIZING, 23 | UNKNOWN, 24 | ONLINE, 25 | OFFLINE, 26 | REMOVING, 27 | REMOVED, 28 | THING_UNKNOWN; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/trigger/JRuleContactTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.trigger; 14 | 15 | /** 16 | * The {@link JRuleSwitchTrigger} Items 17 | * 18 | * @author Joseph (Seaside) Hagberg - Initial contribution 19 | */ 20 | public interface JRuleContactTrigger { 21 | String OPEN = "OPEN"; 22 | String CLOSED = "CLOSED"; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/openhab/automation/jrule/trigger/JRulePlayerTrigger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.trigger; 14 | 15 | /** 16 | * The {@link JRulePlayerTrigger} Items 17 | * 18 | * @author Gerhard Riegler - Initial contribution 19 | */ 20 | public interface JRulePlayerTrigger { 21 | String PLAY = "PLAY"; 22 | String PAUSE = "PAUSE"; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/resources/OH-INF/addon/addon.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | automation 7 | Java Rules Engine 8 | 9 | The JRule Automation Addon enables openHAB rule development using plain old Java. 10 | 11 | org.openhab.automation.jrule 12 | 13 | -------------------------------------------------------------------------------- /src/main/resources/jrule.conf.default: -------------------------------------------------------------------------------- 1 | ## Prefix to be used when generating items, files 2 | #org.openhab.automation.jrule.itemprefix=_ 3 | 4 | ## Working directory 5 | #org.openhab.automation.jrule.directory=/etc/openhab/automation/jrule 6 | 7 | ## Run rules in a separate threadpool 8 | #org.openhab.automation.jrule.engine.executors.enable=true 9 | 10 | ## Minimum number of threads 11 | #org.openhab.automation.jrule.engine.executors.min=2 12 | 13 | ## Maximum number of threads 14 | #org.openhab.automation.jrule.engine.executors.max=10 15 | 16 | ## Number of seconds before jrule engine is initialized 17 | #org.openhab.automation.jrule.engine.initdelay=5 18 | 19 | ## Number of seconds before rules from jar and source files are loaded 20 | #org.openhab.automation.jrule.engine.rulesdelay=2 21 | 22 | ## Number of seconds to wait after an item change or Java rule change before 23 | ## recompilation and reloading starts 24 | #org.openhab.automation.jrule.engine.itemsrecompilationdelay=5 25 | 26 | ## Package name for rules classes 27 | #org.openhab.automation.jrule.package=org.openhab.automation.jrule.rules.user 28 | 29 | ## Default location for rule source files located under $org.openhab.automation.jrule.directory/rules/ 30 | #org.openhab.automation.jrule.rules.directory=org/openhab/automation/jrule/rules/user 31 | -------------------------------------------------------------------------------- /src/main/resources/templates/CommonLicense.ftlh: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | -------------------------------------------------------------------------------- /src/main/resources/templates/actions/Action.ftlh: -------------------------------------------------------------------------------- 1 | <#include "../CommonLicense.ftlh"> 2 | 3 | package ${action.package}; 4 | 5 | import org.openhab.automation.jrule.actions.${action.parentClass}; 6 | import java.util.Objects; 7 | <#list action.imports as import> 8 | import ${import}; 9 | 10 | 11 | <#include "ActionJavadoc.ftlh"> 12 | public class ${action.class} extends ${action.parentClass} { 13 | <#include "ActionConstructor.ftlh"> 14 | <#list action.methods as method> 15 | <#include "ActionMethod.ftlh"> 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/templates/actions/ActionConstructor.ftlh: -------------------------------------------------------------------------------- 1 | public ${action.class}(String scope, String thingUid) { 2 | super(scope, thingUid); 3 | } 4 | 5 | -------------------------------------------------------------------------------- /src/main/resources/templates/actions/ActionJavadoc.ftlh: -------------------------------------------------------------------------------- 1 | /** 2 | * Automatically Generated Class for Action ${action.name} - DO NOT EDIT! 3 | *
4 | * All functions of ${action.id} from Java Class {@link ${action.type}} 5 | * 6 | * @author Robert Delbrück - Initial contribution 7 | */ 8 | -------------------------------------------------------------------------------- /src/main/resources/templates/actions/ActionMethod.ftlh: -------------------------------------------------------------------------------- 1 | /** 2 | * ${action.id}: ${method.name} 3 | <#list method.args as arg> 4 | * @${arg.name}: ${arg.name} of ${arg.type} 5 | 6 | <#if method.hasReturnType == true>* @return ${method.returnType} 7 | */ 8 | public ${method.returnType} ${method.name}(<#list method.args as arg>${arg.type} ${arg.name}<#sep>, ) { 9 | <#if method.hasReturnType == true>return (${method.returnType}) super.invokeMethod("${method.name}", new Class[]{<#list method.args as arg>${arg.reflectionType}.class<#sep>, }<#if method.args?size != 0>, <#list method.args as arg>${arg.name}<#sep>, ); 10 | } -------------------------------------------------------------------------------- /src/main/resources/templates/actions/Actions.ftlh: -------------------------------------------------------------------------------- 1 | <#include "../CommonLicense.ftlh"> 2 | 3 | package ${packageName}; 4 | 5 | <#list actions as action> 6 | import org.openhab.automation.jrule.generated.actions.${action.class}; 7 | 8 | 9 | /** 10 | * Automatically Generated Class for Actions - DO NOT EDIT! 11 | *
12 | * Includes all available actions for all things 13 | * 14 | * @author Robert Delbrück - Initial contribution 15 | */ 16 | public class JRuleActions { 17 | <#list actions as action> 18 | /** 19 | * thingUid: ${action.id} 20 | */ 21 | public static final ${action.class} ${action.name}; 22 | 23 | 24 | static { 25 | <#list actions as action> 26 | ${action.name} = new ${action.class}("${action.scope}", "${action.id}"); 27 | 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/main/resources/templates/items/CommonJavadoc.ftlh: -------------------------------------------------------------------------------- 1 | /** 2 | * Automatically Generated Class for Item ${item.name} - DO NOT EDIT! 3 | * 4 | * @author Joseph (Seaside) Hagberg - Initial contribution 5 | * @author Timo Litzius - Contribution 6 | * @author Arne Seime - Refactoring 7 | */ 8 | -------------------------------------------------------------------------------- /src/main/resources/templates/items/CommonMethods.ftlh: -------------------------------------------------------------------------------- 1 | public static final String ITEM = "${item.name}"; 2 | 3 | public static final String LABEL = "<#if item.label??>${item.label}"; 4 | 5 | public static final String TYPE = "${item.type}"; 6 | 7 | public static final String ID = "${item.id}"; 8 | 9 | @Override 10 | public String getLabel() { 11 | return LABEL; 12 | } 13 | 14 | @Override 15 | public String getType() { 16 | return TYPE; 17 | } 18 | 19 | @Override 20 | public String getId() { 21 | return ID; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "'"+LABEL+"'/"+ITEM+"/"+TYPE; 27 | } 28 | 29 | public ${item.class}(String name) { 30 | super(name); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/templates/items/ItemNames.ftlh: -------------------------------------------------------------------------------- 1 | <#include "../CommonLicense.ftlh"> 2 | 3 | package ${packageName}; 4 | 5 | /** 6 | * Automatically Generated Enum for ItemNames - DO NOT EDIT! 7 | * 8 | * @author Robert Delbrück - Initial 9 | */ 10 | public class JRuleItemNames { 11 | <#list itemNames as itemName> 12 | /** 13 | * Name: ${itemName.name} 14 | *
15 | * Type: ${itemName.type} 16 | *
17 | * Label: ${(itemName.label)!} 18 | *
19 | * Tags: ${itemName.tags} 20 | *
21 | * Metadata: ${itemName.metadata} 22 | */ 23 | public static final String ${itemName.name} = "${itemName.name}"; 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/main/resources/templates/items/Items.ftlh: -------------------------------------------------------------------------------- 1 | <#include "../CommonLicense.ftlh"> 2 | 3 | package ${packageName}; 4 | 5 | import org.openhab.automation.jrule.items.JRuleItemRegistry; 6 | import org.openhab.automation.jrule.exception.JRuleItemNotFoundException; 7 | 8 | <#list items as item> 9 | import org.openhab.automation.jrule.internal.items.${item.internalClass}; 10 | import org.openhab.automation.jrule.items.${item.interfaceClass}; 11 | 12 | 13 | /** 14 | * Automatically Generated Class for Items - DO NOT EDIT! 15 | * 16 | * @author Arne Seime - Refactoring 17 | * @author Robert Delbrück - Refactoring 18 | */ 19 | public class JRuleItems { 20 | 21 | 22 | 23 | <#list items as item> 24 | /** 25 | * Name: ${item.name} 26 | *
27 | * Type: ${item.type} 28 | *
29 | * Label: ${(item.label)!} 30 | *
31 | * Tags: ${item.tags} 32 | *
33 | * Metadata: ${item.metadata} 34 | */ 35 | public static ${item.interfaceClass} ${item.name}; 36 | 37 | 38 | 39 | static { 40 | loadItems(); 41 | } 42 | 43 | /** 44 | * Need this method for testing 45 | */ 46 | private static void loadItems() throws JRuleItemNotFoundException { 47 | <#list items as item> 48 | ${item.name} = JRuleItemRegistry.get("${item.name}", ${item.internalClass}.class); 49 | 50 | 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/main/resources/templates/things/BridgeThing.ftlh: -------------------------------------------------------------------------------- 1 | <#include "../CommonLicense.ftlh"> 2 | 3 | package ${thing.package}; 4 | 5 | import org.openhab.automation.jrule.things.${thing.parentClass}; 6 | import java.util.List; 7 | <#include "ThingJavadoc.ftlh"> 8 | public class ${thing.class} extends ${thing.parentClass} { 9 | <#include "ThingMethods.ftlh"> 10 | 11 | public List getSubThingUIDs() { 12 | return List.of( 13 | <#list thing.subThingUIDs as subThingUID> 14 | "${subThingUID}"<#sep>, 15 | 16 | ); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/templates/things/Standalone.ftlh: -------------------------------------------------------------------------------- 1 | <#include "../CommonLicense.ftlh"> 2 | 3 | package ${thing.package}; 4 | 5 | import org.openhab.automation.jrule.things.${thing.parentClass}; 6 | 7 | <#include "ThingJavadoc.ftlh"> 8 | public class ${thing.class} extends ${thing.parentClass} { 9 | <#include "ThingMethods.ftlh"> 10 | } 11 | -------------------------------------------------------------------------------- /src/main/resources/templates/things/SubThing.ftlh: -------------------------------------------------------------------------------- 1 | <#include "../CommonLicense.ftlh"> 2 | 3 | package ${thing.package}; 4 | 5 | import org.openhab.automation.jrule.things.${thing.parentClass}; 6 | 7 | <#include "ThingJavadoc.ftlh"> 8 | public class ${thing.class} extends ${thing.parentClass} { 9 | <#include "ThingMethods.ftlh"> 10 | 11 | public String getBridgeUID() { 12 | return "${thing.bridgeUID}"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/templates/things/ThingJavadoc.ftlh: -------------------------------------------------------------------------------- 1 | /** 2 | * Automatically Generated Class for Thing ${thing.name} - DO NOT EDIT! 3 | * 4 | * @author Arne Seime - Initial contribution 5 | */ 6 | -------------------------------------------------------------------------------- /src/main/resources/templates/things/ThingMethods.ftlh: -------------------------------------------------------------------------------- 1 | 2 | public static final String ID = "${thing.id}"; 3 | 4 | public static final String LABEL = "<#if thing.label??>${thing.label}"; 5 | 6 | <#list thing.triggerChannels as channel> 7 | public static final String ${channel.fieldName} = "${thing.id}:${channel.channelName}"; 8 | 9 | 10 | public ${thing.class}(String id) { 11 | super(id); 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return "'"+LABEL+"'/"+ID; 17 | } 18 | 19 | @Override 20 | public String getLabel() { 21 | return LABEL; 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/main/resources/templates/things/Things.ftlh: -------------------------------------------------------------------------------- 1 | <#include "../CommonLicense.ftlh"> 2 | 3 | package ${packageName}; 4 | 5 | import org.openhab.automation.jrule.things.JRuleThingRegistry; 6 | import org.openhab.automation.jrule.things.JRuleBridgeThing; 7 | import org.openhab.automation.jrule.things.JRuleStandaloneThing; 8 | import org.openhab.automation.jrule.things.JRuleSubThing; 9 | 10 | <#list things as thing> 11 | import org.openhab.automation.jrule.generated.things.${thing.class}; 12 | 13 | 14 | /** 15 | * Automatically Generated Class for Things - DO NOT EDIT! 16 | * 17 | * @author Arne Seime - Initial contribution 18 | */ 19 | public class JRuleThings { 20 | 21 | 22 | 23 | <#list things as thing> 24 | public static ${thing.parentClass} ${thing.name}; 25 | 26 | 27 | 28 | public JRuleThings() { 29 | 30 | <#list things as thing> 31 | ${thing.name} = JRuleThingRegistry.get("${thing.id}", ${thing.class}.class); 32 | 33 | 34 | 35 | } 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/internal/JRuleUtilTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal; 14 | 15 | import static org.junit.jupiter.api.Assertions.assertEquals; 16 | 17 | import org.junit.jupiter.api.BeforeEach; 18 | import org.junit.jupiter.api.Test; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import ch.qos.logback.classic.Level; 22 | import ch.qos.logback.classic.Logger; 23 | 24 | /** 25 | * The {@link JRuleUtilTest} 26 | * 27 | * @author Joseph (Seaside) Hagberg - Initial contribution 28 | */ 29 | public class JRuleUtilTest { 30 | private static final Logger logger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); 31 | 32 | @BeforeEach 33 | public void setUp() { 34 | Logger rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); 35 | rootLogger.setLevel(Level.ALL); 36 | } 37 | 38 | @Test 39 | public void testParseItemName() { 40 | String itemTopicGroup = JRuleUtil 41 | .getItemNameFromTopic("openhab/items/gSensorPowerSum/ZwaveULRDimmerSensorPower/statechanged"); 42 | logger.info("Topic Group: {}", itemTopicGroup); 43 | String topic = "openhab/items/ZwaveEye3Motion/statechanged"; 44 | String itemTopic = JRuleUtil.getItemNameFromTopic(topic); 45 | assertEquals("gSensorPowerSum", itemTopicGroup); 46 | assertEquals("ZwaveEye3Motion", itemTopic); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/internal/QuantityTypeParsingTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal; 14 | 15 | import static org.junit.jupiter.api.Assertions.assertEquals; 16 | import static org.junit.jupiter.api.Assertions.assertThrows; 17 | 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.core.library.types.QuantityType; 20 | import org.openhab.core.library.unit.SIUnits; 21 | 22 | /** 23 | * The {@link QuantityTypeParsingTest} 24 | * 25 | * @author Arne Seime - Initial contribution 26 | */ 27 | public class QuantityTypeParsingTest { 28 | 29 | @Test 30 | public void testParseQuantityType() { 31 | assertEquals(10, new QuantityType<>(10, SIUnits.CELSIUS).doubleValue()); 32 | assertEquals(10, QuantityType.valueOf("10").doubleValue()); 33 | 34 | assertThrows(NumberFormatException.class, () -> QuantityType.valueOf("UNDEF")); 35 | assertThrows(NumberFormatException.class, () -> Double.parseDouble("UNDEF")); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/internal/rules/delayed/JRuleDelayedTestRules.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.rules.delayed; 14 | 15 | import org.openhab.automation.jrule.items.JRuleStringItem; 16 | import org.openhab.automation.jrule.rules.JRule; 17 | import org.openhab.automation.jrule.rules.JRuleDelayed; 18 | import org.openhab.automation.jrule.rules.JRuleName; 19 | import org.openhab.automation.jrule.rules.JRuleWhenItemChange; 20 | 21 | /** 22 | * @author Robert Delbrück - Initial contribution 23 | */ 24 | public class JRuleDelayedTestRules extends JRule { 25 | 26 | public static final String TRIGGER_ITEM = "trigger"; 27 | public static final String TARGET_ITEM = "target"; 28 | 29 | @JRuleName("Rule name") 30 | @JRuleWhenItemChange(item = TRIGGER_ITEM, to = "2s") 31 | @JRuleDelayed(value = 2) 32 | public void test2s() { 33 | JRuleStringItem stringItem = JRuleStringItem.forName(TARGET_ITEM); 34 | stringItem.sendCommand("2s"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/internal/rules/timers/TargetItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.rules.timers; 14 | 15 | import java.util.List; 16 | 17 | import org.openhab.automation.jrule.internal.items.JRuleInternalStringItem; 18 | import org.openhab.automation.jrule.items.metadata.JRuleMetadataRegistry; 19 | 20 | /** 21 | * Simple dummy item used in testcase (would normally be generated from item definition) 22 | * 23 | * @author Arne Seime - Initial contribution 24 | */ 25 | public class TargetItem extends JRuleInternalStringItem { 26 | 27 | public TargetItem(String itemName, String label, String type, String id, JRuleMetadataRegistry metadataRegistry, 28 | List tags) { 29 | super(itemName, label, type, id, metadataRegistry, tags); 30 | } 31 | 32 | @Override 33 | public String getLabel() { 34 | return "label"; 35 | } 36 | 37 | @Override 38 | public String getType() { 39 | return "STRING"; 40 | } 41 | 42 | @Override 43 | public String getId() { 44 | return "ID"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/internal/rules/triggers/itemchangecondition/JRuleItemChangeConditionRules.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.internal.rules.triggers.itemchangecondition; 14 | 15 | import org.openhab.automation.jrule.rules.JRule; 16 | import org.openhab.automation.jrule.rules.JRuleCondition; 17 | import org.openhab.automation.jrule.rules.JRuleName; 18 | import org.openhab.automation.jrule.rules.JRuleWhenItemChange; 19 | import org.openhab.automation.jrule.rules.event.JRuleEvent; 20 | 21 | /** 22 | * The {@link JRuleItemChangeConditionRules} contains rules for testing @JRuleWhenItemChange#previousCondition 23 | * 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | public class JRuleItemChangeConditionRules extends JRule { 28 | public static final String ITEM_FROM_TO = "item_from_to"; 29 | public static final String ITEM_FROM_TO_2 = "item_from_to_2"; 30 | public static final String ITEM_FROM_TO_3 = "item_from_to_3"; 31 | 32 | @JRuleName("Test JRuleWhenItemChange/from/to") 33 | @JRuleWhenItemChange(item = ITEM_FROM_TO, previousCondition = @JRuleCondition(lt = 12), condition = @JRuleCondition(gte = 12)) 34 | public void itemChangeFromTo(JRuleEvent event) { 35 | } 36 | 37 | @JRuleName("Test JRuleWhenItemChange/from/to") 38 | @JRuleWhenItemChange(item = ITEM_FROM_TO_2, previousCondition = @JRuleCondition(lt = 10), condition = @JRuleCondition(gt = 20)) 39 | public void itemChangeFromTo2(JRuleEvent event) { 40 | } 41 | 42 | @JRuleName("Test JRuleWhenItemChange/from/to Quantity") 43 | @JRuleWhenItemChange(item = ITEM_FROM_TO_3, previousCondition = @JRuleCondition(lt = 40), condition = @JRuleCondition(gt = 40)) 44 | public void itemChangeFromTo3(JRuleEvent event) { 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleCallGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalCallGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRuleStringListValue; 21 | 22 | /** 23 | * The {@link JRuleCallGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | public class JRuleCallGroupItemTest extends JRuleCallItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalCallGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, List.of("Lighting", "Inside")); 31 | } 32 | 33 | @Test 34 | public void testMemberOfGeneric() { 35 | List set = JRuleCallGroupItem.forName(GROUP_NAME).memberItems().stream() 36 | .map(JRuleCallItem::getStateAsStringList).toList(); 37 | Assertions.assertEquals(3, set.size()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleColorGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalColorGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRuleHsbValue; 21 | 22 | /** 23 | * The {@link JRuleColorGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleColorGroupItemTest extends JRuleColorItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalColorGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, List.of("Lighting", "Inside")); 31 | } 32 | 33 | @Test 34 | public void testMemberOfGeneric() { 35 | List set = JRuleColorGroupItem.forName(GROUP_NAME).memberItems().stream() 36 | .map(JRuleColorItem::getStateAsHsb).toList(); 37 | Assertions.assertEquals(3, set.size()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleContactGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalContactGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRuleOpenClosedValue; 21 | 22 | /** 23 | * The {@link JRuleContactGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleContactGroupItemTest extends JRuleContactItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalContactGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, 31 | List.of("Lighting", "Inside")); 32 | } 33 | 34 | @Test 35 | public void testMemberOfGeneric() { 36 | List set = JRuleContactGroupItem.forName(GROUP_NAME).memberItems().stream() 37 | .map(JRuleContactItem::getStateAsOpenClose).toList(); 38 | Assertions.assertEquals(3, set.size()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleDateTimeGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalDateTimeGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRuleDateTimeValue; 21 | 22 | /** 23 | * The {@link JRuleDateTimeGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleDateTimeGroupItemTest extends JRuleDateTimeItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalDateTimeGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, 31 | List.of("Lighting", "Inside")); 32 | } 33 | 34 | @Test 35 | public void testMemberOfGeneric() { 36 | List set = JRuleDateTimeGroupItem.forName(GROUP_NAME).memberItems().stream() 37 | .map(JRuleDateTimeItem::getStateAsDateTime).toList(); 38 | Assertions.assertEquals(3, set.size()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleDimmerGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalDimmerGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRulePercentValue; 21 | 22 | /** 23 | * The {@link JRuleDimmerGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleDimmerGroupItemTest extends JRuleDimmerItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalDimmerGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, List.of("Lighting", "Inside")); 31 | } 32 | 33 | @Test 34 | public void testMemberOfGeneric() { 35 | List set = JRuleDimmerGroupItem.forName(GROUP_NAME).memberItems().stream() 36 | .map(JRuleDimmerItem::getStateAsPercent).toList(); 37 | Assertions.assertEquals(3, set.size()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleImageGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalImageGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRuleRawValue; 21 | 22 | /** 23 | * The {@link JRuleImageGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleImageGroupItemTest extends JRuleImageItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalImageGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, List.of("Lighting", "Inside")); 31 | } 32 | 33 | @Test 34 | public void testMemberOfGeneric() { 35 | List set = JRuleImageGroupItem.forName(GROUP_NAME).memberItems().stream() 36 | .map(JRuleImageItem::getStateAsRaw).toList(); 37 | Assertions.assertEquals(3, set.size()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleLocationGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalLocationGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRulePointValue; 21 | 22 | /** 23 | * The {@link JRuleLocationGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleLocationGroupItemTest extends JRuleLocationItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalLocationGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, 31 | List.of("Lighting", "Inside")); 32 | } 33 | 34 | @Test 35 | public void testMemberOfGeneric() { 36 | List set = JRuleLocationGroupItem.forName(GROUP_NAME).memberItems().stream() 37 | .map(JRuleLocationItem::getStateAsPoint).toList(); 38 | Assertions.assertEquals(3, set.size()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleNumberGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalNumberGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRuleDecimalValue; 21 | 22 | /** 23 | * The {@link JRuleNumberGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleNumberGroupItemTest extends JRuleNumberItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalNumberGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, List.of("Lighting", "Inside")); 31 | } 32 | 33 | @Test 34 | public void testMemberOfGeneric() { 35 | List set = JRuleNumberGroupItem.forName(GROUP_NAME).memberItems().stream() 36 | .map(JRuleNumberItem::getStateAsDecimal).toList(); 37 | Assertions.assertEquals(3, set.size()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRulePlayerGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalPlayerGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRulePlayPauseValue; 21 | 22 | /** 23 | * The {@link JRulePlayerGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRulePlayerGroupItemTest extends JRulePlayerItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalPlayerGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, List.of("Lighting", "Inside")); 31 | } 32 | 33 | @Test 34 | public void testMemberOfGeneric() { 35 | List set = JRulePlayerGroupItem.forName(GROUP_NAME).memberItems().stream() 36 | .map(JRulePlayerItem::getStateAsPlayPause).toList(); 37 | Assertions.assertEquals(3, set.size()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleQuantityGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalQuantityGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRuleQuantityValue; 21 | 22 | /** 23 | * The {@link JRuleQuantityGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleQuantityGroupItemTest extends JRuleQuantityItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalQuantityGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, 31 | List.of("Lighting", "Inside")); 32 | } 33 | 34 | @Test 35 | public void testMemberOfGeneric() { 36 | List set = JRuleQuantityGroupItem.forName(GROUP_NAME).memberItems().stream() 37 | .map(JRuleQuantityItem::getStateAsQuantity).toList(); 38 | Assertions.assertEquals(3, set.size()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleRollershutterGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalRollershutterGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRulePercentValue; 21 | 22 | /** 23 | * The {@link JRuleRollershutterGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleRollershutterGroupItemTest extends JRuleRollershutterItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalRollershutterGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, 31 | List.of("Lighting", "Inside")); 32 | } 33 | 34 | @Test 35 | public void testMemberOfGeneric() { 36 | List set = JRuleRollershutterGroupItem.forName(GROUP_NAME).memberItems().stream() 37 | .map(JRuleRollershutterItem::getStateAsPercent).toList(); 38 | Assertions.assertEquals(3, set.size()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleStringGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalStringGroupItem; 20 | 21 | /** 22 | * The {@link JRuleStringGroupItemTest} 23 | * 24 | * @author Robert Delbrück - Initial contribution 25 | */ 26 | class JRuleStringGroupItemTest extends JRuleStringItemTest { 27 | @Override 28 | protected JRuleItem getJRuleItem() { 29 | return new JRuleInternalStringGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, List.of("Lighting", "Inside")); 30 | } 31 | 32 | @Test 33 | public void testMemberOfGeneric() { 34 | List set = JRuleStringGroupItem.forName(GROUP_NAME).memberItems().stream() 35 | .map(JRuleStringItem::getStateAsString).toList(); 36 | Assertions.assertEquals(3, set.size()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/items/JRuleSwitchGroupItemTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.items; 14 | 15 | import java.util.List; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | import org.openhab.automation.jrule.internal.items.JRuleInternalSwitchGroupItem; 20 | import org.openhab.automation.jrule.rules.value.JRuleOnOffValue; 21 | 22 | /** 23 | * The {@link JRuleSwitchGroupItemTest} 24 | * 25 | * @author Robert Delbrück - Initial contribution 26 | */ 27 | class JRuleSwitchGroupItemTest extends JRuleSwitchItemTest { 28 | @Override 29 | protected JRuleItem getJRuleItem() { 30 | return new JRuleInternalSwitchGroupItem(GROUP_NAME, "Label", "Type", "Id", mock, List.of("Lighting", "Inside")); 31 | } 32 | 33 | @Test 34 | public void testMemberOfGeneric() { 35 | List set = JRuleSwitchGroupItem.forName(GROUP_NAME).memberItems().stream() 36 | .map(JRuleSwitchItem::getStateAsOnOff).toList(); 37 | Assertions.assertEquals(3, set.size()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleDateTimeValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import java.time.ZonedDateTime; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | 20 | /** 21 | * The {@link JRuleDateTimeValueTest} 22 | * 23 | * @author Robert Delbrück - Initial contribution 24 | */ 25 | class JRuleDateTimeValueTest { 26 | 27 | @Test 28 | void asStringValue() { 29 | JRuleDateTimeValue value = new JRuleDateTimeValue(ZonedDateTime.now()); 30 | String string = value.stringValue(); 31 | JRuleDateTimeValue fromString = new JRuleDateTimeValue(string); 32 | Assertions.assertEquals(value, fromString); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleDecimalValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import java.util.function.Consumer; 16 | import java.util.stream.Stream; 17 | 18 | import org.junit.jupiter.api.Assertions; 19 | import org.junit.jupiter.api.DynamicTest; 20 | import org.junit.jupiter.api.Test; 21 | import org.junit.jupiter.api.TestFactory; 22 | 23 | /** 24 | * The {@link JRuleDecimalValueTest} 25 | * 26 | * @author Robert Delbrück - Initial contribution 27 | */ 28 | class JRuleDecimalValueTest { 29 | 30 | @Test 31 | void asStringValue() { 32 | JRuleDecimalValue value = new JRuleDecimalValue(23.12); 33 | String string = value.stringValue(); 34 | JRuleDecimalValue fromString = new JRuleDecimalValue(string); 35 | Assertions.assertEquals(value, fromString); 36 | } 37 | 38 | @TestFactory 39 | Stream as() { 40 | return Stream.of( 41 | DynamicTest.dynamicTest("JRuleDecimalValue", 42 | () -> cast(new JRuleQuantityValue("23.12 kW"), JRuleDecimalValue.class, 43 | t -> Assertions.assertEquals(23.12F, t.floatValue()))), 44 | DynamicTest.dynamicTest("JRulePercentValue", () -> cast(new JRuleQuantityValue("70 %"), 45 | JRulePercentValue.class, t -> Assertions.assertEquals(70, t.intValue())))); 46 | } 47 | 48 | private void cast(JRuleQuantityValue value, Class target, Consumer assertion) { 49 | assertion.accept((T) value.as(target)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleHsbValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRuleHsbValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRuleHsbValueTest { 24 | @Test 25 | void asStringValue() { 26 | JRuleHsbValue value = new JRuleHsbValue(24, 45, 13); 27 | String string = value.stringValue(); 28 | JRuleHsbValue fromString = new JRuleHsbValue(string); 29 | Assertions.assertEquals(value, fromString); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleIncreaseDecreaseValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRuleIncreaseDecreaseValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRuleIncreaseDecreaseValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRuleIncreaseDecreaseValue value = JRuleIncreaseDecreaseValue.INCREASE; 28 | String string = value.stringValue(); 29 | JRuleIncreaseDecreaseValue fromString = JRuleIncreaseDecreaseValue.getValueFromString(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleOnOffValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRuleOnOffValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRuleOnOffValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRuleOnOffValue value = JRuleOnOffValue.OFF; 28 | String string = value.stringValue(); 29 | JRuleOnOffValue fromString = JRuleOnOffValue.getValueFromString(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleOpenClosedValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRuleOpenClosedValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRuleOpenClosedValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRuleOpenClosedValue value = JRuleOpenClosedValue.CLOSED; 28 | String string = value.stringValue(); 29 | JRuleOpenClosedValue fromString = JRuleOpenClosedValue.getValueFromString(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRulePercentValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRulePercentValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRulePercentValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRulePercentValue value = new JRulePercentValue(23.12); 28 | String string = value.stringValue(); 29 | JRulePercentValue fromString = new JRulePercentValue(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRulePlayPauseValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRulePlayPauseValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRulePlayPauseValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRulePlayPauseValue value = JRulePlayPauseValue.PLAY; 28 | String string = value.stringValue(); 29 | JRulePlayPauseValue fromString = JRulePlayPauseValue.getValueFromString(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRulePointValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import java.math.BigDecimal; 16 | 17 | import org.junit.jupiter.api.Assertions; 18 | import org.junit.jupiter.api.Test; 19 | 20 | /** 21 | * The {@link JRulePointValueTest} 22 | * 23 | * @author Robert Delbrück - Initial contribution 24 | */ 25 | class JRulePointValueTest { 26 | 27 | @Test 28 | void asStringValue() { 29 | JRulePointValue value = new JRulePointValue(new BigDecimal("23.12"), new BigDecimal("37.56")); 30 | String string = value.stringValue(); 31 | JRulePointValue fromString = new JRulePointValue(string); 32 | Assertions.assertEquals(value, fromString); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleRawValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRuleRawValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRuleRawValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRuleRawValue value = new JRuleRawValue("jpg", new byte[16]); 28 | String string = value.stringValue(); 29 | JRuleRawValue fromString = new JRuleRawValue(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleStopMoveValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRuleStopMoveValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRuleStopMoveValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRuleStopMoveValue value = JRuleStopMoveValue.MOVE; 28 | String string = value.stringValue(); 29 | JRuleStopMoveValue fromString = JRuleStopMoveValue.getValueFromString(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleStringValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRuleStringValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRuleStringValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRuleStringValue value = new JRuleStringValue("hallo"); 28 | String string = value.stringValue(); 29 | JRuleStringValue fromString = new JRuleStringValue(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/openhab/automation/jrule/rules/value/JRuleUpDownValueTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2010-2023 Contributors to the openHAB project 3 | * 4 | * See the NOTICE file(s) distributed with this work for additional 5 | * information. 6 | * 7 | * This program and the accompanying materials are made available under the 8 | * terms of the Eclipse Public License 2.0 which is available at 9 | * http://www.eclipse.org/legal/epl-2.0 10 | * 11 | * SPDX-License-Identifier: EPL-2.0 12 | */ 13 | package org.openhab.automation.jrule.rules.value; 14 | 15 | import org.junit.jupiter.api.Assertions; 16 | import org.junit.jupiter.api.Test; 17 | 18 | /** 19 | * The {@link JRuleUpDownValueTest} 20 | * 21 | * @author Robert Delbrück - Initial contribution 22 | */ 23 | class JRuleUpDownValueTest { 24 | 25 | @Test 26 | void asStringValue() { 27 | JRuleUpDownValue value = JRuleUpDownValue.DOWN; 28 | String string = value.stringValue(); 29 | JRuleUpDownValue fromString = JRuleUpDownValue.getValueFromString(string); 30 | Assertions.assertEquals(value, fromString); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/maven-resources/version: -------------------------------------------------------------------------------- 1 | ${project.version} -------------------------------------------------------------------------------- /src/test/resources/docker/conf/persistence/influxdb.persist: -------------------------------------------------------------------------------- 1 | Strategies { 2 | } 3 | Items { 4 | InfluxDbPersist* : strategy = everyChange 5 | } -------------------------------------------------------------------------------- /src/test/resources/docker/conf/services/addons.cfg: -------------------------------------------------------------------------------- 1 | # The installation package of this openHAB instance 2 | # Note: This is only regarded at the VERY FIRST START of openHAB 3 | # Note: If you want to specify your add-ons yourself through entries below, set the package to "minimal" 4 | # as otherwise your definition might be in conflict with what the installation package defines. 5 | # 6 | # Valid options: 7 | # - standard : Standard setup for normal use of openHAB with persistence (rrd4j) and additional UI add-ons (basic,habpanel). 8 | # - minimal : Installation of core components without additional add-ons. 9 | # 10 | package = standard 11 | 12 | # Access Remote Add-on Repository 13 | # Defines whether the remote openHAB add-on repository should be used for browsing and installing add-ons. (default is true) 14 | # 15 | #remote = true 16 | 17 | # A comma-separated list of automation services to install (e.g. "automation = groovyscripting") 18 | #automation = 19 | 20 | # A comma-separated list of bindings to install (e.g. "binding = knx,sonos,zwave") 21 | binding = mqtt 22 | 23 | # A comma-separated list of miscellaneous services to install (e.g. "misc = openhabcloud") 24 | #misc = 25 | 26 | # A comma-separated list of persistence services to install (e.g. "persistence = jpa,rrd4j") 27 | persistence = rrd4j,influxdb 28 | 29 | # A comma-separated list of transformation services to install (e.g. "transformation = jsonpath,map") 30 | #transformation = 31 | 32 | # A comma-separated list of UIs to install (e.g. "ui = basic,habpanel") 33 | #ui = 34 | 35 | # A comma-separated list of voice services to install (e.g. "voice = googletts,marytts") 36 | #voice = 37 | -------------------------------------------------------------------------------- /src/test/resources/docker/conf/services/influxdb.cfg: -------------------------------------------------------------------------------- 1 | version=V2 2 | url=http://influxdb:8086 3 | user=openhab 4 | token=mytoken 5 | db=openhab 6 | retentionPolicy=autogen 7 | -------------------------------------------------------------------------------- /src/test/resources/docker/conf/services/rrd4j.cfg: -------------------------------------------------------------------------------- 1 | # configure specific rrd properties for given items in this file. 2 | # please refer to the documentation available at 3 | # https://www.openhab.org/addons/persistence/rrd4j/ 4 | # 5 | # default_numeric and default_other are internally defined defnames and are used as 6 | # defaults when no other defname applies 7 | 8 | #.def=[ABSOLUTE|COUNTER|DERIVE|GAUGE],,[|U],[|U], 9 | #.archives=[AVERAGE|MIN|MAX|LAST|FIRST|TOTAL],,, 10 | #.items= 11 | -------------------------------------------------------------------------------- /src/test/resources/docker/conf/things/mqtt.things: -------------------------------------------------------------------------------- 1 | Bridge mqtt:broker:mqtt [ host="mqtt", port=8666, username="admin", password="admin", reconnectTime=5000, keepAlive=5 ] 2 | { 3 | Thing topic generic { 4 | Channels: 5 | Type number : number [ stateTopic="number/state" ] 6 | Type number : numberTrigger [ stateTopic="number/state", trigger="true" ] 7 | } 8 | Thing topic fromonlinetest { 9 | Channels: 10 | Type number : number [ stateTopic="fromonlinetest/state" ] 11 | } 12 | } -------------------------------------------------------------------------------- /src/test/resources/docker/mosquitto/default.acl: -------------------------------------------------------------------------------- 1 | # anonymous access 2 | topic readwrite # -------------------------------------------------------------------------------- /src/test/resources/docker/users.json: -------------------------------------------------------------------------------- 1 | { 2 | "admin": { 3 | "class": "org.openhab.core.auth.ManagedUser", 4 | "value": { 5 | "name": "admin", 6 | "passwordHash": "Z0ByfAakbZRjZEOPF51HP8gtvM8HDXOvBsdCg4x66MEYUMewmOqnVc0pf1gOvr+L0G0YuWducjpcyAokl2GEVQ\u003d\u003d", 7 | "passwordSalt": "SYow/J4DzuRZFXCb7zYp9mo4gEiDM8AcxfOoOLsvwiTGc958FZZqrSZl58/fRGmw7WJPnG6iB0oJQvmnLEoKEQ\u003d\u003d", 8 | "roles": [ 9 | "administrator" 10 | ], 11 | "sessions": [], 12 | "apiTokens": [] 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/test/resources/docker/users.properties: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | ################################################################################ 19 | 20 | # 21 | # This file contains the users, groups, and roles. 22 | # Each line has to be of the format: 23 | # 24 | # USER=PASSWORD,ROLE1,ROLE2,... 25 | # USER=PASSWORD,_g_:GROUP,... 26 | # _g_\:GROUP=ROLE1,ROLE2,... 27 | # 28 | # All users, groups, and roles entered in this file are available after Karaf startup 29 | # and modifiable via the JAAS command group. These users reside in a JAAS domain 30 | # with the name "karaf". 31 | # 32 | openhab = {CRYPT}4F61A0FD056BC0FD8231899EC4D9F9CA06AF0DEC895B2A3B0773F6FBC1C99776{CRYPT},_g_:admingroup 33 | _g_\:admingroup = group,admin,manager,viewer,systembundles 34 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tools/static-code-analysis/checkstyle/ruleset.properties: -------------------------------------------------------------------------------- 1 | checkstyle.headerCheck.content=^/\\*\\*$\\n^ \\* Copyright \\(c\\) {0}-{1} Contributors to the openHAB project$\\n^ \\*$\\n^ \\* See the NOTICE file\\(s\\) distributed with this work for additional$\\n^ \\* information.$\\n^ \\*$\\n^ \\* This program and the accompanying materials are made available under the$\\n^ \\* terms of the Eclipse Public License 2\\.0 which is available at$\\n^ \\* http://www.eclipse.org/legal/epl\\-2\\.0$\\n^ \\*$\\n^ \\* SPDX-License-Identifier: EPL-2.0$ 2 | checkstyle.headerCheck.values=2010,2023 3 | checkstyle.forbiddenPackageUsageCheck.forbiddenPackages=com.google.common,gnu.io,javax.comm,org.apache.commons,org.joda.time,org.junit.Assert,org.junit.Test,si.uom,tech.units 4 | checkstyle.forbiddenPackageUsageCheck.exceptions= 5 | checkstyle.requiredFilesCheck.files=pom.xml 6 | checkstyle.karafAddonFeatureCheck.featureNameMappings=-transform-:-transformation-,-io-:-misc- 7 | checkstyle.karafAddonFeatureCheck.excludeAddonPatterns=org.openhab.persistence.jdbc.*,org.openhab.binding.modbus.* 8 | -------------------------------------------------------------------------------- /tools/static-code-analysis/spotbugs/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | --------------------------------------------------------------------------------