mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
bugfix websocket exception (#16962)
Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
f61d4ed3bf
commit
287afde891
@ -110,6 +110,7 @@ import com.google.protobuf.Int32Value;
|
|||||||
* {@link VehicleHandler} transform data into state updates and handling of vehicle commands
|
* {@link VehicleHandler} transform data into state updates and handling of vehicle commands
|
||||||
*
|
*
|
||||||
* @author Bernd Weymann - Initial contribution
|
* @author Bernd Weymann - Initial contribution
|
||||||
|
* @author Bernd Weymann - Bugfix https://github.com/openhab/openhab-addons/issues/16932
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class VehicleHandler extends BaseThingHandler {
|
public class VehicleHandler extends BaseThingHandler {
|
||||||
@ -552,24 +553,33 @@ public class VehicleHandler extends BaseThingHandler {
|
|||||||
public void distributeCommandStatus(AppTwinCommandStatusUpdatesByPID cmdUpdates) {
|
public void distributeCommandStatus(AppTwinCommandStatusUpdatesByPID cmdUpdates) {
|
||||||
Map<Long, AppTwinCommandStatus> updates = cmdUpdates.getUpdatesByPidMap();
|
Map<Long, AppTwinCommandStatus> updates = cmdUpdates.getUpdatesByPidMap();
|
||||||
updates.forEach((key, value) -> {
|
updates.forEach((key, value) -> {
|
||||||
// Command name
|
try {
|
||||||
ChannelStateMap csmCommand = new ChannelStateMap(OH_CHANNEL_CMD_NAME, GROUP_COMMAND,
|
// getting type and state may throw Exception
|
||||||
new DecimalType(value.getType().getNumber()));
|
int commandType = value.getType().getNumber();
|
||||||
updateChannel(csmCommand);
|
int commandState = value.getState().getNumber();
|
||||||
// Command State
|
// Command name
|
||||||
ChannelStateMap csmState = new ChannelStateMap(OH_CHANNEL_CMD_STATE, GROUP_COMMAND,
|
ChannelStateMap csmCommand = new ChannelStateMap(OH_CHANNEL_CMD_NAME, GROUP_COMMAND,
|
||||||
new DecimalType(value.getState().getNumber()));
|
new DecimalType(commandType));
|
||||||
updateChannel(csmState);
|
updateChannel(csmCommand);
|
||||||
// Command Time
|
// Command State
|
||||||
DateTimeType dtt = Utils.getDateTimeType(value.getTimestampInMs());
|
ChannelStateMap csmState = new ChannelStateMap(OH_CHANNEL_CMD_STATE, GROUP_COMMAND,
|
||||||
UOMObserver observer = null;
|
new DecimalType(commandState));
|
||||||
if (Locale.US.getCountry().equals(Utils.getCountry())) {
|
updateChannel(csmState);
|
||||||
observer = new UOMObserver(UOMObserver.TIME_US);
|
// Command Time
|
||||||
} else {
|
DateTimeType dtt = Utils.getDateTimeType(value.getTimestampInMs());
|
||||||
observer = new UOMObserver(UOMObserver.TIME_ROW);
|
UOMObserver observer = null;
|
||||||
|
if (Locale.US.getCountry().equals(Utils.getCountry())) {
|
||||||
|
observer = new UOMObserver(UOMObserver.TIME_US);
|
||||||
|
} else {
|
||||||
|
observer = new UOMObserver(UOMObserver.TIME_ROW);
|
||||||
|
}
|
||||||
|
ChannelStateMap csmUpdated = new ChannelStateMap(OH_CHANNEL_CMD_LAST_UPDATE, GROUP_COMMAND, dtt,
|
||||||
|
observer);
|
||||||
|
updateChannel(csmUpdated);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
logger.trace("Cannot decode command {} {}", value.getAllFields().toString(), iae.getMessage());
|
||||||
|
// silent ignore update
|
||||||
}
|
}
|
||||||
ChannelStateMap csmUpdated = new ChannelStateMap(OH_CHANNEL_CMD_LAST_UPDATE, GROUP_COMMAND, dtt, observer);
|
|
||||||
updateChannel(csmUpdated);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,11 +39,14 @@ import org.openhab.core.thing.link.ItemChannelLinkRegistry;
|
|||||||
import org.openhab.core.types.RefreshType;
|
import org.openhab.core.types.RefreshType;
|
||||||
|
|
||||||
import com.daimler.mbcarkit.proto.VehicleEvents.VEPUpdate;
|
import com.daimler.mbcarkit.proto.VehicleEvents.VEPUpdate;
|
||||||
|
import com.daimler.mbcarkit.proto.Vehicleapi.AppTwinCommandStatus;
|
||||||
|
import com.daimler.mbcarkit.proto.Vehicleapi.AppTwinCommandStatusUpdatesByPID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link VehicleHandlerTest} check state updates and command sending of vehicles
|
* {@link VehicleHandlerTest} check state updates and command sending of vehicles
|
||||||
*
|
*
|
||||||
* @author Bernd Weymann - Initial contribution
|
* @author Bernd Weymann - Initial contribution
|
||||||
|
* @author Bernd Weymann - Additional test for https://github.com/openhab/openhab-addons/issues/16932
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
class VehicleHandlerTest {
|
class VehicleHandlerTest {
|
||||||
@ -468,4 +471,24 @@ class VehicleHandlerTest {
|
|||||||
"Charge Program Command");
|
"Charge Program Command");
|
||||||
assertEquals(100, ahm.getCommand().getInt("max_soc"), "Charge Program SOC Setting");
|
assertEquals(100, ahm.getCommand().getInt("max_soc"), "Charge Program SOC Setting");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
/**
|
||||||
|
* Testing UNRECOGNIZED (-1) values in CommandStatus which throws Exception
|
||||||
|
*/
|
||||||
|
public void testCommandDistribution() {
|
||||||
|
Thing thingMock = mock(Thing.class);
|
||||||
|
when(thingMock.getThingTypeUID()).thenReturn(Constants.THING_TYPE_BEV);
|
||||||
|
when(thingMock.getUID()).thenReturn(new ThingUID("test", Constants.BEV));
|
||||||
|
VehicleHandler vh = new VehicleHandler(thingMock, new LocationProviderMock(),
|
||||||
|
mock(MercedesMeCommandOptionProvider.class), mock(MercedesMeStateOptionProvider.class));
|
||||||
|
AppTwinCommandStatus command = AppTwinCommandStatus.newBuilder().setStateValue(-1).setTypeValue(-1).build();
|
||||||
|
AppTwinCommandStatusUpdatesByPID commandPid = AppTwinCommandStatusUpdatesByPID.newBuilder()
|
||||||
|
.putUpdatesByPid(Long.MIN_VALUE, command).build();
|
||||||
|
try {
|
||||||
|
vh.distributeCommandStatus(commandPid);
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user