Skip to content

Commit e40b556

Browse files
author
Nemer Daud
committed
[lgthinq] optimizing instanceof/typecast operations
Signed-off-by: Nemer Daud <[email protected]>
1 parent 6ec28b8 commit e40b556

File tree

7 files changed

+46
-48
lines changed

7 files changed

+46
-48
lines changed

bundles/org.openhab.binding.lgthinq/src/main/java/org/openhab/binding/lgthinq/internal/handler/LGThinQAirConditionerHandler.java

+22-24
Original file line numberDiff line numberDiff line change
@@ -331,84 +331,82 @@ protected void processCommand(AsyncCommandParams params) throws LGThinqApiExcept
331331
Command command = params.command;
332332
switch (getSimpleChannelUID(params.channelUID)) {
333333
case CHANNEL_AC_MOD_OP_ID: {
334-
if (params.command instanceof DecimalType) {
335-
lgThinqACApiClientService.changeOperationMode(getBridgeId(), getDeviceId(),
336-
((DecimalType) command).intValue());
334+
if (params.command instanceof DecimalType dtCmd) {
335+
lgThinqACApiClientService.changeOperationMode(getBridgeId(), getDeviceId(), dtCmd.intValue());
337336
} else {
338337
logger.warn("Received command different of Numeric in Mod Operation. Ignoring");
339338
}
340339
break;
341340
}
342341
case CHANNEL_AC_FAN_SPEED_ID: {
343-
if (command instanceof DecimalType) {
344-
lgThinqACApiClientService.changeFanSpeed(getBridgeId(), getDeviceId(),
345-
((DecimalType) command).intValue());
342+
if (command instanceof DecimalType dtCmd) {
343+
lgThinqACApiClientService.changeFanSpeed(getBridgeId(), getDeviceId(), dtCmd.intValue());
346344
} else {
347345
logger.warn("Received command different of Numeric in FanSpeed Channel. Ignoring");
348346
}
349347
break;
350348
}
351349
case CHANNEL_AC_STEP_UP_DOWN_ID: {
352-
if (command instanceof DecimalType) {
350+
if (command instanceof DecimalType dtCmd) {
353351
lgThinqACApiClientService.changeStepUpDown(getBridgeId(), getDeviceId(), getLastShot(),
354-
((DecimalType) command).intValue());
352+
dtCmd.intValue());
355353
} else {
356354
logger.warn("Received command different of Numeric in Step Up/Down Channel. Ignoring");
357355
}
358356
break;
359357
}
360358
case CHANNEL_AC_STEP_LEFT_RIGHT_ID: {
361-
if (command instanceof DecimalType) {
359+
if (command instanceof DecimalType dtCmd) {
362360
lgThinqACApiClientService.changeStepLeftRight(getBridgeId(), getDeviceId(), getLastShot(),
363-
((DecimalType) command).intValue());
361+
dtCmd.intValue());
364362
} else {
365363
logger.warn("Received command different of Numeric in Step Left/Right Channel. Ignoring");
366364
}
367365
break;
368366
}
369367
case CHANNEL_AC_POWER_ID: {
370-
if (command instanceof OnOffType) {
368+
if (command instanceof OnOffType ooCmd) {
371369
lgThinqACApiClientService.turnDevicePower(getBridgeId(), getDeviceId(),
372-
command == OnOffType.ON ? DevicePowerState.DV_POWER_ON : DevicePowerState.DV_POWER_OFF);
370+
ooCmd == OnOffType.ON ? DevicePowerState.DV_POWER_ON : DevicePowerState.DV_POWER_OFF);
373371
} else {
374372
logger.warn("Received command different of OnOffType in Power Channel. Ignoring");
375373
}
376374
break;
377375
}
378376
case CHANNEL_AC_COOL_JET_ID: {
379-
if (command instanceof OnOffType) {
377+
if (command instanceof OnOffType ooCmd) {
380378
lgThinqACApiClientService.turnCoolJetMode(getBridgeId(), getDeviceId(),
381-
command == OnOffType.ON ? getCapabilities().getCoolJetModeCommandOn()
379+
ooCmd == OnOffType.ON ? getCapabilities().getCoolJetModeCommandOn()
382380
: getCapabilities().getCoolJetModeCommandOff());
383381
} else {
384382
logger.warn("Received command different of OnOffType in CoolJet Mode Channel. Ignoring");
385383
}
386384
break;
387385
}
388386
case CHANNEL_AC_AIR_CLEAN_ID: {
389-
if (command instanceof OnOffType) {
387+
if (command instanceof OnOffType ooCmd) {
390388
lgThinqACApiClientService.turnAirCleanMode(getBridgeId(), getDeviceId(),
391-
command == OnOffType.ON ? getCapabilities().getAirCleanModeCommandOn()
389+
ooCmd == OnOffType.ON ? getCapabilities().getAirCleanModeCommandOn()
392390
: getCapabilities().getAirCleanModeCommandOff());
393391
} else {
394392
logger.warn("Received command different of OnOffType in AirClean Mode Channel. Ignoring");
395393
}
396394
break;
397395
}
398396
case CHANNEL_AC_AUTO_DRY_ID: {
399-
if (command instanceof OnOffType) {
397+
if (command instanceof OnOffType ooCmd) {
400398
lgThinqACApiClientService.turnAutoDryMode(getBridgeId(), getDeviceId(),
401-
command == OnOffType.ON ? getCapabilities().getAutoDryModeCommandOn()
399+
ooCmd == OnOffType.ON ? getCapabilities().getAutoDryModeCommandOn()
402400
: getCapabilities().getAutoDryModeCommandOff());
403401
} else {
404402
logger.warn("Received command different of OnOffType in AutoDry Mode Channel. Ignoring");
405403
}
406404
break;
407405
}
408406
case CHANNEL_AC_ENERGY_SAVING_ID: {
409-
if (command instanceof OnOffType) {
407+
if (command instanceof OnOffType ooCmd) {
410408
lgThinqACApiClientService.turnEnergySavingMode(getBridgeId(), getDeviceId(),
411-
command == OnOffType.ON ? getCapabilities().getEnergySavingModeCommandOn()
409+
ooCmd == OnOffType.ON ? getCapabilities().getEnergySavingModeCommandOn()
412410
: getCapabilities().getEnergySavingModeCommandOff());
413411
} else {
414412
logger.warn("Received command different of OnOffType in EvergySaving Mode Channel. Ignoring");
@@ -417,10 +415,10 @@ protected void processCommand(AsyncCommandParams params) throws LGThinqApiExcept
417415
}
418416
case CHANNEL_AC_TARGET_TEMP_ID: {
419417
double targetTemp;
420-
if (command instanceof DecimalType) {
421-
targetTemp = ((DecimalType) command).doubleValue();
422-
} else if (command instanceof QuantityType) {
423-
targetTemp = ((QuantityType<?>) command).doubleValue();
418+
if (command instanceof DecimalType dtCmd) {
419+
targetTemp = dtCmd.doubleValue();
420+
} else if (command instanceof QuantityType<?> qtCmd) {
421+
targetTemp = qtCmd.doubleValue();
424422
} else {
425423
logger.warn("Received command different of Numeric in TargetTemp Channel. Ignoring");
426424
break;

bundles/org.openhab.binding.lgthinq/src/main/java/org/openhab/binding/lgthinq/internal/handler/LGThinQFridgeHandler.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,10 @@ protected void processCommand(AsyncCommandParams params) throws LGThinqApiExcept
344344
case CHANNEL_FR_FREEZER_TEMP_ID:
345345
case CHANNEL_FR_FRIDGE_TEMP_ID: {
346346
int targetTemp;
347-
if (command instanceof DecimalType) {
348-
targetTemp = ((DecimalType) command).intValue();
349-
} else if (command instanceof QuantityType) {
350-
targetTemp = ((QuantityType<?>) command).intValue();
347+
if (command instanceof DecimalType dCmd) {
348+
targetTemp = dCmd.intValue();
349+
} else if (command instanceof QuantityType<?> qCmd) {
350+
targetTemp = qCmd.intValue();
351351
} else {
352352
logger.warn("Received command different of Numeric in TargetTemp Channel. Ignoring");
353353
break;
@@ -365,18 +365,18 @@ protected void processCommand(AsyncCommandParams params) throws LGThinqApiExcept
365365
break;
366366
}
367367
case CHANNEL_FR_ICE_PLUS: {
368-
if (command instanceof OnOffType) {
368+
if (command instanceof OnOffType ooCmd) {
369369
lgThinqFridgeApiClientService.setIcePlus(getBridgeId(), getDeviceId(), getCapabilities(),
370-
OnOffType.ON.equals(command), cmdSnap);
370+
ooCmd == OnOffType.ON, cmdSnap);
371371
} else {
372372
logger.warn("Received command different of OnOff in IcePlus Channel. It's mostly like a bug");
373373
}
374374
break;
375375
}
376376
case CHANNEL_FR_EXPRESS_FREEZE_MODE: {
377377
String targetExpressMode;
378-
if (command instanceof StringType) {
379-
targetExpressMode = ((StringType) command).toString();
378+
if (command instanceof StringType stCmd) {
379+
targetExpressMode = stCmd.toString();
380380
} else {
381381
logger.warn("Received command different of String in ExpressMode Channel. It's mostly like a bug");
382382
break;
@@ -386,19 +386,19 @@ protected void processCommand(AsyncCommandParams params) throws LGThinqApiExcept
386386
break;
387387
}
388388
case CHANNEL_FR_EXPRESS_COOL_MODE: {
389-
if (command instanceof OnOffType) {
389+
if (command instanceof OnOffType ooCmd) {
390390
lgThinqFridgeApiClientService.setExpressCoolMode(getBridgeId(), getDeviceId(),
391-
OnOffType.ON.equals(command));
391+
ooCmd == OnOffType.ON);
392392
} else {
393393
logger.warn(
394394
"Received command different of OnOffType in ExpressCoolMode Channel. It's mostly like a bug");
395395
}
396396
break;
397397
}
398398
case CHANNEL_FR_VACATION_MODE: {
399-
if (command instanceof OnOffType) {
399+
if (command instanceof OnOffType ooCmd) {
400400
lgThinqFridgeApiClientService.setEcoFriendlyMode(getBridgeId(), getDeviceId(),
401-
OnOffType.ON.equals(command));
401+
ooCmd == OnOffType.ON);
402402
} else {
403403
logger.warn(
404404
"Received command different of OnOffType in VacationMode Channel. It's most likely a bug");

bundles/org.openhab.binding.lgthinq/src/main/java/org/openhab/binding/lgthinq/internal/handler/LGThinQWasherDryerHandler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ protected void processCommand(LGThinQAbstractDeviceHandler.AsyncCommandParams pa
388388
simpleChannelUID = getSimpleChannelUID(params.channelUID);
389389
switch (simpleChannelUID) {
390390
case CHANNEL_WMD_REMOTE_START_START_STOP: {
391-
if (command instanceof OnOffType) {
392-
if (OnOffType.ON.equals(command)) {
391+
if (command instanceof OnOffType ooCmd) {
392+
if (ooCmd == OnOffType.ON) {
393393
if (!lastShot.isStandBy()) {
394394
lgThinqWMApiClientService.remoteStart(getBridgeId(), getCapabilities(), getDeviceId(),
395395
getRemoteStartData());
@@ -406,8 +406,8 @@ protected void processCommand(LGThinQAbstractDeviceHandler.AsyncCommandParams pa
406406
break;
407407
}
408408
case CHANNEL_WMD_STAND_BY_ID: {
409-
if (command instanceof OnOffType) {
410-
lgThinqWMApiClientService.wakeUp(getBridgeId(), getDeviceId(), OnOffType.ON.equals(command));
409+
if (command instanceof OnOffType ooCmd) {
410+
lgThinqWMApiClientService.wakeUp(getBridgeId(), getDeviceId(), ooCmd == OnOffType.ON);
411411
} else {
412412
logger.warn("Received command different of OnOffType in StandBy Channel. Ignoring");
413413
}

bundles/org.openhab.binding.lgthinq/src/main/java/org/openhab/binding/lgthinq/lgservices/LGThinQAbstractApiV1ClientService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ protected RestResult sendCommand(String bridgeName, String deviceId, Object cmdP
116116
Map<String, String> headers = getCommonHeaders(token.getGatewayInfo().getLanguage(),
117117
token.getGatewayInfo().getCountry(), token.getAccessToken(), token.getUserInfo().getUserNumber());
118118
ObjectNode payloadNode;
119-
if (cmdPayload instanceof ObjectNode) {
120-
payloadNode = ((ObjectNode) cmdPayload).deepCopy();
119+
if (cmdPayload instanceof ObjectNode oNode) {
120+
payloadNode = oNode.deepCopy();
121121
} else {
122122
payloadNode = objectMapper.convertValue(cmdPayload, new TypeReference<>() {
123123
});

bundles/org.openhab.binding.lgthinq/src/main/java/org/openhab/binding/lgthinq/lgservices/LGThinQWMApiV2ClientServiceImpl.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ public void remoteStart(String bridgeName, WasherDryerCapability cap, String dev
6969
data.remove("SmartCourse");
7070
for (Map.Entry<String, Object> value : data.entrySet()) {
7171
Object v = value.getValue();
72-
if (v instanceof Double) {
73-
nodeData.put(value.getKey(), (Double) v);
74-
} else if (v instanceof Integer) {
75-
nodeData.put(value.getKey(), (Integer) v);
72+
if (v instanceof Double d) {
73+
nodeData.put(value.getKey(), d);
74+
} else if (v instanceof Integer i) {
75+
nodeData.put(value.getKey(), i);
7676
} else {
7777
nodeData.put(value.getKey(), value.getValue().toString());
7878
}

bundles/org.openhab.binding.lgthinq/src/main/resources/OH-INF/thing/air-conditioner.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
<parameter name="pollExtraInfoOnPowerOff" type="boolean" required="true" groupName="Settings">
4848
<label>Extra Info</label>
4949
<description>If enables, extra info will be fetched even when the device is powered off.
50-
It's not so common, since extra info are normally changed only when the device is running.
50+
It's not so common, since
51+
extra info are normally changed only when the device is running.
5152
</description>
5253
<default>false</default>
5354
</parameter>

bundles/org.openhab.binding.lgthinq/src/main/resources/OH-INF/thing/channels.xml

-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@
199199
<item-type>String</item-type>
200200
<label>Remaining Time</label>
201201
<description>Remaining Time</description>
202-
<!-- TODO: change this to String. -->
203202
<state readOnly="true"/>
204203
</channel-type>
205204

0 commit comments

Comments
 (0)