Search in sources :

Example 11 with RefreshType

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);
    }
}
Also used : Channel(org.openhab.core.thing.Channel) RefreshType(org.openhab.core.types.RefreshType)

Example 12 with RefreshType

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);
    }
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType) StringType(org.openhab.core.library.types.StringType) Device(org.openhab.binding.innogysmarthome.internal.client.entity.device.Device) DecimalType(org.openhab.core.library.types.DecimalType) UpDownType(org.openhab.core.library.types.UpDownType) RefreshType(org.openhab.core.types.RefreshType) Nullable(org.eclipse.jdt.annotation.Nullable) StopMoveType(org.openhab.core.library.types.StopMoveType)

Example 13 with RefreshType

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());
        }
    }
}
Also used : PercentType(org.openhab.core.library.types.PercentType) UpdateException(org.openhab.binding.lametrictime.api.local.UpdateException) Audio(org.openhab.binding.lametrictime.api.local.model.Audio) RefreshType(org.openhab.core.types.RefreshType)

Example 14 with RefreshType

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());
    }
}
Also used : AbstractLcnModuleSubHandler(org.openhab.binding.lcn.internal.subhandler.AbstractLcnModuleSubHandler) LcnChannelGroup(org.openhab.binding.lcn.internal.common.LcnChannelGroup) StringType(org.openhab.core.library.types.StringType) LcnException(org.openhab.binding.lcn.internal.common.LcnException) Channel(org.openhab.core.thing.Channel) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) StopMoveType(org.openhab.core.library.types.StopMoveType) DimmerOutputCommand(org.openhab.binding.lcn.internal.common.DimmerOutputCommand) OnOffType(org.openhab.core.library.types.OnOffType) QuantityType(org.openhab.core.library.types.QuantityType) DecimalType(org.openhab.core.library.types.DecimalType) HSBType(org.openhab.core.library.types.HSBType) NoSuchElementException(java.util.NoSuchElementException)

Example 15 with RefreshType

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());
    }
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType) RefreshType(org.openhab.core.types.RefreshType) AdorneHubController(org.openhab.binding.adorne.internal.hub.AdorneHubController)

Aggregations

RefreshType (org.openhab.core.types.RefreshType)210 OnOffType (org.openhab.core.library.types.OnOffType)81 StringType (org.openhab.core.library.types.StringType)66 DecimalType (org.openhab.core.library.types.DecimalType)60 PercentType (org.openhab.core.library.types.PercentType)50 QuantityType (org.openhab.core.library.types.QuantityType)29 Channel (org.openhab.core.thing.Channel)26 State (org.openhab.core.types.State)26 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)25 IOException (java.io.IOException)22 Nullable (org.eclipse.jdt.annotation.Nullable)18 Bridge (org.openhab.core.thing.Bridge)18 ChannelUID (org.openhab.core.thing.ChannelUID)16 HSBType (org.openhab.core.library.types.HSBType)15 BigDecimal (java.math.BigDecimal)14 DateTimeType (org.openhab.core.library.types.DateTimeType)11 UpDownType (org.openhab.core.library.types.UpDownType)11 Temperature (javax.measure.quantity.Temperature)8 Thing (org.openhab.core.thing.Thing)8 Command (org.openhab.core.types.Command)8