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