case CHANNEL_SENSOR_SLEEPTIME:
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)
: 0;
api.setSleepTime(value);
logger.debug("{}: Select profile {}", thingName, command);
int id = -1;
if (command instanceof Number) {
- id = (int) getNumber(command);
+ id = getNumber(command).intValue();
} else {
String cmd = command.toString();
if (isDigit(cmd.charAt(0))) {
break;
case CHANNEL_CONTROL_SETTEMP:
logger.debug("{}: Set temperature to {}", thingName, command);
- api.setValveTemperature(0, (int) getNumber(command));
+ api.setValveTemperature(0, getNumber(command).intValue());
break;
case CHANNEL_CONTROL_POSITION:
logger.debug("{}: Set position to {}", thingName, command);
break;
case CHANNEL_CONTROL_BTIMER:
logger.debug("{}: Set boost timer to {}", thingName, command);
- api.setValveBoostTime(0, (int) getNumber(command));
+ api.setValveBoostTime(0, getNumber(command).intValue());
break;
case CHANNEL_SENSOR_MUTE:
if (profile.isSmoke && ((OnOffType) command) == OnOffType.ON) {
}
}
- 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
*/
}
public static Double getNumber(Command command) throws IllegalArgumentException {
+ if (command instanceof QuantityType<?> quantityCommand) {
+ return quantityCommand.doubleValue();
+ }
if (command instanceof DecimalType decimalCommand) {
return decimalCommand.doubleValue();
}
- if (command instanceof QuantityType<?> quantityCommand) {
- return quantityCommand.doubleValue();
+ if (command instanceof Number numberCommand) {
+ return numberCommand.doubleValue();
}
- throw new IllegalArgumentException("Unable to convert number");
+ throw new IllegalArgumentException("Invalid Number type for conversion: " + command);
}
public static OnOffType getOnOff(@Nullable Boolean value) {