Skip to content

Commit

Permalink
refactor animations
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreKoepke committed Feb 20, 2025
1 parent 2a7cf1c commit 85d6713
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ch.akop.homesystem.models.devices.actor.SimpleLight;
import ch.akop.homesystem.persistence.model.animation.Animation;
import ch.akop.homesystem.persistence.model.animation.steps.Step;
import ch.akop.homesystem.persistence.repository.config.AnimationRepository;
import io.quarkus.vertx.ConsumeEvent;
import io.reactivex.rxjava3.core.Observable;
Expand Down Expand Up @@ -44,14 +45,22 @@ public void playAnimation(UUID animationId) {
var freshAnimation = animationRepository.getOne(animationId);
var animationSteps = freshAnimation.materializeSteps();

runningAnimations.put(animationId, Observable.fromRunnable(() -> animationSteps
.forEach(step -> {
if (runningAnimations.containsKey(animationId)) {
step.play(deviceService);
}
}))
runningAnimations.put(animationId, Observable.fromRunnable(() -> playAllAnimation(freshAnimation, animationSteps))
.subscribeOn(RxHelper.blockingScheduler(vertx))
.subscribe(ignore -> runningAnimations.remove(animationId)));
.subscribe(o -> {
}));
}

private void playAllAnimation(Animation animation, List<? extends Step> steps) {
try {
steps.stream()
.filter(step -> runningAnimations.containsKey(animation.getId()))
.forEach(step -> step.play(deviceService));
} catch (Exception e) {
log.error("Error playing animation {}", animation.getId(), e);
} finally {
runningAnimations.remove(animation.getId());
}
}

@Transactional
Expand Down

0 comments on commit 85d6713

Please sign in to comment.