[automower] Support for GPS coordinates provided by API (#11323)

* Added support for the 50 GPS waypoints provided by the Automower API

Signed-off-by: Bernhard Bauer <bern77@gmail.com>

* Added Channel for last position

Signed-off-by: Bernhard Bauer <bern77@gmail.com>

* Fixed channel of position 40

Signed-off-by: Bernhard Bauer <bern77@gmail.com>

* Updated Doku + mvn:spotless apply

Signed-off-by: Bernhard Bauer <bern77@gmail.com>

* Inputs from static code analysis

Signed-off-by: Bernhard Bauer <bern77@gmail.com>

* Removed channel groups

Signed-off-by: Bernhard Bauer <bern77@gmail.com>

* mvn spotless:apply

Signed-off-by: Bernhard Bauer <bern77@gmail.com>
This commit is contained in:
Bernhard Bauer
2021-10-30 13:14:24 +02:00
committed by GitHub
parent ad54da1638
commit a7ec511dca
7 changed files with 283 additions and 51 deletions

View File

@@ -12,6 +12,9 @@
*/
package org.openhab.binding.automower.internal;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;
@@ -31,26 +34,54 @@ public class AutomowerBindingConstants {
// generic thing types
public static final ThingTypeUID THING_TYPE_AUTOMOWER = new ThingTypeUID(BINDING_ID, "automower");
// List of all Channel ids
public static final String CHANNEL_STATUS_NAME = "name";
public static final String CHANNEL_STATUS_MODE = "mode";
public static final String CHANNEL_STATUS_ACTIVITY = "activity";
public static final String CHANNEL_STATUS_STATE = "state";
public static final String CHANNEL_STATUS_LAST_UPDATE = "last-update";
public static final String CHANNEL_STATUS_BATTERY = "battery";
public static final String CHANNEL_STATUS_ERROR_CODE = "error-code";
public static final String CHANNEL_STATUS_ERROR_TIMESTAMP = "error-timestamp";
public static final String CHANNEL_PLANNER_NEXT_START = "planner-next-start";
public static final String CHANNEL_PLANNER_OVERRIDE_ACTION = "planner-override-action";
public static final String CHANNEL_CALENDAR_TASKS = "calendar-tasks";
// List of all status Channel ids
public static final String GROUP_STATUS = ""; // no channel group in use at the moment, we'll possibly introduce
// this in a future release
public static final String CHANNEL_STATUS_NAME = GROUP_STATUS + "name";
public static final String CHANNEL_STATUS_MODE = GROUP_STATUS + "mode";
public static final String CHANNEL_STATUS_ACTIVITY = GROUP_STATUS + "activity";
public static final String CHANNEL_STATUS_STATE = GROUP_STATUS + "state";
public static final String CHANNEL_STATUS_LAST_UPDATE = GROUP_STATUS + "last-update";
public static final String CHANNEL_STATUS_BATTERY = GROUP_STATUS + "battery";
public static final String CHANNEL_STATUS_ERROR_CODE = GROUP_STATUS + "error-code";
public static final String CHANNEL_STATUS_ERROR_TIMESTAMP = GROUP_STATUS + "error-timestamp";
public static final String CHANNEL_PLANNER_NEXT_START = GROUP_STATUS + "planner-next-start";
public static final String CHANNEL_PLANNER_OVERRIDE_ACTION = GROUP_STATUS + "planner-override-action";
public static final String CHANNEL_CALENDAR_TASKS = GROUP_STATUS + "calendar-tasks";
// Command channels
public static final String CHANNEL_COMMAND_START = "start";
public static final String CHANNEL_COMMAND_RESUME_SCHEDULE = "resume_schedule";
public static final String CHANNEL_COMMAND_PAUSE = "pause";
public static final String CHANNEL_COMMAND_PARK = "park";
public static final String CHANNEL_COMMAND_PARK_UNTIL_NEXT_SCHEDULE = "park_until_next_schedule";
public static final String CHANNEL_COMMAND_PARK_UNTIL_NOTICE = "park_until_further_notice";
// Position Channels ids
public static final String GROUP_POSITIONS = ""; // no channel group in use at the moment, we'll possibly
// introduce
// this in a future release
public static final String LAST_POSITION = GROUP_POSITIONS + "last-position";
public static final ArrayList<String> CHANNEL_POSITIONS = new ArrayList<String>(
List.of(GROUP_POSITIONS + "position01", GROUP_POSITIONS + "position02", GROUP_POSITIONS + "position03",
GROUP_POSITIONS + "position04", GROUP_POSITIONS + "position05", GROUP_POSITIONS + "position06",
GROUP_POSITIONS + "position07", GROUP_POSITIONS + "position08", GROUP_POSITIONS + "position09",
GROUP_POSITIONS + "position10", GROUP_POSITIONS + "position11", GROUP_POSITIONS + "position12",
GROUP_POSITIONS + "position13", GROUP_POSITIONS + "position14", GROUP_POSITIONS + "position15",
GROUP_POSITIONS + "position16", GROUP_POSITIONS + "position17", GROUP_POSITIONS + "position18",
GROUP_POSITIONS + "position19", GROUP_POSITIONS + "position20", GROUP_POSITIONS + "position21",
GROUP_POSITIONS + "position22", GROUP_POSITIONS + "position23", GROUP_POSITIONS + "position24",
GROUP_POSITIONS + "position25", GROUP_POSITIONS + "position26", GROUP_POSITIONS + "position27",
GROUP_POSITIONS + "position28", GROUP_POSITIONS + "position29", GROUP_POSITIONS + "position30",
GROUP_POSITIONS + "position31", GROUP_POSITIONS + "position32", GROUP_POSITIONS + "position33",
GROUP_POSITIONS + "position34", GROUP_POSITIONS + "position35", GROUP_POSITIONS + "position36",
GROUP_POSITIONS + "position37", GROUP_POSITIONS + "position38", GROUP_POSITIONS + "position39",
GROUP_POSITIONS + "position40", GROUP_POSITIONS + "position41", GROUP_POSITIONS + "position42",
GROUP_POSITIONS + "position43", GROUP_POSITIONS + "position44", GROUP_POSITIONS + "position45",
GROUP_POSITIONS + "position46", GROUP_POSITIONS + "position47", GROUP_POSITIONS + "position48",
GROUP_POSITIONS + "position49", GROUP_POSITIONS + "position50"));
// Command Channel ids
public static final String GROUP_COMMANDS = ""; // no channel group in use at the moment, we'll possibly introduce
// this in a future release
public static final String CHANNEL_COMMAND_START = GROUP_COMMANDS + "start";
public static final String CHANNEL_COMMAND_RESUME_SCHEDULE = GROUP_COMMANDS + "resume_schedule";
public static final String CHANNEL_COMMAND_PAUSE = GROUP_COMMANDS + "pause";
public static final String CHANNEL_COMMAND_PARK = GROUP_COMMANDS + "park";
public static final String CHANNEL_COMMAND_PARK_UNTIL_NEXT_SCHEDULE = GROUP_COMMANDS + "park_until_next_schedule";
public static final String CHANNEL_COMMAND_PARK_UNTIL_NOTICE = GROUP_COMMANDS + "park_until_further_notice";
// Automower properties
public static final String AUTOMOWER_ID = "mowerId";

View File

@@ -12,6 +12,8 @@
*/
package org.openhab.binding.automower.internal.rest.api.automowerconnect.dto;
import java.util.ArrayList;
/**
* @author Markus Pfleger - Initial contribution
*/
@@ -22,6 +24,7 @@ public class MowerData {
private Calendar calendar;
private Planner planner;
private Metadata metadata;
private ArrayList<Position> positions = new ArrayList<Position>();
public System getSystem() {
return system;
@@ -70,4 +73,16 @@ public class MowerData {
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
public void addPosition(Position position) {
this.positions.add(position);
}
public ArrayList<Position> getPositions() {
return this.positions;
}
public Position getLastPosition() {
return !this.positions.isEmpty() ? this.positions.get(0) : null;
}
}

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2010-2021 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.automower.internal.rest.api.automowerconnect.dto;
/**
* @author Bernhard Bauer - Initial contribution
*/
public class Position {
private double latitude;
private double longitude;
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
}

View File

@@ -17,11 +17,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ChannelUID;
/**
* @author Markus Pfleger - Initial contribution
*/
@NonNullByDefault
public enum AutomowerCommand {
START("Start", "mower#start"),
RESUME_SCHEDULE("ResumeSchedule", "mower#resume_schedule"),

View File

@@ -16,6 +16,7 @@ import static org.openhab.binding.automower.internal.AutomowerBindingConstants.*
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -34,12 +35,14 @@ import org.openhab.binding.automower.internal.actions.AutomowerActions;
import org.openhab.binding.automower.internal.bridge.AutomowerBridge;
import org.openhab.binding.automower.internal.bridge.AutomowerBridgeHandler;
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.Mower;
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.Position;
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.RestrictedReason;
import org.openhab.binding.automower.internal.rest.api.automowerconnect.dto.State;
import org.openhab.binding.automower.internal.rest.exceptions.AutomowerCommunicationException;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.PointType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units;
@@ -313,6 +316,16 @@ public class AutomowerHandler extends BaseThingHandler {
updateState(CHANNEL_CALENDAR_TASKS,
new StringType(gson.toJson(mower.getAttributes().getCalendar().getTasks())));
updateState(LAST_POSITION,
new PointType(new DecimalType(mower.getAttributes().getLastPosition().getLatitude()),
new DecimalType(mower.getAttributes().getLastPosition().getLongitude())));
ArrayList<Position> positions = mower.getAttributes().getPositions();
for (int i = 0; i < positions.size(); i++) {
updateState(CHANNEL_POSITIONS.get(i), new PointType(new DecimalType(positions.get(i).getLatitude()),
new DecimalType(positions.get(i).getLongitude())));
}
}
}

View File

@@ -45,6 +45,7 @@
<description>An automatic lawn mower</description>
<channels>
<!-- Status -->
<channel id="name" typeId="nameType"/>
<channel id="mode" typeId="modeType"/>
<channel id="activity" typeId="activityType"/>
@@ -56,12 +57,68 @@
<channel id="planner-next-start" typeId="plannerNextStartTimestampType"/>
<channel id="planner-override-action" typeId="plannerOverrideActionType"/>
<channel id="calendar-tasks" typeId="calendarTasksType"/>
<!-- Commands -->
<channel id="start" typeId="start"/>
<channel id="resume_schedule" typeId="resumeSchedule"/>
<channel id="pause" typeId="pause"/>
<channel id="park" typeId="park"/>
<channel id="park_until_next_schedule" typeId="parkUntilNextSchedule"/>
<channel id="park_until_further_notice" typeId="parkUntilFurtherNotice"/>
<!-- Positions -->
<channel id="last-position" typeId="positionType">
<description>Last Position</description>
</channel>
<channel id="position01" typeId="positionType"/>
<channel id="position02" typeId="positionType"/>
<channel id="position03" typeId="positionType"/>
<channel id="position04" typeId="positionType"/>
<channel id="position05" typeId="positionType"/>
<channel id="position06" typeId="positionType"/>
<channel id="position07" typeId="positionType"/>
<channel id="position08" typeId="positionType"/>
<channel id="position09" typeId="positionType"/>
<channel id="position10" typeId="positionType"/>
<channel id="position11" typeId="positionType"/>
<channel id="position12" typeId="positionType"/>
<channel id="position13" typeId="positionType"/>
<channel id="position14" typeId="positionType"/>
<channel id="position15" typeId="positionType"/>
<channel id="position16" typeId="positionType"/>
<channel id="position17" typeId="positionType"/>
<channel id="position18" typeId="positionType"/>
<channel id="position19" typeId="positionType"/>
<channel id="position20" typeId="positionType"/>
<channel id="position21" typeId="positionType"/>
<channel id="position22" typeId="positionType"/>
<channel id="position23" typeId="positionType"/>
<channel id="position24" typeId="positionType"/>
<channel id="position25" typeId="positionType"/>
<channel id="position26" typeId="positionType"/>
<channel id="position27" typeId="positionType"/>
<channel id="position28" typeId="positionType"/>
<channel id="position29" typeId="positionType"/>
<channel id="position30" typeId="positionType"/>
<channel id="position31" typeId="positionType"/>
<channel id="position32" typeId="positionType"/>
<channel id="position33" typeId="positionType"/>
<channel id="position34" typeId="positionType"/>
<channel id="position35" typeId="positionType"/>
<channel id="position36" typeId="positionType"/>
<channel id="position37" typeId="positionType"/>
<channel id="position38" typeId="positionType"/>
<channel id="position39" typeId="positionType"/>
<channel id="position40" typeId="positionType"/>
<channel id="position41" typeId="positionType"/>
<channel id="position42" typeId="positionType"/>
<channel id="position43" typeId="positionType"/>
<channel id="position44" typeId="positionType"/>
<channel id="position45" typeId="positionType"/>
<channel id="position46" typeId="positionType"/>
<channel id="position47" typeId="positionType"/>
<channel id="position48" typeId="positionType"/>
<channel id="position49" typeId="positionType"/>
<channel id="position50" typeId="positionType"/>
</channels>
<properties>
@@ -85,6 +142,7 @@
</thing-type>
<channel-type id="nameType">
<item-type>String</item-type>
<label>Automower Name</label>
@@ -201,6 +259,13 @@
<state readOnly="true"/>
</channel-type>
<channel-type id="positionType">
<item-type>Point</item-type>
<label>GPS Position</label>
<description>The channel providing a waypoint of the mower's activity.</description>
<state readOnly="true"/>
</channel-type>
<channel-type id="start">
<item-type>Number</item-type>
<label>Start with Duration</label>