2 * Copyright (c) 2010-2022 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.boschindego.internal;
15 import static java.util.Map.entry;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.boschindego.internal.dto.DeviceCommand;
24 * {@link DeviceStatus} describes status codes from the device with corresponding
25 * ready state and associated command.
27 * @author Jacob Laursen - Initial contribution
30 public class DeviceStatus {
32 private static final Map<Integer, DeviceStatus> STATUS_MAP = Map.ofEntries(
33 entry(0, new DeviceStatus("Reading status", false, DeviceCommand.RETURN)),
34 entry(257, new DeviceStatus("Charging", false, DeviceCommand.RETURN)),
35 entry(258, new DeviceStatus("Docked", true, DeviceCommand.RETURN)),
36 entry(259, new DeviceStatus("Docked - Software update", false, DeviceCommand.RETURN)),
37 entry(260, new DeviceStatus("Docked", true, DeviceCommand.RETURN)),
38 entry(261, new DeviceStatus("Docked", true, DeviceCommand.RETURN)),
39 entry(262, new DeviceStatus("Docked - Loading map", false, DeviceCommand.MOW)),
40 entry(263, new DeviceStatus("Docked - Saving map", false, DeviceCommand.RETURN)),
41 entry(513, new DeviceStatus("Mowing", false, DeviceCommand.MOW)),
42 entry(514, new DeviceStatus("Relocalising", false, DeviceCommand.MOW)),
43 entry(515, new DeviceStatus("Loading map", false, DeviceCommand.MOW)),
44 entry(516, new DeviceStatus("Learning lawn", false, DeviceCommand.MOW)),
45 entry(517, new DeviceStatus("Paused", true, DeviceCommand.PAUSE)),
46 entry(518, new DeviceStatus("Border cut", false, DeviceCommand.MOW)),
47 entry(519, new DeviceStatus("Idle in lawn", true, DeviceCommand.MOW)),
48 entry(769, new DeviceStatus("Returning to dock", false, DeviceCommand.RETURN)),
49 entry(770, new DeviceStatus("Returning to dock", false, DeviceCommand.RETURN)),
50 entry(771, new DeviceStatus("Returning to dock - Battery low", false, DeviceCommand.RETURN)),
51 entry(772, new DeviceStatus("Returning to dock - Calendar timeslot ended", false, DeviceCommand.RETURN)),
52 entry(773, new DeviceStatus("Returning to dock - Battery temp range", false, DeviceCommand.RETURN)),
53 entry(774, new DeviceStatus("Returning to dock", false, DeviceCommand.RETURN)),
54 entry(775, new DeviceStatus("Returning to dock - Lawn complete", false, DeviceCommand.RETURN)),
55 entry(776, new DeviceStatus("Returning to dock - Relocalising", false, DeviceCommand.RETURN)),
56 entry(1025, new DeviceStatus("Diagnostic mode", false, null)),
57 entry(1026, new DeviceStatus("End of life", false, null)),
58 entry(1281, new DeviceStatus("Software update", false, null)),
59 entry(64513, new DeviceStatus("Docked", true, DeviceCommand.RETURN)));
61 private String message;
63 private boolean isReadyToMow;
65 private @Nullable DeviceCommand associatedCommand;
67 private DeviceStatus(String message, boolean isReadyToMow, @Nullable DeviceCommand associatedCommand) {
68 this.message = message;
69 this.isReadyToMow = isReadyToMow;
70 this.associatedCommand = associatedCommand;
74 * Returns a {@link DeviceStatus} instance describing the status code.
76 * @param code the status code
77 * @return the {@link DeviceStatus} providing additional context for the code
79 public static DeviceStatus fromCode(int code) {
80 DeviceStatus status = STATUS_MAP.get(code);
85 DeviceCommand command = null;
86 switch (code & 0xff00) {
88 command = DeviceCommand.RETURN;
91 command = DeviceCommand.MOW;
94 command = DeviceCommand.RETURN;
98 return new DeviceStatus(String.format("Unknown status code %d", code), false, command);
101 public String getMessage() {
105 public boolean isReadyToMow() {
109 public @Nullable DeviceCommand getAssociatedCommand() {
110 return associatedCommand;