]> git.basschouten.com Git - openhab-addons.git/blob
de1070c075a4aa657b446b960d0fe24abf889cb3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.automower.internal.things;
14
15 import java.util.EnumSet;
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.Optional;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.core.thing.ChannelUID;
22
23 /**
24  * @author Markus Pfleger - Initial contribution
25  */
26 @NonNullByDefault
27 public enum AutomowerCommand {
28     START("Start", "mower#start"),
29     RESUME_SCHEDULE("ResumeSchedule", "mower#resume_schedule"),
30     PAUSE("Pause", "mower#pause"),
31     PARK("Park", "mower#park"),
32     PARK_UNTIL_NEXT_SCHEDULE("ParkUntilNextSchedule", "mower#park_until_next_schedule"),
33     PARK_UNTIL_FURTHER_NOTICE("ParkUntilFurtherNotice", "mower#park_until_further_notice");
34
35     private static final Map<String, AutomowerCommand> CHANNEL_TO_CMD_MAP = new HashMap<>();
36
37     static {
38         EnumSet.allOf(AutomowerCommand.class).forEach(cmd -> CHANNEL_TO_CMD_MAP.put(cmd.getChannel(), cmd));
39     }
40
41     private final String command;
42     private final String channel;
43
44     AutomowerCommand(String command, String channel) {
45         this.command = command;
46         this.channel = channel;
47     }
48
49     public static Optional<AutomowerCommand> fromChannelUID(ChannelUID channelUID) {
50         return Optional.ofNullable(CHANNEL_TO_CMD_MAP.get(channelUID.getId()));
51     }
52
53     public String getCommand() {
54         return command;
55     }
56
57     public String getChannel() {
58         return channel;
59     }
60 }