Skip to content

Commit 1aa3af4

Browse files
authored
[worxlandroid] Fix NumberFormatException when sending a Command to mode Channel (#21331)
* [worxlandroid] Fix NumberFormatException when sending a Command to mode Channel Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
1 parent decf433 commit 1aa3af4

3 files changed

Lines changed: 49 additions & 10 deletions

File tree

bundles/org.openhab.binding.worxlandroid/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ As second step you are able to set time in percent and split in parts of 10 betw
9898

9999
### Schedule
100100

101-
| Channel | Type | ChannelName | |
102-
|----------------|----------|-------------------------|-------------------|
103-
| mode | String | schedule#mode | ONLY IF SUPPORTED |
104-
| time-extension | Number | schedule#time-extension | |
105-
| next-start | DateTime | schedule#next-start | |
106-
| next-stop | DateTime | schedule#next-stop | |
101+
| Channel | Type | ChannelName | |
102+
|----------------|----------|-------------------------|----------------------|
103+
| mode | String | schedule#mode | *1 ONLY IF SUPPORTED |
104+
| time-extension | Number | schedule#time-extension | |
105+
| next-start | DateTime | schedule#next-start | |
106+
| next-stop | DateTime | schedule#next-stop | |
107+
108+
*1: Commands for **mode** Channel: Normal, Party.
107109

108110
### Aws
109111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2010-2026 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.worxlandroid.internal.codes;
14+
15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
17+
/**
18+
* The {@link WorxLandroidModeCodes} hosts mode codes.
19+
*
20+
* @author Christoph Weitkamp - Initial contribution
21+
*/
22+
@NonNullByDefault
23+
public enum WorxLandroidModeCodes {
24+
NORMAL(1, "Normal"),
25+
PARTY(2, "Party");
26+
27+
public final int code;
28+
public final String description;
29+
30+
WorxLandroidModeCodes(int code, String description) {
31+
this.code = code;
32+
this.description = description;
33+
}
34+
}

bundles/org.openhab.binding.worxlandroid/src/main/java/org/openhab/binding/worxlandroid/internal/handler/WorxLandroidMowerHandler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.openhab.binding.worxlandroid.internal.api.dto.ProductItemStatus;
4848
import org.openhab.binding.worxlandroid.internal.codes.WorxLandroidActionCodes;
4949
import org.openhab.binding.worxlandroid.internal.codes.WorxLandroidDayCodes;
50+
import org.openhab.binding.worxlandroid.internal.codes.WorxLandroidModeCodes;
5051
import org.openhab.binding.worxlandroid.internal.codes.WorxLandroidStatusCodes;
5152
import org.openhab.binding.worxlandroid.internal.config.MowerConfiguration;
5253
import org.openhab.binding.worxlandroid.internal.vo.Mower;
@@ -241,7 +242,7 @@ protected void internalHandleCommand(@Nullable String groupId, String channelId,
241242
} else if (GROUP_AWS.equals(groupId)) {
242243
handleAWSCommand(theMower, channelId);
243244
} else if (GROUP_SCHEDULE.equals(groupId)) {
244-
handleScheduleCommand(theMower, channelId, Integer.parseInt(command.toString()));
245+
handleScheduleCommand(theMower, channelId, command);
245246
} else if (GROUP_ONE_TIME.equals(groupId)) {
246247
handleOneTimeSchedule(theMower, channelId, command);
247248
} else if (GROUP_COMMON.equals(groupId)) {
@@ -302,11 +303,13 @@ private void handleOneTimeSchedule(Mower theMower, String channel, Command comma
302303
}
303304
}
304305

305-
private void handleScheduleCommand(Mower theMower, String channel, int command) {
306+
private void handleScheduleCommand(Mower theMower, String channel, Command command) {
306307
if (CHANNEL_MODE.equals(channel)) {
307-
sendCommand(theMower, new ScheduleCommand(command));
308+
WorxLandroidModeCodes modeCode = WorxLandroidModeCodes.valueOf(command.toString().toUpperCase(Locale.ROOT));
309+
sendCommand(theMower, new ScheduleCommand(modeCode.code));
308310
} else if (CHANNEL_TIME_EXTENSION.equals(channel)) {
309-
theMower.setTimeExtension(command);
311+
int timeExtension = Integer.parseInt(command.toString());
312+
theMower.setTimeExtension(timeExtension);
310313
sendCommand(theMower,
311314
theMower.scheduler2Supported()
312315
? new ScheduleDaysCommand(theMower.getTimeExtension(), theMower.getScheduleArray1(),

0 commit comments

Comments
 (0)