Remove duplicated code. (#16393)
Signed-off-by: Alexander Falkenstern <alexander.falkenstern@gmail.com>pull/16399/head
parent
4c4f29283c
commit
473b0acda1
|
@ -415,7 +415,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||||
|
|
||||||
case CHANNEL_SENSOR_SLEEPTIME:
|
case CHANNEL_SENSOR_SLEEPTIME:
|
||||||
logger.debug("{}: Set sensor sleep time to {}", thingName, command);
|
logger.debug("{}: Set sensor sleep time to {}", thingName, command);
|
||||||
int value = (int) getNumber(command);
|
int value = getNumber(command).intValue();
|
||||||
value = value > 0 ? Math.max(SHELLY_MOTION_SLEEPTIME_OFFSET, value - SHELLY_MOTION_SLEEPTIME_OFFSET)
|
value = value > 0 ? Math.max(SHELLY_MOTION_SLEEPTIME_OFFSET, value - SHELLY_MOTION_SLEEPTIME_OFFSET)
|
||||||
: 0;
|
: 0;
|
||||||
api.setSleepTime(value);
|
api.setSleepTime(value);
|
||||||
|
@ -432,7 +432,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||||
logger.debug("{}: Select profile {}", thingName, command);
|
logger.debug("{}: Select profile {}", thingName, command);
|
||||||
int id = -1;
|
int id = -1;
|
||||||
if (command instanceof Number) {
|
if (command instanceof Number) {
|
||||||
id = (int) getNumber(command);
|
id = getNumber(command).intValue();
|
||||||
} else {
|
} else {
|
||||||
String cmd = command.toString();
|
String cmd = command.toString();
|
||||||
if (isDigit(cmd.charAt(0))) {
|
if (isDigit(cmd.charAt(0))) {
|
||||||
|
@ -458,7 +458,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||||
break;
|
break;
|
||||||
case CHANNEL_CONTROL_SETTEMP:
|
case CHANNEL_CONTROL_SETTEMP:
|
||||||
logger.debug("{}: Set temperature to {}", thingName, command);
|
logger.debug("{}: Set temperature to {}", thingName, command);
|
||||||
api.setValveTemperature(0, (int) getNumber(command));
|
api.setValveTemperature(0, getNumber(command).intValue());
|
||||||
break;
|
break;
|
||||||
case CHANNEL_CONTROL_POSITION:
|
case CHANNEL_CONTROL_POSITION:
|
||||||
logger.debug("{}: Set position to {}", thingName, command);
|
logger.debug("{}: Set position to {}", thingName, command);
|
||||||
|
@ -470,7 +470,7 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||||
break;
|
break;
|
||||||
case CHANNEL_CONTROL_BTIMER:
|
case CHANNEL_CONTROL_BTIMER:
|
||||||
logger.debug("{}: Set boost timer to {}", thingName, command);
|
logger.debug("{}: Set boost timer to {}", thingName, command);
|
||||||
api.setValveBoostTime(0, (int) getNumber(command));
|
api.setValveBoostTime(0, getNumber(command).intValue());
|
||||||
break;
|
break;
|
||||||
case CHANNEL_SENSOR_MUTE:
|
case CHANNEL_SENSOR_MUTE:
|
||||||
if (profile.isSmoke && ((OnOffType) command) == OnOffType.ON) {
|
if (profile.isSmoke && ((OnOffType) command) == OnOffType.ON) {
|
||||||
|
@ -514,19 +514,6 @@ public abstract class ShellyBaseHandler extends BaseThingHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getNumber(Command command) {
|
|
||||||
if (command instanceof QuantityType<?> quantityCommand) {
|
|
||||||
return quantityCommand.doubleValue();
|
|
||||||
}
|
|
||||||
if (command instanceof DecimalType decimalCommand) {
|
|
||||||
return decimalCommand.doubleValue();
|
|
||||||
}
|
|
||||||
if (command instanceof Number numberCommand) {
|
|
||||||
return numberCommand.doubleValue();
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Invalid Number type for conversion: " + command);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update device status and channels
|
* Update device status and channels
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -236,13 +236,16 @@ public class ShellyUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Double getNumber(Command command) throws IllegalArgumentException {
|
public static Double getNumber(Command command) throws IllegalArgumentException {
|
||||||
if (command instanceof DecimalType decimalCommand) {
|
|
||||||
return decimalCommand.doubleValue();
|
|
||||||
}
|
|
||||||
if (command instanceof QuantityType<?> quantityCommand) {
|
if (command instanceof QuantityType<?> quantityCommand) {
|
||||||
return quantityCommand.doubleValue();
|
return quantityCommand.doubleValue();
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unable to convert number");
|
if (command instanceof DecimalType decimalCommand) {
|
||||||
|
return decimalCommand.doubleValue();
|
||||||
|
}
|
||||||
|
if (command instanceof Number numberCommand) {
|
||||||
|
return numberCommand.doubleValue();
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Invalid Number type for conversion: " + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OnOffType getOnOff(@Nullable Boolean value) {
|
public static OnOffType getOnOff(@Nullable Boolean value) {
|
||||||
|
|
Loading…
Reference in New Issue