Search in sources :

Example 1 with RefreshType

use of org.openhab.core.types.RefreshType in project omatic by seaside1.

the class OMaticMachineThingHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logDebug("Handling command = {} for channel = {}", command.getClass(), channelUID);
    String channelId = channelUID.getIdWithoutGroup();
    OMaticChannel channel = OMaticChannel.fromString(channelId);
    if (command instanceof RefreshType) {
        refreshChannel(channel, channelId);
        return;
    }
    if (command instanceof OnOffType) {
        updateOnOffChannel(channel, channelId, (OnOffType) command);
        return;
    }
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType) RefreshType(org.openhab.core.types.RefreshType) OMaticChannel(org.openhab.binding.omatic.internal.OMaticChannel)

Example 2 with RefreshType

use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.

the class BenqProjectorHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    String channelId = channelUID.getId();
    if (command instanceof RefreshType) {
        Channel channel = this.thing.getChannel(channelUID);
        if (channel != null && getThing().getStatus() == ThingStatus.ONLINE) {
            updateChannelState(channel);
        }
    } else {
        BenqProjectorCommandType benqCommand = BenqProjectorCommandType.getCommandType(channelId);
        sendDataToDevice(benqCommand, command);
    }
}
Also used : BenqProjectorCommandType(org.openhab.binding.benqprojector.internal.BenqProjectorCommandType) Channel(org.openhab.core.thing.Channel) RefreshType(org.openhab.core.types.RefreshType)

Example 3 with RefreshType

use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.

the class Cm11aLampHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.debug("**** Cm11aLampHandler handleCommand command = {}, channelUID = {}", command.toString(), channelUID.getAsString());
    x10Function = 0;
    Bridge bridge = getBridge();
    if (bridge == null) {
        logger.debug("Unable to handle command. Bridge is null.");
        return;
    }
    this.channelUID = channelUID;
    Cm11aBridgeHandler cm11aHandler = (Cm11aBridgeHandler) bridge.getHandler();
    if (cm11aHandler != null && cm11aHandler.getThing().getStatus().equals(ThingStatus.ONLINE)) {
        if (OnOffType.ON.equals(command)) {
            desiredState = OnOffType.ON;
        } else if (OnOffType.OFF.equals(command)) {
            desiredState = OnOffType.OFF;
        } else if (command instanceof PercentType) {
            desiredState = (PercentType) command;
        } else if (command instanceof RefreshType) {
            // Refresh is triggered by framework during startup.
            // Force the lamp off by indicating it is currently on and we want it off
            // Start with it off
            desiredState = PercentType.ZERO;
            logger.info("Received REFRESH command for switch {}", houseUnitCode);
        } else {
            logger.error("Ignoring unknown command received for device: {}", houseUnitCode);
        }
        if (!(desiredState instanceof UnDefType)) {
            X10Interface x10Interface = cm11aHandler.getX10Interface();
            x10Interface.scheduleHWUpdate(this);
        }
    } else {
        logger.error("Attempted to change switch {} cm11a is not online", houseUnitCode);
    }
}
Also used : X10Interface(org.openhab.binding.cm11a.internal.X10Interface) UnDefType(org.openhab.core.types.UnDefType) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) Bridge(org.openhab.core.thing.Bridge)

Example 4 with RefreshType

use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.

the class ComfoAirHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    String channelId = channelUID.getId();
    if (comfoAirConnector != null) {
        boolean isActive = !comfoAirConnector.getIsSuspended();
        if (isActive || channelId.equals(ACTIVATE_CHANNEL_ID)) {
            if (command instanceof RefreshType) {
                Channel channel = this.thing.getChannel(channelUID);
                if (channel != null) {
                    updateChannelState(channel);
                }
            } else {
                ComfoAirCommand changeCommand = ComfoAirCommandType.getChangeCommand(channelId, command);
                if (changeCommand != null) {
                    Set<String> keysToUpdate = getThing().getChannels().stream().map(Channel::getUID).filter(this::isLinked).map(ChannelUID::getId).collect(Collectors.toSet());
                    sendCommand(changeCommand, channelId);
                    Collection<ComfoAirCommand> affectedReadCommands = ComfoAirCommandType.getAffectedReadCommands(channelId, keysToUpdate);
                    if (!affectedReadCommands.isEmpty()) {
                        Runnable updateThread = new AffectedItemsUpdateThread(affectedReadCommands, keysToUpdate);
                        affectedItemsPoller = scheduler.schedule(updateThread, 3, TimeUnit.SECONDS);
                    }
                } else {
                    logger.warn("Unhandled command type: {}, channelId: {}", command.toString(), channelId);
                }
            }
        } else {
            logger.debug("Binding control is currently not active.");
        }
    }
}
Also used : Channel(org.openhab.core.thing.Channel) RefreshType(org.openhab.core.types.RefreshType)

Example 5 with RefreshType

use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.

the class CBusDaliHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    Group group = this.group;
    if (group == null) {
        return;
    }
    if (command instanceof RefreshType) {
        try {
            int level = group.getLevel();
            logger.debug("handle RefreshType Command for Chanell {} Group {} level {}", channelUID, groupId, level);
            if (channelUID.getId().equals(CBusBindingConstants.CHANNEL_LEVEL)) {
                updateState(channelUID, new PercentType((int) (level * 100 / 255.0)));
            }
        } catch (CGateException e) {
            logger.debug("Failed to getLevel for group {}", groupId, e);
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication Error");
        }
    } else {
        if (channelUID.getId().equals(CBusBindingConstants.CHANNEL_LEVEL)) {
            logger.debug("Channel Level command for {}: {}", channelUID, command);
            try {
                if (command instanceof OnOffType) {
                    if (command == OnOffType.ON) {
                        group.on();
                    } else if (command == OnOffType.OFF) {
                        group.off();
                    }
                } else if (command instanceof PercentType) {
                    PercentType value = (PercentType) command;
                    group.ramp((int) Math.round(value.doubleValue() / 100 * 255), 0);
                } else if (command instanceof IncreaseDecreaseType) {
                    int level = group.getLevel();
                    if (command == IncreaseDecreaseType.DECREASE) {
                        level = Math.max(level - 1, 0);
                    } else if (command == IncreaseDecreaseType.INCREASE) {
                        level = Math.min(level + 1, 255);
                    }
                    group.ramp(level, 0);
                    logger.debug("Change group level to {}", level);
                }
            } catch (CGateException e) {
                logger.debug("Cannot send command {} to {}", command, group, e);
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication Error");
            }
        }
    }
}
Also used : Group(com.daveoxley.cbus.Group) OnOffType(org.openhab.core.library.types.OnOffType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) CGateException(com.daveoxley.cbus.CGateException)

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