]> git.basschouten.com Git - openhab-addons.git/blob
36725293ca0c0ff4ee90494158c28dcb9257067b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.ecovacs.internal.api.commands;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.ecovacs.internal.api.impl.ProtocolVersion;
18 import org.w3c.dom.Document;
19 import org.w3c.dom.Element;
20
21 import com.google.gson.JsonElement;
22 import com.google.gson.JsonObject;
23
24 /**
25  * @author Danny Baumann - Initial contribution
26  */
27 @NonNullByDefault
28 public class PlaySoundCommand extends AbstractNoResponseCommand {
29     public enum SoundType {
30         STARTUP(0),
31         SUSPENDED(3),
32         CHECK_WHEELS(4),
33         HELP_ME_OUT(5),
34         INSTALL_DUST_BIN(6),
35         BEEP(17),
36         BATTERY_LOW(18),
37         POWER_ON_BEFORE_CHARGE(29),
38         I_AM_HERE(30),
39         PLEASE_CLEAN_BRUSH(31),
40         PLEASE_CLEAN_SENSORS(35),
41         BRUSH_IS_TANGLED(48),
42         RELOCATING(55),
43         UPGRADE_DONE(56),
44         RETURNING_TO_CHARGE(63),
45         CLEANING_PAUSED(65),
46         CONNECTED_IN_SETUP(69),
47         RESTORING_MAP(71),
48         BATTERY_LOW_RETURNING_TO_DOCK(73),
49         DIFFICULT_TO_LOCATE(74),
50         RESUMING_CLEANING(75),
51         UPGRADE_FAILED(76),
52         PLACE_ON_CHARGING_DOCK(77),
53         RESUME_CLEANING(79),
54         STARTING_CLEANING(80),
55         READY_FOR_MOPPING(84),
56         REMOVE_MOPPING_PLATE(85),
57         CLEANING_COMPLETE(86),
58         LDS_MALFUNCTION(89),
59         UPGRADING(90);
60
61         final int id;
62
63         private SoundType(int id) {
64             this.id = id;
65         }
66     }
67
68     private final int soundId;
69
70     public PlaySoundCommand(SoundType type) {
71         super();
72         this.soundId = type.id;
73     }
74
75     public PlaySoundCommand(int soundId) {
76         super();
77         this.soundId = soundId;
78     }
79
80     @Override
81     public String getName(ProtocolVersion version) {
82         return version == ProtocolVersion.XML ? "PlaySound" : "playSound";
83     }
84
85     @Override
86     protected void applyXmlPayload(Document doc, Element ctl) {
87         ctl.setAttribute("sid", String.valueOf(soundId));
88     }
89
90     @Override
91     protected @Nullable JsonElement getJsonPayloadArgs(ProtocolVersion version) {
92         JsonObject args = new JsonObject();
93         args.addProperty("sid", soundId);
94         return args;
95     }
96 }