2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ecovacs.internal.action;
15 import static org.openhab.binding.ecovacs.internal.EcovacsBindingConstants.*;
17 import java.util.Optional;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.ecovacs.internal.api.commands.PlaySoundCommand;
22 import org.openhab.binding.ecovacs.internal.handler.EcovacsVacuumHandler;
23 import org.openhab.core.automation.annotation.ActionInput;
24 import org.openhab.core.automation.annotation.RuleAction;
25 import org.openhab.core.thing.binding.ThingActions;
26 import org.openhab.core.thing.binding.ThingActionsScope;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * @author Danny Baumann - Initial contribution
34 @ThingActionsScope(name = "ecovacs")
36 public class EcovacsVacuumActions implements ThingActions {
37 private final Logger logger = LoggerFactory.getLogger(EcovacsVacuumActions.class);
38 private @Nullable EcovacsVacuumHandler handler;
41 public void setThingHandler(@Nullable ThingHandler handler) {
42 this.handler = (EcovacsVacuumHandler) handler;
46 public @Nullable ThingHandler getThingHandler() {
50 @RuleAction(label = "@text/playSoundActionLabel", description = "@text/playSoundActionDesc")
51 public void playSound(
52 @ActionInput(name = "type", label = "@text/actionInputSoundTypeLabel", description = "@text/actionInputSoundTypeDesc") String type) {
53 EcovacsVacuumHandler handler = this.handler;
54 if (handler != null) {
55 Optional<PlaySoundCommand.SoundType> soundType = SOUND_TYPE_MAPPING.findMappedEnumValue(type);
56 if (soundType.isPresent()) {
57 handler.playSound(new PlaySoundCommand(soundType.get()));
59 logger.debug("Sound type '{}' is unknown, ignoring", type);
64 @RuleAction(label = "@text/playSoundActionLabel", description = "@text/playSoundActionDesc")
65 public void playSoundWithId(
66 @ActionInput(name = "soundId", label = "@text/actionInputSoundIdLabel", description = "@text/actionInputSoundIdDesc") int soundId) {
67 EcovacsVacuumHandler handler = this.handler;
68 if (handler != null) {
69 handler.playSound(new PlaySoundCommand(soundId));
73 public static void playSound(@Nullable ThingActions actions, String type) {
74 if (actions instanceof EcovacsVacuumActions action) {
75 action.playSound(type);
79 public static void playSoundWithId(@Nullable ThingActions actions, int soundId) {
80 if (actions instanceof EcovacsVacuumActions action) {
81 action.playSoundWithId(soundId);