Skip to content

Commit

Permalink
Merge branch 'openhab:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
genesis81 authored Nov 1, 2023
2 parents fe1673c + 26283da commit f73e748
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.openhab.core.audio.AudioSinkAsync;
import org.openhab.core.audio.AudioStream;
import org.openhab.core.audio.StreamServed;
import org.openhab.core.audio.URLAudioStream;
import org.openhab.core.audio.UnsupportedAudioFormatException;
import org.openhab.core.audio.UnsupportedAudioStreamException;
import org.openhab.core.events.EventPublisher;
Expand Down Expand Up @@ -67,29 +66,19 @@ public void processAsynchronously(@Nullable AudioStream audioStream)
if (audioStream == null) {
// in case the audioStream is null, this should be interpreted as a request to end any currently playing
// stream.
logger.debug("Web Audio sink does not support stopping the currently playing stream.");
sendEvent("");
return;
}
logger.debug("Received audio stream of format {}", audioStream.getFormat());
if (audioStream instanceof URLAudioStream urlAudioStream) {
try (AudioStream stream = urlAudioStream) {
// in this case only, we need to close the stream by ourself in a try with block,
// because nothing will consume it
// it is an external URL, so we can directly pass this on.
sendEvent(urlAudioStream.getURL());
} catch (IOException e) {
logger.debug("Error while closing the audio stream: {}", e.getMessage(), e);
}
} else {
// we need to serve it for a while and make it available to multiple clients
try {
StreamServed servedStream = audioHTTPServer.serve(audioStream, 10, true);
// we will let the HTTP servlet run the delayed task when finished with the stream
servedStream.playEnd().thenRun(() -> this.playbackFinished(audioStream));
sendEvent(servedStream.url());
} catch (IOException e) {
logger.warn("Cannot precache the audio stream to serve it", e);
}

// we need to serve it for a while and make it available to multiple clients
try {
StreamServed servedStream = audioHTTPServer.serve(audioStream, 10, true);
// we will let the HTTP servlet run the delayed task when finished with the stream
servedStream.playEnd().thenRun(() -> this.playbackFinished(audioStream));
sendEvent(servedStream.url());
} catch (IOException e) {
logger.warn("Cannot precache the audio stream to serve it", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public class FolderObserver implements WatchService.WatchEventListener {
/* set of file extensions for which we have parsers already registered */
private final Set<String> parsers = new HashSet<>();

/* set of file extensions for missing parsers during activation */
private final Set<String> missingParsers = new HashSet<>();

/* set of files that have been ignored due to a missing parser */
private final Set<Path> ignoredPaths = new HashSet<>();
private final Map<String, Path> namePathMap = new HashMap<>();
Expand Down Expand Up @@ -135,9 +138,20 @@ public void activate(ComponentContext ctx) {
}

watchService.registerListener(this, Path.of(""));

addModelsToRepo();
this.activated = true;
logger.debug("{} has been activated", FolderObserver.class.getSimpleName());

// process ignored paths for missing parsers which were added during activation
for (String extension : missingParsers) {
if (parsers.contains(extension)) {
processIgnoredPaths(extension);
readyService.markReady(new ReadyMarker(READYMARKER_TYPE, extension));
logger.debug("Marked extension '{}' as ready", extension);
}
}
missingParsers.clear();
}

@Deactivate
Expand Down Expand Up @@ -187,7 +201,7 @@ private void addModelsToRepo() {
}

for (String extension : validExtensions) {
if (parsers.contains(extension)) {
if (parsers.contains(extension) && !missingParsers.contains(extension)) {
readyService.markReady(new ReadyMarker(READYMARKER_TYPE, extension));
logger.debug("Marked extension '{}' as ready", extension);
}
Expand Down Expand Up @@ -243,8 +257,11 @@ private void checkPath(final Path path, final WatchService.Kind kind) {
} catch (IOException e) {
logger.warn("Error while opening file during update: {}", path.toAbsolutePath());
}
} else {
} else if (extension != null) {
ignoredPaths.add(path);
if (!activated) {
missingParsers.add(extension);
}
if (logger.isDebugEnabled()) {
logger.debug("Missing parser for '{}' extension, added ignored path: {}", extension,
path.toAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ public static BridgeBuilder create(ThingTypeUID thingTypeUID, ThingUID thingUID)
return new BridgeBuilder(thingTypeUID, thingUID);
}

/**
* Create a new bridge {@link BridgeBuilder} for a copy of the given bridge
*
* @param bridge the {@link Bridge} to create this builder from
* @return the created {@link BridgeBuilder}
*
*/
public static BridgeBuilder create(Bridge bridge) {
return BridgeBuilder.create(bridge.getThingTypeUID(), bridge.getUID()).withBridge(bridge.getBridgeUID())
.withChannels(bridge.getChannels()).withConfiguration(bridge.getConfiguration())
.withLabel(bridge.getLabel()).withLocation(bridge.getLocation()).withProperties(bridge.getProperties());
}

@Override
public Bridge build() {
final BridgeImpl bridge = new BridgeImpl(thingTypeUID, thingUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.binding.builder.ThingStatusInfoBuilder;
import org.openhab.core.thing.events.ThingEventFactory;
Expand Down Expand Up @@ -238,7 +239,7 @@ protected void thingUpdated(final Thing thing) {
throw new IllegalArgumentException(MessageFormat.format(
"Cannot update thing {0} because it is not known to the registry", thing.getUID().getAsString()));
}
final Provider<Thing> provider = thingRegistry.getProvider(thing);
final Provider<Thing> provider = thingRegistry.getProvider(oldThing);
if (provider == null) {
throw new IllegalArgumentException(MessageFormat.format(
"Provider for thing {0} cannot be determined because it is not known to the registry",
Expand Down Expand Up @@ -1089,7 +1090,8 @@ private boolean checkAndPerformUpdate(Thing thing, ThingHandlerFactory factory)
}

// create a thing builder and apply the update instructions
ThingBuilder thingBuilder = ThingBuilder.create(thing);
ThingBuilder thingBuilder = thing instanceof Bridge ? BridgeBuilder.create((Bridge) thing)
: ThingBuilder.create(thing);
instructions.forEach(instruction -> instruction.perform(thing, thingBuilder));
int newThingTypeVersion = instructions.get(instructions.size() - 1).getThingTypeVersion();
thingBuilder.withProperty(PROPERTY_THING_TYPE_VERSION, String.valueOf(newThingTypeVersion));
Expand Down
Loading

0 comments on commit f73e748

Please sign in to comment.