use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class HeosChannelHandlerPlayerSelect method handleBridgeCommand.
@Override
public void handleBridgeCommand(Command command, ThingUID uid) {
if (command instanceof RefreshType) {
return;
}
Channel channel = bridge.getThing().getChannel(channelUID.getId());
if (channel == null) {
logger.debug("Channel {} not found", channelUID);
return;
}
List<String[]> selectedPlayerList = bridge.getSelectedPlayerList();
if (command.equals(OnOffType.ON)) {
String[] selectedPlayerInfo = new String[2];
selectedPlayerInfo[0] = channel.getProperties().get(PID);
selectedPlayerInfo[1] = channelUID.getId();
selectedPlayerList.add(selectedPlayerInfo);
} else if (!selectedPlayerList.isEmpty()) {
int indexPlayerChannel = -1;
for (int i = 0; i < selectedPlayerList.size(); i++) {
String localPID = selectedPlayerList.get(i)[0];
if (localPID.equals(channel.getProperties().get(PID))) {
indexPlayerChannel = i;
}
}
selectedPlayerList.remove(indexPlayerChannel);
bridge.setSelectedPlayerList(selectedPlayerList);
}
}
use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class InnogyDeviceHandler method handleCommand.
@Override
public void handleCommand(final ChannelUID channelUID, final Command command) {
logger.debug("handleCommand called for channel '{}' of type '{}' with command '{}'", channelUID, getThing().getThingTypeUID().getId(), command);
@Nullable final InnogyBridgeHandler innogyBridgeHandler = getInnogyBridgeHandler();
if (innogyBridgeHandler == null) {
logger.warn("BridgeHandler not found. Cannot handle command without bridge.");
return;
}
if (!ThingStatus.ONLINE.equals(innogyBridgeHandler.getThing().getStatus())) {
logger.debug("Cannot handle command - bridge is not online. Command ignored.");
return;
}
if (command instanceof RefreshType) {
@Nullable final Device device = innogyBridgeHandler.getDeviceById(deviceId);
if (device != null) {
onDeviceStateChanged(device);
}
return;
}
// SWITCH
if (CHANNEL_SWITCH.equals(channelUID.getId())) {
// DEBUGGING HELPER
// ----------------
@Nullable final Device device = innogyBridgeHandler.getDeviceById(deviceId);
if (device != null && DEBUG.equals(device.getConfig().getName())) {
logger.debug("DEBUG SWITCH ACTIVATED!");
if (OnOffType.ON.equals(command)) {
innogyBridgeHandler.onEvent("{\"sequenceNumber\": -1,\"type\": \"MessageCreated\",\"desc\": \"/desc/event/MessageCreated\",\"namespace\": \"core.RWE\",\"timestamp\": \"2019-07-07T18:41:47.2970000Z\",\"source\": \"/desc/device/SHC.RWE/1.0\",\"data\": {\"id\": \"6e5ce2290cd247208f95a5b53736958b\",\"type\": \"DeviceLowBattery\",\"read\": false,\"class\": \"Alert\",\"timestamp\": \"2019-07-07T18:41:47.232Z\",\"devices\": [\"/device/fe51785319854f36a621d0b4f8ea0e25\"],\"properties\": {\"deviceName\": \"Heizkörperthermostat\",\"serialNumber\": \"914110165056\",\"locationName\": \"Bad\"},\"namespace\": \"core.RWE\"}}");
} else {
innogyBridgeHandler.onEvent("{\"sequenceNumber\": -1,\"type\": \"MessageDeleted\",\"desc\": \"/desc/event/MessageDeleted\",\"namespace\": \"core.RWE\",\"timestamp\": \"2019-07-07T19:15:39.2100000Z\",\"data\": { \"id\": \"6e5ce2290cd247208f95a5b53736958b\" }}");
}
return;
}
// ----------------
if (command instanceof OnOffType) {
innogyBridgeHandler.commandSwitchDevice(deviceId, OnOffType.ON.equals(command));
}
// DIMMER
} else if (CHANNEL_DIMMER.equals(channelUID.getId())) {
if (command instanceof DecimalType) {
final DecimalType dimLevel = (DecimalType) command;
innogyBridgeHandler.commandSetDimmLevel(deviceId, dimLevel.intValue());
} else if (command instanceof OnOffType) {
if (OnOffType.ON.equals(command)) {
innogyBridgeHandler.commandSetDimmLevel(deviceId, 100);
} else {
innogyBridgeHandler.commandSetDimmLevel(deviceId, 0);
}
}
// ROLLERSHUTTER
} else if (CHANNEL_ROLLERSHUTTER.equals(channelUID.getId())) {
if (command instanceof DecimalType) {
final DecimalType rollerShutterLevel = (DecimalType) command;
innogyBridgeHandler.commandSetRollerShutterLevel(deviceId, invertValueIfConfigured(CHANNEL_ROLLERSHUTTER, rollerShutterLevel.intValue()));
} else if (command instanceof OnOffType) {
if (OnOffType.ON.equals(command)) {
innogyBridgeHandler.commandSetRollerShutterStop(deviceId, ShutterAction.ShutterActions.DOWN);
} else {
innogyBridgeHandler.commandSetRollerShutterStop(deviceId, ShutterAction.ShutterActions.UP);
}
} else if (command instanceof UpDownType) {
if (UpDownType.DOWN.equals(command)) {
innogyBridgeHandler.commandSetRollerShutterStop(deviceId, ShutterAction.ShutterActions.DOWN);
} else {
innogyBridgeHandler.commandSetRollerShutterStop(deviceId, ShutterAction.ShutterActions.UP);
}
} else if (command instanceof StopMoveType) {
if (StopMoveType.STOP.equals(command)) {
innogyBridgeHandler.commandSetRollerShutterStop(deviceId, ShutterAction.ShutterActions.STOP);
}
}
// SET_TEMPERATURE
} else if (CHANNEL_SET_TEMPERATURE.equals(channelUID.getId())) {
if (command instanceof DecimalType) {
final DecimalType pointTemperature = (DecimalType) command;
innogyBridgeHandler.commandUpdatePointTemperature(deviceId, pointTemperature.doubleValue());
}
// OPERATION_MODE
} else if (CHANNEL_OPERATION_MODE.equals(channelUID.getId())) {
if (command instanceof StringType) {
final String autoModeCommand = command.toString();
if (CapabilityState.STATE_VALUE_OPERATION_MODE_AUTO.equals(autoModeCommand)) {
innogyBridgeHandler.commandSetOperationMode(deviceId, true);
} else if (CapabilityState.STATE_VALUE_OPERATION_MODE_MANUAL.equals(autoModeCommand)) {
innogyBridgeHandler.commandSetOperationMode(deviceId, false);
} else {
logger.warn("Could not set operationmode. Invalid value '{}'! Only '{}' or '{}' allowed.", autoModeCommand, CapabilityState.STATE_VALUE_OPERATION_MODE_AUTO, CapabilityState.STATE_VALUE_OPERATION_MODE_MANUAL);
}
}
// ALARM
} else if (CHANNEL_ALARM.equals(channelUID.getId())) {
if (command instanceof OnOffType) {
innogyBridgeHandler.commandSwitchAlarm(deviceId, OnOffType.ON.equals(command));
}
} else {
logger.debug("UNSUPPORTED channel {} for device {}.", channelUID.getId(), deviceId);
}
}
use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class LaMetricTimeHandler method handleAudioCommand.
private void handleAudioCommand(ChannelUID channelUID, Command command) {
Audio audio = clock.getLocalApi().getAudio();
if (command instanceof RefreshType) {
updateState(channelUID, new PercentType(audio.getVolume()));
} else if (command instanceof PercentType) {
try {
PercentType percentTypeCommand = (PercentType) command;
int volume = percentTypeCommand.intValue();
if (volume >= 0 && volume != audio.getVolume()) {
audio.setVolume(volume);
clock.getLocalApi().updateAudio(audio);
updateStatus(ThingStatus.ONLINE);
}
} catch (UpdateException e) {
logger.debug("Failed to update audio volume - taking clock offline", e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
}
use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class LcnModuleHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUid, Command command) {
try {
String groupId = channelUid.getGroupId();
if (!channelUid.isInGroup()) {
return;
}
if (groupId == null) {
throw new LcnException("Group ID is null");
}
LcnChannelGroup channelGroup = LcnChannelGroup.valueOf(groupId.toUpperCase());
AbstractLcnModuleSubHandler subHandler = subHandlers.get(channelGroup);
if (subHandler == null) {
throw new LcnException("Sub Handler not found for: " + channelGroup);
}
Optional<Integer> number = channelUidToChannelNumber(channelUid, channelGroup);
if (command instanceof RefreshType) {
number.ifPresent(n -> subHandler.handleRefresh(channelGroup, n));
subHandler.handleRefresh(channelUid.getIdWithoutGroup());
} else if (command instanceof OnOffType) {
subHandler.handleCommandOnOff((OnOffType) command, channelGroup, number.get());
} else if (command instanceof DimmerOutputCommand) {
subHandler.handleCommandDimmerOutput((DimmerOutputCommand) command, number.get());
} else if (command instanceof PercentType && number.isPresent()) {
subHandler.handleCommandPercent((PercentType) command, channelGroup, number.get());
} else if (command instanceof HSBType) {
subHandler.handleCommandHsb((HSBType) command, channelUid.getIdWithoutGroup());
} else if (command instanceof PercentType) {
subHandler.handleCommandPercent((PercentType) command, channelGroup, channelUid.getIdWithoutGroup());
} else if (command instanceof StringType) {
subHandler.handleCommandString((StringType) command, number.get());
} else if (command instanceof DecimalType) {
DecimalType decimalType = (DecimalType) command;
DecimalType nativeValue = getConverter(channelUid).onCommandFromItem(decimalType.doubleValue());
subHandler.handleCommandDecimal(nativeValue, channelGroup, number.get());
} else if (command instanceof QuantityType) {
QuantityType<?> quantityType = (QuantityType<?>) command;
DecimalType nativeValue = getConverter(channelUid).onCommandFromItem(quantityType);
subHandler.handleCommandDecimal(nativeValue, channelGroup, number.get());
} else if (command instanceof UpDownType) {
Channel channel = thing.getChannel(channelUid);
if (channel != null) {
Object invertConfig = channel.getConfiguration().get("invertUpDown");
boolean invertUpDown = invertConfig instanceof Boolean && (boolean) invertConfig;
subHandler.handleCommandUpDown((UpDownType) command, channelGroup, number.get(), invertUpDown);
}
} else if (command instanceof StopMoveType) {
subHandler.handleCommandStopMove((StopMoveType) command, channelGroup, number.get());
} else {
throw new LcnException("Unsupported command type");
}
} catch (IllegalArgumentException | NoSuchElementException | LcnException e) {
logger.warn("{}: Failed to handle command {}: {}", channelUid, command.getClass().getSimpleName(), e.getMessage());
}
}
use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class AdorneSwitchHandler method handleCommand.
/**
* Handles refresh and on/off commands for channel
* {@link org.openhab.binding.adorne.internal.AdorneBindingConstants#CHANNEL_POWER}
*/
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.trace("handleCommand (channelUID:{} command:{}", channelUID, command);
try {
if (channelUID.getId().equals(CHANNEL_POWER)) {
if (command instanceof OnOffType) {
AdorneHubController adorneHubController = getAdorneHubController();
adorneHubController.setOnOff(zoneId, command.equals(OnOffType.ON));
} else if (command instanceof RefreshType) {
refreshOnOff();
}
}
} catch (IllegalStateException e) {
// Hub controller could't handle our commands. Unfortunately the framework has no mechanism to report
// runtime errors. If we throw the exception up the framework logs it as an error - we don't want that - we
// want the framework to handle it gracefully. No point to update the thing status, since the
// AdorneHubController already does that. So we are forced to swallow the exception here.
logger.debug("Failed to execute command {} for channel {} for thing {} ({})", command, channelUID, getThing().getLabel(), e.getMessage());
}
}
Aggregations