Java 17 features (A-G) (#15516)

- add missing @override
- Java style array syntax
- remove redundant modifiers
- always move String constants to left side in comparisons
- simplify lambda expressions and return statements
- use replace instead of replaceAll w/o regex
- instanceof matching and multiline strings

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich
2023-09-05 22:30:16 +02:00
committed by GitHub
parent a0dc5c05f2
commit cf10b3e9c7
486 changed files with 2053 additions and 1955 deletions

View File

@@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -106,7 +107,7 @@ public class BridgeHandler extends BaseBridgeHandler {
@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(ThingDiscoveryService.class);
return Set.of(ThingDiscoveryService.class);
}
@Override

View File

@@ -65,8 +65,8 @@ public final class ClimateControlHandler extends BoschSHCDeviceHandler {
super.handleCommand(channelUID, command);
switch (channelUID.getId()) {
case CHANNEL_SETPOINT_TEMPERATURE:
if (command instanceof QuantityType<?>) {
updateSetpointTemperature((QuantityType<?>) command);
if (command instanceof QuantityType<?> temperature) {
updateSetpointTemperature(temperature);
}
break;
}

View File

@@ -122,18 +122,18 @@ public class IntrusionDetectionHandler extends BoschSHCHandler {
switch (channelUID.getId()) {
case CHANNEL_ARM_ACTION:
if (command instanceof StringType) {
armIntrusionDetectionSystem((StringType) command);
if (command instanceof StringType stringCommand) {
armIntrusionDetectionSystem(stringCommand);
}
break;
case CHANNEL_DISARM_ACTION:
if (command instanceof OnOffType) {
disarmIntrusionDetectionSystem((OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
disarmIntrusionDetectionSystem(onOffCommand);
}
break;
case CHANNEL_MUTE_ACTION:
if (command instanceof OnOffType) {
muteIntrusionDetectionSystem((OnOffType) command);
if (command instanceof OnOffType onOffCommand) {
muteIntrusionDetectionSystem(onOffCommand);
}
break;
}

View File

@@ -26,5 +26,5 @@ public enum AlarmState {
PRE_ALARM,
ALARM_ON,
ALARM_MUTED,
UNKNOWN;
UNKNOWN
}

View File

@@ -24,5 +24,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
public enum ArmingState {
SYSTEM_ARMED,
SYSTEM_ARMING,
SYSTEM_DISARMED;
SYSTEM_DISARMED
}

View File

@@ -22,5 +22,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
public enum ShutterContactState {
OPEN,
CLOSED;
CLOSED
}

View File

@@ -22,5 +22,5 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
public enum OperationState {
MOVING,
STOPPED;
STOPPED
}

View File

@@ -34,15 +34,13 @@ public class SmokeDetectorCheckService extends BoschSHCService<SmokeDetectorChec
@Override
public SmokeDetectorCheckServiceState handleCommand(Command command) throws BoschSHCException {
if (command instanceof StringType) {
var stringCommand = (StringType) command;
if (command instanceof StringType stringCommand) {
var state = new SmokeDetectorCheckServiceState();
state.value = SmokeDetectorCheckState.from(stringCommand.toString());
return state;
}
if (command instanceof PlayPauseType) {
var playPauseCommand = (PlayPauseType) command;
if (command instanceof PlayPauseType playPauseCommand) {
if (playPauseCommand.equals(PlayPauseType.PLAY)) {
var state = new SmokeDetectorCheckServiceState();
state.value = SmokeDetectorCheckState.SMOKE_TEST_REQUESTED;

View File

@@ -57,12 +57,22 @@ public abstract class AbstractBatteryPoweredDeviceHandlerTest<T extends Abstract
@Test
public void testProcessUpdateBatteryLevelLowBattery() {
JsonElement deviceServiceData = JsonParser.parseString("{ \n" + " \"@type\":\"DeviceServiceData\",\n"
+ " \"path\":\"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel\",\n"
+ " \"id\":\"BatteryLevel\",\n" + " \"deviceId\":\"hdm:ZigBee:000d6f0004b93361\",\n"
+ " \"faults\":{ \n" + " \"entries\":[\n" + " {\n"
+ " \"type\":\"LOW_BATTERY\",\n" + " \"category\":\"WARNING\"\n" + " }\n"
+ " ]\n" + " }\n" + "}");
JsonElement deviceServiceData = JsonParser.parseString("""
{
"@type":"DeviceServiceData",
"path":"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel",
"id":"BatteryLevel",
"deviceId":"hdm:ZigBee:000d6f0004b93361",
"faults":{
"entries":[
{
"type":"LOW_BATTERY",
"category":"WARNING"
}
]
}
}\
""");
getFixture().processUpdate("BatteryLevel", deviceServiceData);
verify(getCallback()).stateUpdated(getChannelUID(BoschSHCBindingConstants.CHANNEL_BATTERY_LEVEL),
new DecimalType(10));
@@ -71,12 +81,22 @@ public abstract class AbstractBatteryPoweredDeviceHandlerTest<T extends Abstract
@Test
public void testProcessUpdateBatteryLevelCriticalLow() {
JsonElement deviceServiceData = JsonParser.parseString("{ \n" + " \"@type\":\"DeviceServiceData\",\n"
+ " \"path\":\"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel\",\n"
+ " \"id\":\"BatteryLevel\",\n" + " \"deviceId\":\"hdm:ZigBee:000d6f0004b93361\",\n"
+ " \"faults\":{ \n" + " \"entries\":[\n" + " {\n"
+ " \"type\":\"CRITICAL_LOW\",\n" + " \"category\":\"WARNING\"\n"
+ " }\n" + " ]\n" + " }\n" + "}");
JsonElement deviceServiceData = JsonParser.parseString("""
{
"@type":"DeviceServiceData",
"path":"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel",
"id":"BatteryLevel",
"deviceId":"hdm:ZigBee:000d6f0004b93361",
"faults":{
"entries":[
{
"type":"CRITICAL_LOW",
"category":"WARNING"
}
]
}
}\
""");
getFixture().processUpdate("BatteryLevel", deviceServiceData);
verify(getCallback()).stateUpdated(getChannelUID(BoschSHCBindingConstants.CHANNEL_BATTERY_LEVEL),
new DecimalType(1));
@@ -85,12 +105,22 @@ public abstract class AbstractBatteryPoweredDeviceHandlerTest<T extends Abstract
@Test
public void testProcessUpdateBatteryLevelCriticallyLowBattery() {
JsonElement deviceServiceData = JsonParser.parseString("{ \n" + " \"@type\":\"DeviceServiceData\",\n"
+ " \"path\":\"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel\",\n"
+ " \"id\":\"BatteryLevel\",\n" + " \"deviceId\":\"hdm:ZigBee:000d6f0004b93361\",\n"
+ " \"faults\":{ \n" + " \"entries\":[\n" + " {\n"
+ " \"type\":\"CRITICALLY_LOW_BATTERY\",\n" + " \"category\":\"WARNING\"\n"
+ " }\n" + " ]\n" + " }\n" + "}");
JsonElement deviceServiceData = JsonParser.parseString("""
{
"@type":"DeviceServiceData",
"path":"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel",
"id":"BatteryLevel",
"deviceId":"hdm:ZigBee:000d6f0004b93361",
"faults":{
"entries":[
{
"type":"CRITICALLY_LOW_BATTERY",
"category":"WARNING"
}
]
}
}\
""");
getFixture().processUpdate("BatteryLevel", deviceServiceData);
verify(getCallback()).stateUpdated(getChannelUID(BoschSHCBindingConstants.CHANNEL_BATTERY_LEVEL),
new DecimalType(1));
@@ -99,9 +129,13 @@ public abstract class AbstractBatteryPoweredDeviceHandlerTest<T extends Abstract
@Test
public void testProcessUpdateBatteryLevelOK() {
JsonElement deviceServiceData = JsonParser.parseString("{ \n" + " \"@type\":\"DeviceServiceData\",\n"
+ " \"path\":\"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel\",\n"
+ " \"id\":\"BatteryLevel\",\n" + " \"deviceId\":\"hdm:ZigBee:000d6f0004b93361\" }");
JsonElement deviceServiceData = JsonParser.parseString("""
{
"@type":"DeviceServiceData",
"path":"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel",
"id":"BatteryLevel",
"deviceId":"hdm:ZigBee:000d6f0004b93361" }\
""");
getFixture().processUpdate("BatteryLevel", deviceServiceData);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_BATTERY_LEVEL),
@@ -112,12 +146,22 @@ public abstract class AbstractBatteryPoweredDeviceHandlerTest<T extends Abstract
@Test
public void testProcessUpdateBatteryLevelNotAvailable() {
JsonElement deviceServiceData = JsonParser.parseString("{ \n" + " \"@type\":\"DeviceServiceData\",\n"
+ " \"path\":\"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel\",\n"
+ " \"id\":\"BatteryLevel\",\n" + " \"deviceId\":\"hdm:ZigBee:000d6f0004b93361\",\n"
+ " \"faults\":{ \n" + " \"entries\":[\n" + " {\n"
+ " \"type\":\"NOT_AVAILABLE\",\n" + " \"category\":\"WARNING\"\n"
+ " }\n" + " ]\n" + " }\n" + "}");
JsonElement deviceServiceData = JsonParser.parseString("""
{
"@type":"DeviceServiceData",
"path":"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel",
"id":"BatteryLevel",
"deviceId":"hdm:ZigBee:000d6f0004b93361",
"faults":{
"entries":[
{
"type":"NOT_AVAILABLE",
"category":"WARNING"
}
]
}
}\
""");
getFixture().processUpdate("BatteryLevel", deviceServiceData);
verify(getCallback()).stateUpdated(getChannelUID(BoschSHCBindingConstants.CHANNEL_BATTERY_LEVEL),
UnDefType.UNDEF);

View File

@@ -103,8 +103,13 @@ public abstract class AbstractPowerSwitchHandlerTest<T extends AbstractPowerSwit
@Test
public void testUpdateChannelPowerMeterServiceState() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"powerMeterState\",\n"
+ " \"powerConsumption\": \"23\",\n" + " \"energyConsumption\": 42\n" + "}");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "powerMeterState",
"powerConsumption": "23",
"energyConsumption": 42
}\
""");
getFixture().processUpdate("PowerMeter", jsonObject);
verify(getCallback()).stateUpdated(eq(getChannelUID(BoschSHCBindingConstants.CHANNEL_POWER_CONSUMPTION)),

View File

@@ -114,7 +114,7 @@ class BoschHttpClientTest {
// mock a logger using reflection to avoid NPEs during logger calls
Logger mockedLogger = mock(Logger.class);
List<Field> fields = ReflectionSupport.findFields(BoschHttpClient.class,
f -> f.getName().equalsIgnoreCase("logger"), HierarchyTraversalMode.TOP_DOWN);
f -> "logger".equalsIgnoreCase(f.getName()), HierarchyTraversalMode.TOP_DOWN);
Field field = fields.iterator().next();
field.setAccessible(true);
field.set(mockedHttpClient, mockedLogger);
@@ -137,7 +137,7 @@ class BoschHttpClientTest {
// mock a logger using reflection to avoid NPEs during logger calls
Logger mockedLogger = mock(Logger.class);
List<Field> fields = ReflectionSupport.findFields(BoschHttpClient.class,
f -> f.getName().equalsIgnoreCase("logger"), HierarchyTraversalMode.TOP_DOWN);
f -> "logger".equalsIgnoreCase(f.getName()), HierarchyTraversalMode.TOP_DOWN);
Field field = fields.iterator().next();
field.setAccessible(true);
field.set(mockedHttpClient, mockedLogger);
@@ -210,9 +210,7 @@ class BoschHttpClientTest {
"{\"@type\": \"JsonRestExceptionResponseEntity\", \"errorCode\": \"500\", \"statusCode\": \"500\"}");
BoschSHCException e = assertThrows(BoschSHCException.class, () -> httpClient.sendRequest(request, Device.class,
Device::isValid, (Integer statusCode, String content) -> {
return new BoschSHCException("test exception");
}));
Device::isValid, (Integer statusCode, String content) -> new BoschSHCException("test exception")));
assertEquals("test exception", e.getMessage());
}
@@ -240,9 +238,7 @@ class BoschHttpClientTest {
when(response.getContentAsString()).thenReturn(
"{\"@type\": \"JsonRestExceptionResponseEntity\", \"errorCode\": \"500\", \"statusCode\": \"500\"}");
ExecutionException e = assertThrows(ExecutionException.class,
() -> httpClient.sendRequest(request, SubscribeResult.class, sr -> {
return false;
}, null));
() -> httpClient.sendRequest(request, SubscribeResult.class, sr -> false, null));
String actualMessage = e.getMessage();
assertTrue(actualMessage.contains(
"Received invalid content for type org.openhab.binding.boschshc.internal.devices.bridge.dto.SubscribeResult:"));
@@ -257,9 +253,7 @@ class BoschHttpClientTest {
when(response.getStatus()).thenReturn(200);
when(response.getContentAsString()).thenReturn("{\"@type\": \"JsonRestExceptionResponseEntity}");
ExecutionException e = assertThrows(ExecutionException.class,
() -> httpClient.sendRequest(request, SubscribeResult.class, sr -> {
return false;
}, null));
() -> httpClient.sendRequest(request, SubscribeResult.class, sr -> false, null));
assertEquals(
"Received invalid content in response, expected type org.openhab.binding.boschshc.internal.devices.bridge.dto.SubscribeResult: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 44 path $.@type",
e.getMessage());

View File

@@ -159,14 +159,21 @@ class BridgeHandlerTest {
Request devicesRequest = mock(Request.class);
ContentResponse devicesResponse = mock(ContentResponse.class);
when(devicesResponse.getStatus()).thenReturn(200);
when(devicesResponse.getContentAsString()).thenReturn("[{\"@type\":\"device\",\r\n"
+ " \"rootDeviceId\":\"64-da-a0-02-14-9b\",\r\n"
+ " \"id\":\"hdm:HomeMaticIP:3014F711A00004953859F31B\",\r\n"
+ " \"deviceServiceIds\":[\"PowerMeter\",\"PowerSwitch\",\"PowerSwitchProgram\",\"Routing\"],\r\n"
+ " \"manufacturer\":\"BOSCH\",\r\n" + " \"roomId\":\"hz_3\",\r\n" + " \"deviceModel\":\"PSM\",\r\n"
+ " \"serial\":\"3014F711A00004953859F31B\",\r\n" + " \"profile\":\"GENERIC\",\r\n"
+ " \"name\":\"Coffee Machine\",\r\n" + " \"status\":\"AVAILABLE\",\r\n" + " \"childDeviceIds\":[]\r\n"
+ " }]");
when(devicesResponse.getContentAsString()).thenReturn("""
[{"@type":"device",
"rootDeviceId":"64-da-a0-02-14-9b",
"id":"hdm:HomeMaticIP:3014F711A00004953859F31B",
"deviceServiceIds":["PowerMeter","PowerSwitch","PowerSwitchProgram","Routing"],
"manufacturer":"BOSCH",
"roomId":"hz_3",
"deviceModel":"PSM",
"serial":"3014F711A00004953859F31B",
"profile":"GENERIC",
"name":"Coffee Machine",
"status":"AVAILABLE",
"childDeviceIds":[]
}]\
""");
when(devicesRequest.send()).thenReturn(devicesResponse);
when(httpClient.createRequest(contains("/devices"), same(HttpMethod.GET))).thenReturn(devicesRequest);
@@ -175,7 +182,7 @@ class BridgeHandlerTest {
Request longPollRequest = mock(Request.class);
when(httpClient.createRequest(anyString(), same(HttpMethod.POST),
argThat((JsonRpcRequest r) -> r.method.equals("RE/longPoll")))).thenReturn(longPollRequest);
argThat((JsonRpcRequest r) -> "RE/longPoll".equals(r.method)))).thenReturn(longPollRequest);
fixture.initialAccess(httpClient);
verify(thingHandlerCallback).statusUpdated(any(),
@@ -190,18 +197,37 @@ class BridgeHandlerTest {
when(request.header(anyString(), anyString())).thenReturn(request);
ContentResponse response = mock(ContentResponse.class);
when(response.getStatus()).thenReturn(200);
when(response.getContentAsString()).thenReturn("{\r\n" + " \"@type\": \"systemState\",\r\n"
+ " \"systemAvailability\": {\r\n" + " \"@type\": \"systemAvailabilityState\",\r\n"
+ " \"available\": true,\r\n" + " \"deleted\": false\r\n" + " },\r\n"
+ " \"armingState\": {\r\n" + " \"@type\": \"armingState\",\r\n"
+ " \"state\": \"SYSTEM_DISARMED\",\r\n" + " \"deleted\": false\r\n" + " },\r\n"
+ " \"alarmState\": {\r\n" + " \"@type\": \"alarmState\",\r\n"
+ " \"value\": \"ALARM_OFF\",\r\n" + " \"incidents\": [],\r\n"
+ " \"deleted\": false\r\n" + " },\r\n" + " \"activeConfigurationProfile\": {\r\n"
+ " \"@type\": \"activeConfigurationProfile\",\r\n" + " \"deleted\": false\r\n"
+ " },\r\n" + " \"securityGapState\": {\r\n" + " \"@type\": \"securityGapState\",\r\n"
+ " \"securityGaps\": [],\r\n" + " \"deleted\": false\r\n" + " },\r\n"
+ " \"deleted\": false\r\n" + " }");
when(response.getContentAsString()).thenReturn("""
{
"@type": "systemState",
"systemAvailability": {
"@type": "systemAvailabilityState",
"available": true,
"deleted": false
},
"armingState": {
"@type": "armingState",
"state": "SYSTEM_DISARMED",
"deleted": false
},
"alarmState": {
"@type": "alarmState",
"value": "ALARM_OFF",
"incidents": [],
"deleted": false
},
"activeConfigurationProfile": {
"@type": "activeConfigurationProfile",
"deleted": false
},
"securityGapState": {
"@type": "securityGapState",
"securityGaps": [],
"deleted": false
},
"deleted": false
}\
""");
when(request.send()).thenReturn(response);
when(httpClient.createRequest(anyString(), same(HttpMethod.GET))).thenReturn(request);
@@ -302,12 +328,22 @@ class BridgeHandlerTest {
when(request.header(anyString(), anyString())).thenReturn(request);
ContentResponse response = mock(ContentResponse.class);
when(response.getStatus()).thenReturn(200);
when(response.getContentAsString()).thenReturn("{ \n" + " \"@type\":\"DeviceServiceData\",\n"
+ " \"path\":\"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel\",\n"
+ " \"id\":\"BatteryLevel\",\n" + " \"deviceId\":\"hdm:ZigBee:000d6f0004b93361\",\n"
+ " \"faults\":{ \n" + " \"entries\":[\n" + " {\n"
+ " \"type\":\"LOW_BATTERY\",\n" + " \"category\":\"WARNING\"\n" + " }\n"
+ " ]\n" + " }\n" + "}");
when(response.getContentAsString()).thenReturn("""
{
"@type":"DeviceServiceData",
"path":"/devices/hdm:ZigBee:000d6f0004b93361/services/BatteryLevel",
"id":"BatteryLevel",
"deviceId":"hdm:ZigBee:000d6f0004b93361",
"faults":{\s
"entries":[
{
"type":"LOW_BATTERY",
"category":"WARNING"
}
]
}
}\
""");
when(request.send()).thenReturn(response);
when(httpClient.createRequest(anyString(), same(HttpMethod.GET))).thenReturn(request);

View File

@@ -210,13 +210,13 @@ class LongPollingTest {
Request subscribeRequest = mock(Request.class);
when(httpClient.createRequest(anyString(), same(HttpMethod.POST),
argThat((JsonRpcRequest r) -> r.method.equals("RE/subscribe")))).thenReturn(subscribeRequest);
argThat((JsonRpcRequest r) -> "RE/subscribe".equals(r.method)))).thenReturn(subscribeRequest);
SubscribeResult subscribeResult = new SubscribeResult();
when(httpClient.sendRequest(any(), same(SubscribeResult.class), any(), any())).thenReturn(subscribeResult);
Request longPollRequest = mock(Request.class);
when(httpClient.createRequest(anyString(), same(HttpMethod.POST),
argThat((JsonRpcRequest r) -> r.method.equals("RE/longPoll")))).thenReturn(longPollRequest);
argThat((JsonRpcRequest r) -> "RE/longPoll".equals(r.method)))).thenReturn(longPollRequest);
fixture.start(httpClient);
@@ -268,7 +268,7 @@ class LongPollingTest {
Request longPollRequest = mock(Request.class);
when(httpClient.createRequest(anyString(), same(HttpMethod.POST),
argThat((JsonRpcRequest r) -> r.method.equals("RE/longPoll")))).thenReturn(longPollRequest);
argThat((JsonRpcRequest r) -> "RE/longPoll".equals(r.method)))).thenReturn(longPollRequest);
fixture.start(httpClient);
@@ -296,13 +296,13 @@ class LongPollingTest {
Request subscribeRequest = mock(Request.class);
when(httpClient.createRequest(anyString(), same(HttpMethod.POST),
argThat((JsonRpcRequest r) -> r.method.equals("RE/subscribe")))).thenReturn(subscribeRequest);
argThat((JsonRpcRequest r) -> "RE/subscribe".equals(r.method)))).thenReturn(subscribeRequest);
SubscribeResult subscribeResult = new SubscribeResult();
when(httpClient.sendRequest(any(), same(SubscribeResult.class), any(), any())).thenReturn(subscribeResult);
Request longPollRequest = mock(Request.class);
when(httpClient.createRequest(anyString(), same(HttpMethod.POST),
argThat((JsonRpcRequest r) -> r.method.equals("RE/longPoll")))).thenReturn(longPollRequest);
argThat((JsonRpcRequest r) -> "RE/longPoll".equals(r.method)))).thenReturn(longPollRequest);
fixture.start(httpClient);

View File

@@ -78,8 +78,12 @@ class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest<Climat
@Test
void testUpdateChannelsTemperatureLevelService() {
JsonElement jsonObject = JsonParser.parseString(
"{\n" + " \"@type\": \"temperatureLevelState\",\n" + " \"temperature\": 21.5\n" + " }");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "temperatureLevelState",
"temperature": 21.5
}\
""");
getFixture().processUpdate("TemperatureLevel", jsonObject);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE),
@@ -88,8 +92,12 @@ class ClimateControlHandlerTest extends AbstractBoschSHCDeviceHandlerTest<Climat
@Test
void testUpdateChannelsRoomClimateControlService() {
JsonElement jsonObject = JsonParser.parseString(
"{\n" + " \"@type\": \"climateControlState\",\n" + " \"setpointTemperature\": 21.5\n" + " }");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "climateControlState",
"setpointTemperature": 21.5
}\
""");
getFixture().processUpdate("RoomClimateControl", jsonObject);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SETPOINT_TEMPERATURE),

View File

@@ -80,18 +80,37 @@ class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<Intrusio
@Test
void testUpdateChannelsIntrusionDetectionSystemState() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"systemState\",\n"
+ " \"systemAvailability\": {\n" + " \"@type\": \"systemAvailabilityState\",\n"
+ " \"available\": true,\n" + " \"deleted\": false\n" + " },\n"
+ " \"armingState\": {\n" + " \"@type\": \"armingState\",\n"
+ " \"state\": \"SYSTEM_DISARMED\",\n" + " \"deleted\": false\n" + " },\n"
+ " \"alarmState\": {\n" + " \"@type\": \"alarmState\",\n"
+ " \"value\": \"ALARM_OFF\",\n" + " \"incidents\": [],\n"
+ " \"deleted\": false\n" + " },\n" + " \"activeConfigurationProfile\": {\n"
+ " \"@type\": \"activeConfigurationProfile\",\n" + " \"deleted\": false\n"
+ " },\n" + " \"securityGapState\": {\n" + " \"@type\": \"securityGapState\",\n"
+ " \"securityGaps\": [],\n" + " \"deleted\": false\n" + " },\n"
+ " \"deleted\": false\n" + " }\n");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "systemState",
"systemAvailability": {
"@type": "systemAvailabilityState",
"available": true,
"deleted": false
},
"armingState": {
"@type": "armingState",
"state": "SYSTEM_DISARMED",
"deleted": false
},
"alarmState": {
"@type": "alarmState",
"value": "ALARM_OFF",
"incidents": [],
"deleted": false
},
"activeConfigurationProfile": {
"@type": "activeConfigurationProfile",
"deleted": false
},
"securityGapState": {
"@type": "securityGapState",
"securityGaps": [],
"deleted": false
},
"deleted": false
}
""");
getFixture().processUpdate(BoschSHCBindingConstants.SERVICE_INTRUSION_DETECTION, jsonObject);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_SYSTEM_AVAILABILITY),
@@ -109,15 +128,35 @@ class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<Intrusio
@Test
void testUpdateChannelsIntrusionDetectionControlState() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"intrusionDetectionControlState\",\n"
+ " \"activeProfile\": \"0\",\n" + " \"alarmActivationDelayTime\": 30,\n" + " \"actuators\": [\n"
+ " {\n" + " \"readonly\": false,\n" + " \"active\": true,\n"
+ " \"id\": \"intrusion:video\"\n" + " },\n" + " {\n" + " \"readonly\": false,\n"
+ " \"active\": false,\n" + " \"id\": \"intrusion:siren\"\n" + " }\n" + " ],\n"
+ " \"remainingTimeUntilArmed\": 29559,\n" + " \"armActivationDelayTime\": 30,\n"
+ " \"triggers\": [\n" + " {\n" + " \"readonly\": false,\n" + " \"active\": true,\n"
+ " \"id\": \"hdm:ZigBee:000d6f0012f02378\"\n" + " }\n" + " ],\n"
+ " \"value\": \"SYSTEM_ARMING\"\n" + " }");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "intrusionDetectionControlState",
"activeProfile": "0",
"alarmActivationDelayTime": 30,
"actuators": [
{
"readonly": false,
"active": true,
"id": "intrusion:video"
},
{
"readonly": false,
"active": false,
"id": "intrusion:siren"
}
],
"remainingTimeUntilArmed": 29559,
"armActivationDelayTime": 30,
"triggers": [
{
"readonly": false,
"active": true,
"id": "hdm:ZigBee:000d6f0012f02378"
}
],
"value": "SYSTEM_ARMING"
}\
""");
getFixture().processUpdate("IntrusionDetectionControl", jsonObject);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ARMING_STATE),
@@ -126,11 +165,22 @@ class IntrusionDetectionHandlerTest extends AbstractBoschSHCHandlerTest<Intrusio
@Test
void testUpdateChannelsSurveillanceAlarmState() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"surveillanceAlarmState\",\n"
+ " \"incidents\": [\n" + " {\n" + " \"triggerName\": \"Motion Detector\",\n"
+ " \"locationId\": \"hz_5\",\n" + " \"location\": \"Living Room\",\n"
+ " \"id\": \"hdm:ZigBee:000d6f0012f02342\",\n" + " \"time\": 1652615755336,\n"
+ " \"type\": \"INTRUSION\"\n" + " }\n" + " ],\n" + " \"value\": \"ALARM_ON\"\n" + " }");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "surveillanceAlarmState",
"incidents": [
{
"triggerName": "Motion Detector",
"locationId": "hz_5",
"location": "Living Room",
"id": "hdm:ZigBee:000d6f0012f02342",
"time": 1652615755336,
"type": "INTRUSION"
}
],
"value": "ALARM_ON"
}\
""");
getFixture().processUpdate("SurveillanceAlarm", jsonObject);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_ALARM_STATE),

View File

@@ -51,8 +51,12 @@ class MotionDetectorHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<
@Test
void testUpdateChannelsLatestMotionService() {
JsonElement jsonObject = JsonParser.parseString("{\n" + " \"@type\": \"latestMotionState\",\n"
+ " \"latestMotionDetected\": \"2020-04-03T19:02:19.054Z\"\n" + " }");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "latestMotionState",
"latestMotionDetected": "2020-04-03T19:02:19.054Z"
}\
""");
getFixture().processUpdate("LatestMotion", jsonObject);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_LATEST_MOTION),

View File

@@ -132,9 +132,15 @@ class SmartBulbHandlerTest extends AbstractBoschSHCDeviceHandlerTest<SmartBulbHa
@Test
void testUpdateChannelHSBColorActuatorState() {
JsonElement jsonObject = JsonParser.parseString("{\"colorTemperatureRange\": {\n" + " \"minCt\": 153,\n"
+ " \"maxCt\": 526\n" + " },\n" + " \"@type\": \"colorState\",\n"
+ " \"gamut\": \"LEDVANCE_GAMUT_A\",\n" + " \"rgb\": -12427}");
JsonElement jsonObject = JsonParser.parseString("""
{"colorTemperatureRange": {
"minCt": 153,
"maxCt": 526
},
"@type": "colorState",
"gamut": "LEDVANCE_GAMUT_A",
"rgb": -12427}\
""");
getFixture().processUpdate("HSBColorActuator", jsonObject);
verify(getCallback()).stateUpdated(new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_COLOR),
HSBType.fromRGB(255, 207, 117));

View File

@@ -121,8 +121,12 @@ class ThermostatHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<Ther
@Test
void testUpdateChannelsTemperatureLevelService() {
JsonElement jsonObject = JsonParser.parseString(
"{\n" + " \"@type\": \"temperatureLevelState\",\n" + " \"temperature\": 21.5\n" + " }");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "temperatureLevelState",
"temperature": 21.5
}\
""");
getFixture().processUpdate("TemperatureLevel", jsonObject);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE),

View File

@@ -58,8 +58,10 @@ class TwinguardHandlerTest extends AbstractSmokeDetectorHandlerTest<TwinguardHan
@Test
void testUpdateChannelsAirQualityLevelService() {
JsonElement jsonObject = JsonParser.parseString(
"{\"temperatureRating\":\"GOOD\",\"humidityRating\":\"MEDIUM\",\"purity\":620,\"@type\":\"airQualityLevelState\",\n"
+ " \"purityRating\":\"GOOD\",\"temperature\":23.77,\"description\":\"LITTLE_DRY\",\"humidity\":32.69,\"combinedRating\":\"MEDIUM\"}");
"""
{"temperatureRating":"GOOD","humidityRating":"MEDIUM","purity":620,"@type":"airQualityLevelState",
"purityRating":"GOOD","temperature":23.77,"description":"LITTLE_DRY","humidity":32.69,"combinedRating":"MEDIUM"}\
""");
getFixture().processUpdate("AirQualityLevel", jsonObject);
verify(getCallback()).stateUpdated(

View File

@@ -56,8 +56,12 @@ class WallThermostatHandlerTest extends AbstractBatteryPoweredDeviceHandlerTest<
@Test
void testUpdateChannelsTemperatureLevelService() {
JsonElement jsonObject = JsonParser.parseString(
"{\n" + " \"@type\": \"temperatureLevelState\",\n" + " \"temperature\": 21.5\n" + " }");
JsonElement jsonObject = JsonParser.parseString("""
{
"@type": "temperatureLevelState",
"temperature": 21.5
}\
""");
getFixture().processUpdate("TemperatureLevel", jsonObject);
verify(getCallback()).stateUpdated(
new ChannelUID(getThing().getUID(), BoschSHCBindingConstants.CHANNEL_TEMPERATURE),

View File

@@ -86,13 +86,35 @@ class IntrusionDetectionControlStateServiceTest {
@Test
void onStateUpdate() {
final String json = "{\n" + "\"@type\": \"intrusionDetectionControlState\",\n" + "\"activeProfile\": \"0\",\n"
+ "\"alarmActivationDelayTime\": 30,\n" + "\"actuators\": [\n" + "{\n" + "\"readonly\": false,\n"
+ "\"active\": true,\n" + "\"id\": \"intrusion:video\"\n" + "},\n" + "{\n" + "\"readonly\": false,\n"
+ "\"active\": false,\n" + "\"id\": \"intrusion:siren\"\n" + "}\n" + "],\n"
+ "\"remainingTimeUntilArmed\": 28959,\n" + "\"armActivationDelayTime\": 30,\n" + "\"triggers\": [\n"
+ "{\n" + "\"readonly\": false,\n" + "\"active\": true,\n" + "\"id\": \"hdm:ZigBee:000d6f0422f42378\"\n"
+ "}\n" + "],\n" + "\"value\": \"SYSTEM_ARMING\"\n" + "}";
final String json = """
{
"@type":"intrusionDetectionControlState",
"activeProfile":"0",
"alarmActivationDelayTime":30,
"actuators":[
{
"readonly":false,
"active":true,
"id":"intrusion:video"
},
{
"readonly":false,
"active":false,
"id":"intrusion:siren"
}
],
"remainingTimeUntilArmed":28959,
"armActivationDelayTime":30,
"triggers":[
{
"readonly":false,
"active":true,
"id":"hdm:ZigBee:000d6f0422f42378"
}
],
"value":"SYSTEM_ARMING"
}\
""";
JsonElement jsonElement = JsonParser.parseString(json);
fixture.onStateUpdate(jsonElement);
verify(consumer).accept(any());