Skip to content

Commit

Permalink
Added networkaddresresolver and other oh managers to be available fro…
Browse files Browse the repository at this point in the history
…m rules
  • Loading branch information
seaside1 committed Nov 22, 2023
1 parent 93f043e commit ed67bea
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,7 +64,8 @@ public class JRuleFactory {
public JRuleFactory(Map<String, Object> 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) {
Expand All @@ -74,10 +77,12 @@ public JRuleFactory(Map<String, Object> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
}

0 comments on commit ed67bea

Please sign in to comment.