use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class StateUtil method getAllStates.
public static List<State> getAllStates() {
LinkedList<State> states = new LinkedList<>();
DateTimeType dateTime = new DateTimeType();
states.add(dateTime);
DecimalType decimal = new DecimalType(23);
states.add(decimal);
PercentType percent = new PercentType(50);
states.add(percent);
HSBType hsb = new HSBType("50,75,42");
states.add(hsb);
states.add(OnOffType.ON);
states.add(OnOffType.OFF);
states.add(OpenClosedType.OPEN);
states.add(OpenClosedType.CLOSED);
states.add(PlayPauseType.PLAY);
states.add(PlayPauseType.PAUSE);
PointType point = new PointType("42.23,23.5");
states.add(point);
RawType raw = new RawType(new byte[0], "application/octet-stream");
states.add(raw);
states.add(RewindFastforwardType.REWIND);
states.add(RewindFastforwardType.FASTFORWARD);
StringListType stringList = new StringListType(new String[] { "foo", "bar" });
states.add(stringList);
StringType string = new StringType("foo");
states.add(string);
states.add(UnDefType.NULL);
states.add(UnDefType.UNDEF);
states.add(UpDownType.UP);
states.add(UpDownType.DOWN);
QuantityType<Temperature> quantityType = new QuantityType<Temperature>("12 °C");
states.add(quantityType);
return states;
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class DeviceHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
BridgeHandler dssBridgeHandler = getDssBridgeHandler();
if (dssBridgeHandler == null) {
logger.debug("BridgeHandler not found. Cannot handle command without bridge.");
return;
}
if (device == null) {
logger.debug("Device not known on StructureManager or DeviceStatusListener is not registerd. Cannot handle command.");
return;
}
if (command instanceof RefreshType) {
try {
SensorEnum sensorType = SensorEnum.valueOf(channelUID.getId());
dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(sensorType, 1));
} catch (IllegalArgumentException e) {
dssBridgeHandler.sendComandsToDSS(device, new DeviceStateUpdateImpl(DeviceStateUpdate.REFRESH_OUTPUT, 0));
}
} else if (!device.isShade()) {
if (DsChannelTypeProvider.isOutputChannel(channelUID.getId())) {
if (command instanceof PercentType) {
device.setOutputValue((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxOutputValue()));
} else if (command instanceof OnOffType) {
if (OnOffType.ON.equals(command)) {
device.setIsOn(true);
} else {
device.setIsOn(false);
}
} else if (command instanceof IncreaseDecreaseType) {
if (IncreaseDecreaseType.INCREASE.equals(command)) {
device.increase();
} else {
device.decrease();
}
} else if (command instanceof StringType) {
device.setOutputValue(Short.parseShort(((StringType) command).toString()));
}
} else {
logger.debug("Command sent to an unknown channel id: {}", channelUID);
}
} else {
if (channelUID.getId().contains(DsChannelTypeProvider.ANGLE)) {
if (command instanceof PercentType) {
device.setAnglePosition((short) fromPercentToValue(((PercentType) command).intValue(), device.getMaxSlatAngle()));
} else if (command instanceof OnOffType) {
if (OnOffType.ON.equals(command)) {
device.setAnglePosition(device.getMaxSlatAngle());
} else {
device.setAnglePosition(device.getMinSlatAngle());
}
} else if (command instanceof IncreaseDecreaseType) {
if (IncreaseDecreaseType.INCREASE.equals(command)) {
device.increaseSlatAngle();
} else {
device.decreaseSlatAngle();
}
}
} else if (channelUID.getId().contains(DsChannelTypeProvider.SHADE)) {
if (command instanceof PercentType) {
int percent = ((PercentType) command).intValue();
if (!device.getHWinfo().equals("GR-KL200")) {
percent = 100 - percent;
}
device.setSlatPosition(fromPercentToValue(percent, device.getMaxSlatPosition()));
this.lastComand = command;
} else if (command instanceof StopMoveType) {
if (StopMoveType.MOVE.equals(command)) {
handleCommand(channelUID, this.lastComand);
} else {
dssBridgeHandler.stopOutputValue(device);
}
} else if (command instanceof UpDownType) {
if (UpDownType.UP.equals(command)) {
device.setIsOpen(true);
this.lastComand = command;
} else {
device.setIsOpen(false);
this.lastComand = command;
}
}
} else {
logger.debug("Command sent to an unknown channel id: {}", channelUID);
}
}
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class DeviceHandler method onDeviceStateChanged.
@Override
public synchronized void onDeviceStateChanged(DeviceStateUpdate deviceStateUpdate) {
if (device != null) {
if (deviceStateUpdate != null) {
if (sensorChannelsLoaded()) {
if (deviceStateUpdate.isSensorUpdateType()) {
updateState(getSensorChannelID(deviceStateUpdate.getTypeAsSensorEnum()), new DecimalType(deviceStateUpdate.getValueAsFloat()));
logger.debug("Update ESH-State");
return;
}
if (deviceStateUpdate.isBinarayInputType()) {
if (deviceStateUpdate.getValueAsShort() == 1) {
updateState(getBinaryInputChannelID(deviceStateUpdate.getTypeAsDeviceBinarayInputEnum()), OnOffType.ON);
} else {
updateState(getBinaryInputChannelID(deviceStateUpdate.getTypeAsDeviceBinarayInputEnum()), OnOffType.OFF);
}
}
}
if (!device.isShade()) {
if (currentChannel != null) {
switch(deviceStateUpdate.getType()) {
case DeviceStateUpdate.OUTPUT_DECREASE:
case DeviceStateUpdate.OUTPUT_INCREASE:
case DeviceStateUpdate.OUTPUT:
if (currentChannel.contains(DsChannelTypeProvider.DIMMER)) {
if (deviceStateUpdate.getValueAsInteger() > 0) {
updateState(currentChannel, new PercentType(fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxOutputValue())));
} else {
updateState(currentChannel, OnOffType.OFF);
}
} else if (currentChannel.contains(DsChannelTypeProvider.STAGE)) {
if (currentChannel.contains(TWO_STAGE_SWITCH_IDENTICATOR)) {
updateState(currentChannel, new StringType(convertStageValue((short) 2, device.getOutputValue())));
} else {
updateState(currentChannel, new StringType(convertStageValue((short) 3, device.getOutputValue())));
}
}
break;
case DeviceStateUpdate.ON_OFF:
if (currentChannel.contains(DsChannelTypeProvider.STAGE)) {
onDeviceStateChanged(new DeviceStateUpdateImpl(DeviceStateUpdate.OUTPUT, device.getOutputValue()));
}
if (deviceStateUpdate.getValueAsInteger() > 0) {
updateState(currentChannel, OnOffType.ON);
} else {
updateState(currentChannel, OnOffType.OFF);
}
break;
default:
return;
}
}
} else {
int percent = 0;
switch(deviceStateUpdate.getType()) {
case DeviceStateUpdate.SLAT_DECREASE:
case DeviceStateUpdate.SLAT_INCREASE:
case DeviceStateUpdate.SLATPOSITION:
percent = fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxSlatPosition());
break;
case DeviceStateUpdate.OPEN_CLOSE:
if (deviceStateUpdate.getValueAsInteger() > 0) {
percent = 100;
}
break;
case DeviceStateUpdate.OPEN_CLOSE_ANGLE:
if (device.isBlind() && currentChannel != null) {
if (deviceStateUpdate.getValueAsInteger() > 0) {
updateState(currentChannel, PercentType.HUNDRED);
} else {
updateState(currentChannel, PercentType.ZERO);
}
}
return;
case DeviceStateUpdate.SLAT_ANGLE_DECREASE:
case DeviceStateUpdate.SLAT_ANGLE_INCREASE:
case DeviceStateUpdate.SLAT_ANGLE:
if (device.isBlind() && currentChannel != null) {
updateState(currentChannel, new PercentType(fromValueToPercent(deviceStateUpdate.getValueAsInteger(), device.getMaxSlatAngle())));
}
return;
default:
return;
}
if (!device.getHWinfo().equals("GR-KL210")) {
percent = 100 - percent;
}
updateState(DsChannelTypeProvider.SHADE, new PercentType(percent));
}
logger.debug("Update ESH-State");
}
}
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class LifxLightCurrentStateUpdater method handleInfraredStatus.
private void handleInfraredStatus(StateLightInfraredResponse packet) {
PercentType infrared = infraredToPercentType(packet.getInfrared());
currentLightState.setInfrared(infrared);
}
use of org.eclipse.smarthome.core.library.types.PercentType in project smarthome by eclipse.
the class LifxLightHandler method handleIncreaseDecreaseInfraredCommand.
private void handleIncreaseDecreaseInfraredCommand(IncreaseDecreaseType increaseDecrease) {
PercentType baseInfrared = getLightStateForCommand().getInfrared();
if (baseInfrared != null) {
PercentType newInfrared = increaseDecreasePercentType(increaseDecrease, baseInfrared);
handleInfraredCommand(newInfrared);
}
}
Aggregations