Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[boschindego] Provide faster channel updates #13192

Merged
merged 4 commits into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions bundles/org.openhab.binding.boschindego/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ His [Java Library](https://github.com/zazaz-de/iot-device-bosch-indego-controlle

Currently the binding supports ***indego*** mowers as a thing type with these configuration parameters:

| Parameter | Description | Default |
|--------------------|-----------------------------------------------------------------|---------|
| username | Username for the Bosch Indego account | |
| password | Password for the Bosch Indego account | |
| refresh | The number of seconds between refreshing device state | 180 |
| cuttingTimeRefresh | The number of minutes between refreshing last/next cutting time | 60 |
| Parameter | Description | Default |
|--------------------|-------------------------------------------------------------------|---------|
| username | Username for the Bosch Indego account | |
| password | Password for the Bosch Indego account | |
| refresh | The number of seconds between refreshing device state when idle | 180 |
| stateActiveRefresh | The number of seconds between refreshing device state when active | 30 |
| cuttingTimeRefresh | The number of minutes between refreshing last/next cutting time | 60 |

## Channels

Expand All @@ -27,12 +28,15 @@ Currently the binding supports ***indego*** mowers as a thing type with these
| mowed | Dimmer | Cut grass in percent | |
| lastCutting | DateTime | Last cutting time | |
| nextCutting | DateTime | Next scheduled cutting time | |
| batteryVoltage | Number:ElectricPotential | Battery voltage reported by the device | |
| batteryLevel | Number | Battery level as a percentage (0-100%) | |
| lowBattery | Switch | Low battery warning with possible values on (low battery) and off (battery ok) | |
| batteryTemperature | Number:Temperature | Battery temperature reported by the device | |
| batteryVoltage | Number:ElectricPotential | Battery voltage reported by the device [^1] | |
| batteryLevel | Number | Battery level as a percentage (0-100%) [^1] | |
| lowBattery | Switch | Low battery warning with possible values on (low battery) and off (battery ok) [^1] | |
| batteryTemperature | Number:Temperature | Battery temperature reported by the device [^1] | |
| gardenSize | Number:Area | Garden size mapped by the device | |
| gardenMap | Image | Garden map mapped by the device | |
| gardenMap | Image | Garden map created by the device [^2] | |

[^1]: This will be updated every six hours when the device is idle. It will wake up the device, which can include turning on its display. When the device is active or charging, this will be updated every two minutes.
[^2]: This will be updated as often as specified by the `stateActiveRefresh` thing parameter.

### State Codes

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.boschindego.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* {@link DeviceStateAttribute} describes a characteristic for a device state.
*
* @author Jacob Laursen - Initial contribution
*/
@NonNullByDefault
public enum DeviceStateAttribute {
READY_TO_MOW,
DOCKED,
CHARGING,
ACTIVE,
COMPLETED
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static java.util.Map.entry;

import java.util.EnumSet;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand All @@ -22,59 +23,90 @@

/**
* {@link DeviceStatus} describes status codes from the device with corresponding
* ready state and associated command.
* characteristics and associated command.
*
* @author Jacob Laursen - Initial contribution
*/
@NonNullByDefault
public class DeviceStatus {

public static final int STATE_LEARNING_LAWN = 516;

private final static String STATE_PREFIX = "indego.state.";
private final static String STATE_UNKNOWN = "unknown";
private static final String STATE_PREFIX = "indego.state.";
private static final String STATE_UNKNOWN = "unknown";

private static final Map<Integer, DeviceStatus> STATUS_MAP = Map.ofEntries(
entry(0, new DeviceStatus("reading-status", false, DeviceCommand.RETURN)),
entry(257, new DeviceStatus("charging", false, DeviceCommand.RETURN)),
entry(258, new DeviceStatus("docked", true, DeviceCommand.RETURN)),
entry(259, new DeviceStatus("docked-software-update", false, DeviceCommand.RETURN)),
entry(260, new DeviceStatus("docked", true, DeviceCommand.RETURN)),
entry(261, new DeviceStatus("docked", true, DeviceCommand.RETURN)),
entry(262, new DeviceStatus("docked-loading-map", false, DeviceCommand.MOW)),
entry(263, new DeviceStatus("docked-saving-map", false, DeviceCommand.RETURN)),
entry(266, new DeviceStatus("leaving-dock", false, DeviceCommand.MOW)),
entry(513, new DeviceStatus("mowing", false, DeviceCommand.MOW)),
entry(514, new DeviceStatus("relocalising", false, DeviceCommand.MOW)),
entry(515, new DeviceStatus("loading-map", false, DeviceCommand.MOW)),
entry(STATE_LEARNING_LAWN, new DeviceStatus("learning-lawn", false, DeviceCommand.MOW)),
entry(517, new DeviceStatus("paused", true, DeviceCommand.PAUSE)),
entry(518, new DeviceStatus("border-cut", false, DeviceCommand.MOW)),
entry(519, new DeviceStatus("idle-in-lawn", true, DeviceCommand.MOW)),
entry(523, new DeviceStatus("spotmow", false, DeviceCommand.MOW)),
entry(769, new DeviceStatus("returning-to-dock", false, DeviceCommand.RETURN)),
entry(770, new DeviceStatus("returning-to-dock", false, DeviceCommand.RETURN)),
entry(771, new DeviceStatus("returning-to-dock-battery-low", false, DeviceCommand.RETURN)),
entry(772, new DeviceStatus("returning-to-dock-calendar-timeslot-ended", false, DeviceCommand.RETURN)),
entry(773, new DeviceStatus("returning-to-dock-battery-temp-range", false, DeviceCommand.RETURN)),
entry(774, new DeviceStatus("returning-to-dock", false, DeviceCommand.RETURN)),
entry(775, new DeviceStatus("returning-to-dock-lawn-complete", false, DeviceCommand.RETURN)),
entry(776, new DeviceStatus("returning-to-dock-relocalising", false, DeviceCommand.RETURN)),
entry(1025, new DeviceStatus("diagnostic-mode", false, null)),
entry(1026, new DeviceStatus("end-of-life", false, null)),
entry(1281, new DeviceStatus("software-update", false, null)),
entry(1537, new DeviceStatus("energy-save-mode", true, DeviceCommand.RETURN)),
entry(64513, new DeviceStatus("docked", true, DeviceCommand.RETURN)));
entry(0, new DeviceStatus("reading-status", EnumSet.noneOf(DeviceStateAttribute.class),
DeviceCommand.RETURN)),
entry(257,
new DeviceStatus("charging", EnumSet.of(DeviceStateAttribute.DOCKED, DeviceStateAttribute.CHARGING),
DeviceCommand.RETURN)),
entry(258, new DeviceStatus("docked",
EnumSet.of(DeviceStateAttribute.DOCKED, DeviceStateAttribute.READY_TO_MOW), DeviceCommand.RETURN)),
entry(259,
new DeviceStatus("docked-software-update", EnumSet.of(DeviceStateAttribute.DOCKED),
DeviceCommand.RETURN)),
entry(260, new DeviceStatus("docked",
EnumSet.of(DeviceStateAttribute.DOCKED, DeviceStateAttribute.READY_TO_MOW), DeviceCommand.RETURN)),
entry(261, new DeviceStatus("docked",
EnumSet.of(DeviceStateAttribute.DOCKED, DeviceStateAttribute.READY_TO_MOW), DeviceCommand.RETURN)),
entry(262,
new DeviceStatus("docked-loading-map",
EnumSet.of(DeviceStateAttribute.DOCKED, DeviceStateAttribute.ACTIVE), DeviceCommand.MOW)),
entry(263, new DeviceStatus("docked-saving-map",
EnumSet.of(DeviceStateAttribute.DOCKED, DeviceStateAttribute.ACTIVE), DeviceCommand.RETURN)),
entry(266,
new DeviceStatus("leaving-dock",
EnumSet.of(DeviceStateAttribute.DOCKED, DeviceStateAttribute.ACTIVE), DeviceCommand.MOW)),
entry(513, new DeviceStatus("mowing", EnumSet.of(DeviceStateAttribute.ACTIVE), DeviceCommand.MOW)),
entry(514, new DeviceStatus("relocalising", EnumSet.of(DeviceStateAttribute.ACTIVE), DeviceCommand.MOW)),
entry(515, new DeviceStatus("loading-map", EnumSet.noneOf(DeviceStateAttribute.class), DeviceCommand.MOW)),
entry(516, new DeviceStatus("learning-lawn", EnumSet.of(DeviceStateAttribute.ACTIVE), DeviceCommand.MOW)),
entry(517, new DeviceStatus("paused", EnumSet.of(DeviceStateAttribute.READY_TO_MOW), DeviceCommand.PAUSE)),
entry(518, new DeviceStatus("border-cut", EnumSet.of(DeviceStateAttribute.ACTIVE), DeviceCommand.MOW)),
entry(519,
new DeviceStatus("idle-in-lawn", EnumSet.of(DeviceStateAttribute.READY_TO_MOW), DeviceCommand.MOW)),
entry(523, new DeviceStatus("spotmow", EnumSet.of(DeviceStateAttribute.ACTIVE), DeviceCommand.MOW)),
entry(769,
new DeviceStatus("returning-to-dock", EnumSet.of(DeviceStateAttribute.ACTIVE),
DeviceCommand.RETURN)),
entry(770,
new DeviceStatus("returning-to-dock", EnumSet.of(DeviceStateAttribute.ACTIVE),
DeviceCommand.RETURN)),
entry(771,
new DeviceStatus("returning-to-dock-battery-low", EnumSet.of(DeviceStateAttribute.ACTIVE),
DeviceCommand.RETURN)),
entry(772,
new DeviceStatus("returning-to-dock-calendar-timeslot-ended",
EnumSet.of(DeviceStateAttribute.ACTIVE), DeviceCommand.RETURN)),
entry(773,
new DeviceStatus("returning-to-dock-battery-temp-range", EnumSet.of(DeviceStateAttribute.ACTIVE),
DeviceCommand.RETURN)),
entry(774,
new DeviceStatus("returning-to-dock", EnumSet.of(DeviceStateAttribute.ACTIVE),
DeviceCommand.RETURN)),
entry(775, new DeviceStatus("returning-to-dock-lawn-complete",
EnumSet.of(DeviceStateAttribute.ACTIVE, DeviceStateAttribute.COMPLETED), DeviceCommand.RETURN)),
entry(776,
new DeviceStatus("returning-to-dock-relocalising", EnumSet.of(DeviceStateAttribute.ACTIVE),
DeviceCommand.RETURN)),
entry(1025, new DeviceStatus("diagnostic-mode", EnumSet.noneOf(DeviceStateAttribute.class), null)),
entry(1026, new DeviceStatus("end-of-life", EnumSet.noneOf(DeviceStateAttribute.class), null)),
entry(1281, new DeviceStatus("software-update", EnumSet.noneOf(DeviceStateAttribute.class), null)),
entry(1537,
new DeviceStatus("energy-save-mode", EnumSet.of(DeviceStateAttribute.READY_TO_MOW),
DeviceCommand.RETURN)),
entry(64513, new DeviceStatus("docked",
EnumSet.of(DeviceStateAttribute.DOCKED, DeviceStateAttribute.READY_TO_MOW), DeviceCommand.RETURN)));

private String textKey;

private boolean isReadyToMow;
private EnumSet<DeviceStateAttribute> attributes;

private @Nullable DeviceCommand associatedCommand;

private DeviceStatus(String textKey, boolean isReadyToMow, @Nullable DeviceCommand associatedCommand) {
private DeviceStatus(String textKey, EnumSet<DeviceStateAttribute> attributes,
@Nullable DeviceCommand associatedCommand) {
this.textKey = textKey;
this.isReadyToMow = isReadyToMow;
this.attributes = attributes;
this.associatedCommand = associatedCommand;
}

Expand All @@ -91,19 +123,22 @@ public static DeviceStatus fromCode(int code) {
}

DeviceCommand command = null;
EnumSet<DeviceStateAttribute> attributes = EnumSet.noneOf(DeviceStateAttribute.class);
switch (code & 0xff00) {
case 0x100:
command = DeviceCommand.RETURN;
break;
case 0x200:
command = DeviceCommand.MOW;
attributes.add(DeviceStateAttribute.ACTIVE);
break;
case 0x300:
command = DeviceCommand.RETURN;
attributes.add(DeviceStateAttribute.ACTIVE);
break;
}

return new DeviceStatus(String.valueOf(code), false, command);
return new DeviceStatus(String.valueOf(code), attributes, command);
}

/**
Expand All @@ -121,7 +156,23 @@ public String getMessage(BoschIndegoTranslationProvider translationProvider) {
}

public boolean isReadyToMow() {
return isReadyToMow;
return attributes.contains(DeviceStateAttribute.READY_TO_MOW);
}

public boolean isActive() {
return attributes.contains(DeviceStateAttribute.ACTIVE);
}

public boolean isCharging() {
return attributes.contains(DeviceStateAttribute.CHARGING);
}

public boolean isDocked() {
return attributes.contains(DeviceStateAttribute.DOCKED);
}

public boolean isCompleted() {
return attributes.contains(DeviceStateAttribute.COMPLETED);
}

public @Nullable DeviceCommand getAssociatedCommand() {
Expand Down
Loading