From ed67bea96f52d67b851fe7bae6fef0f35ecd6988 Mon Sep 17 00:00:00 2001 From: seaside1 Date: Wed, 22 Nov 2023 20:09:22 +0100 Subject: [PATCH] Added networkaddresresolver and other oh managers to be available from rules --- .../jrule/internal/JRuleFactory.java | 9 +++++-- .../jrule/internal/handler/JRuleHandler.java | 8 +++++-- .../handler/JRuleTransformationHandler.java | 6 ++++- .../internal/handler/JRuleVoiceHandler.java | 24 +++++++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openhab/automation/jrule/internal/JRuleFactory.java b/src/main/java/org/openhab/automation/jrule/internal/JRuleFactory.java index 72336e5e..2811732d 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/JRuleFactory.java +++ b/src/main/java/org/openhab/automation/jrule/internal/JRuleFactory.java @@ -22,9 +22,11 @@ import org.openhab.automation.jrule.internal.handler.JRuleHandler; import org.openhab.automation.jrule.internal.module.JRuleRuleProvider; import org.openhab.automation.jrule.items.JRuleItemRegistry; +import org.openhab.core.audio.AudioHTTPServer; import org.openhab.core.events.EventPublisher; import org.openhab.core.items.ItemRegistry; import org.openhab.core.items.MetadataRegistry; +import org.openhab.core.net.NetworkAddressService; import org.openhab.core.persistence.PersistenceServiceRegistry; import org.openhab.core.scheduler.CronScheduler; import org.openhab.core.thing.ThingManager; @@ -62,7 +64,8 @@ public class JRuleFactory { public JRuleFactory(Map properties, final @Reference JRuleEventSubscriber eventSubscriber, final @Reference ItemRegistry itemRegistry, final @Reference ThingRegistry thingRegistry, final @Reference ThingManager thingManager, final @Reference EventPublisher eventPublisher, - final @Reference VoiceManager voiceManager, final ComponentContext componentContext, + final @Reference VoiceManager voiceManager, final @Reference AudioHTTPServer audioHTTPServer, + final @Reference NetworkAddressService networkAddressService, final ComponentContext componentContext, final @Reference CronScheduler cronScheduler, final @Reference MetadataRegistry metadataRegistry, final @Reference JRuleRuleProvider ruleProvider, @Reference final PersistenceServiceRegistry persistenceServiceRegistry) { @@ -74,10 +77,12 @@ public JRuleFactory(Map properties, final @Reference JRuleEventS jRuleEngine.setItemRegistry(itemRegistry); jRuleEngine.setCronScheduler(cronScheduler); jRuleEngine.setRuleProvider(ruleProvider); + jRuleEngine.initialize(); JRuleItemRegistry.setMetadataRegistry(metadataRegistry); jRuleHandler = new JRuleHandler(config, itemRegistry, thingRegistry, thingManager, eventPublisher, - eventSubscriber, voiceManager, cronScheduler, componentContext.getBundleContext(), metadataRegistry); + eventSubscriber, voiceManager, audioHTTPServer, networkAddressService, cronScheduler, + componentContext.getBundleContext(), metadataRegistry); delayedInit.call(this::init); } diff --git a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleHandler.java b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleHandler.java index f5b22c3e..03db92fa 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleHandler.java +++ b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleHandler.java @@ -50,6 +50,7 @@ import org.openhab.automation.jrule.items.JRuleItemRegistry; import org.openhab.automation.jrule.things.JRuleThingClassGenerator; import org.openhab.automation.jrule.things.JRuleThingRegistry; +import org.openhab.core.audio.AudioHTTPServer; import org.openhab.core.events.Event; import org.openhab.core.events.EventPublisher; import org.openhab.core.items.Item; @@ -59,6 +60,7 @@ import org.openhab.core.items.events.ItemAddedEvent; import org.openhab.core.items.events.ItemRemovedEvent; import org.openhab.core.items.events.ItemUpdatedEvent; +import org.openhab.core.net.NetworkAddressService; import org.openhab.core.scheduler.CronScheduler; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingManager; @@ -119,8 +121,8 @@ public class JRuleHandler implements PropertyChangeListener { public JRuleHandler(JRuleConfig config, ItemRegistry itemRegistry, ThingRegistry thingRegistry, ThingManager thingManager, EventPublisher eventPublisher, JRuleEventSubscriber eventSubscriber, - VoiceManager voiceManager, CronScheduler cronScheduler, BundleContext bundleContext, - MetadataRegistry metadataRegistry) { + VoiceManager voiceManager, AudioHTTPServer audioHTTPServer, NetworkAddressService networkAddressService, + CronScheduler cronScheduler, BundleContext bundleContext, MetadataRegistry metadataRegistry) { this.itemRegistry = itemRegistry; this.thingRegistry = thingRegistry; this.metadataRegistry = metadataRegistry; @@ -142,6 +144,8 @@ public JRuleHandler(JRuleConfig config, ItemRegistry itemRegistry, ThingRegistry eventSubscriber.addPropertyChangeListener(this); final JRuleVoiceHandler jRuleVoiceHandler = JRuleVoiceHandler.get(); jRuleVoiceHandler.setVoiceManager(voiceManager); + jRuleVoiceHandler.setAudioHTTPServer(audioHTTPServer); + jRuleVoiceHandler.setNetworkAddressService(networkAddressService); final JRuleTransformationHandler jRuleTransformationHandler = JRuleTransformationHandler.get(); jRuleTransformationHandler.setBundleContext(bundleContext); diff --git a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleTransformationHandler.java b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleTransformationHandler.java index 116092aa..e9478831 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleTransformationHandler.java +++ b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleTransformationHandler.java @@ -50,9 +50,13 @@ public void setBundleContext(BundleContext bundleContext) { this.bundleContext = bundleContext; } + public BundleContext getBundleContext() { + return bundleContext; + } + /** * Transforms the given state with the transformation pattern. - * + * * @param stateDescPattern The transformation pattern * @param state State which should be converted * @return The transformation result diff --git a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleVoiceHandler.java b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleVoiceHandler.java index 7b219d7a..a2c071ca 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleVoiceHandler.java +++ b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleVoiceHandler.java @@ -12,7 +12,9 @@ */ package org.openhab.automation.jrule.internal.handler; +import org.openhab.core.audio.AudioHTTPServer; import org.openhab.core.library.types.PercentType; +import org.openhab.core.net.NetworkAddressService; import org.openhab.core.voice.VoiceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,6 +30,12 @@ public class JRuleVoiceHandler { private static volatile JRuleVoiceHandler instance; private VoiceManager voiceManager; + private AudioHTTPServer audioHTTPServer; + private NetworkAddressService networkAddressService; + + public VoiceManager getVoiceManager() { + return voiceManager; + } private final Logger logger = LoggerFactory.getLogger(JRuleVoiceHandler.class); @@ -66,4 +74,20 @@ public void say(String text, String voiceId, String sinkId, int volumePercent) { final PercentType volume = new PercentType(volumePercent); voiceManager.say(text, voiceId, sinkId, volume); } + + public AudioHTTPServer getAudioHTTPServer() { + return audioHTTPServer; + } + + public void setAudioHTTPServer(AudioHTTPServer audioHTTPServer) { + this.audioHTTPServer = audioHTTPServer; + } + + public NetworkAddressService getNetworkAddressService() { + return networkAddressService; + } + + public void setNetworkAddressService(NetworkAddressService networkAddressService) { + this.networkAddressService = networkAddressService; + } }