Search in sources :

Example 26 with RefreshType

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

the class DaikinMadokaHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.debug("[{}] Channel: {}, Command: {}", super.thing.getUID().getId(), channelUID, command);
    if (command instanceof RefreshType) {
        // The binding will notify updates on channels
        return;
    }
    switch(channelUID.getId()) {
        case DaikinMadokaBindingConstants.CHANNEL_ID_CLEAN_FILTER_INDICATOR:
            OnOffType cleanFilterOrder = (OnOffType) command;
            if (cleanFilterOrder == OnOffType.OFF) {
                resetCleanFilterIndicator();
            }
            break;
        case DaikinMadokaBindingConstants.CHANNEL_ID_SETPOINT:
            try {
                QuantityType<Temperature> setpoint = (QuantityType<Temperature>) command;
                submitCommand(new SetSetpointCommand(setpoint, setpoint));
            } catch (Exception e) {
                logger.warn("Data received is not a valid temperature.", e);
            }
            break;
        case DaikinMadokaBindingConstants.CHANNEL_ID_EYE_BRIGHTNESS:
            try {
                logger.debug("Set eye brightness with value {}, {}", command.getClass().getName(), command);
                PercentType p = (PercentType) command;
                submitCommand(new SetEyeBrightnessCommand(p));
            } catch (Exception e) {
                logger.warn("Data received is not a valid Eye Brightness status", e);
            }
            break;
        case DaikinMadokaBindingConstants.CHANNEL_ID_ONOFF_STATUS:
            try {
                OnOffType oot = (OnOffType) command;
                submitCommand(new SetPowerstateCommand(oot));
            } catch (Exception e) {
                logger.warn("Data received is not a valid on/off status", e);
            }
            break;
        case DaikinMadokaBindingConstants.CHANNEL_ID_FAN_SPEED:
            try {
                DecimalType fanSpeed = (DecimalType) command;
                FanSpeed fs = FanSpeed.valueOf(fanSpeed.intValue());
                submitCommand(new SetFanspeedCommand(fs, fs));
            } catch (Exception e) {
                logger.warn("Data received is not a valid FanSpeed status", e);
            }
            break;
        case DaikinMadokaBindingConstants.CHANNEL_ID_OPERATION_MODE:
            try {
                StringType operationMode = (StringType) command;
                OperationMode m = OperationMode.valueOf(operationMode.toFullString());
                submitCommand(new SetOperationmodeCommand(m));
            } catch (Exception e) {
                logger.warn("Data received is not a valid OPERATION MODE", e);
            }
            break;
        case DaikinMadokaBindingConstants.CHANNEL_ID_HOMEBRIDGE_MODE:
            try {
                // Homebridge are discrete value different from Daikin
                // 0 - Off
                // 1 - Heating
                // 2 - Cooling
                // 3 - Auto
                DecimalType homebridgeMode = (DecimalType) command;
                switch(homebridgeMode.intValue()) {
                    case // Off
                    0:
                        submitCommand(new SetPowerstateCommand(OnOffType.OFF));
                        break;
                    case // Heating
                    1:
                        submitCommand(new SetOperationmodeCommand(OperationMode.HEAT));
                        if (madokaSettings.getOnOffState() == OnOffType.OFF) {
                            submitCommand(new SetPowerstateCommand(OnOffType.ON));
                        }
                        break;
                    case // Cooling
                    2:
                        submitCommand(new SetOperationmodeCommand(OperationMode.COOL));
                        if (madokaSettings.getOnOffState() == OnOffType.OFF) {
                            submitCommand(new SetPowerstateCommand(OnOffType.ON));
                        }
                        break;
                    case // Auto
                    3:
                        submitCommand(new SetOperationmodeCommand(OperationMode.AUTO));
                        if (madokaSettings.getOnOffState() == OnOffType.OFF) {
                            submitCommand(new SetPowerstateCommand(OnOffType.ON));
                        }
                        break;
                    default:
                        // Invalid Value - in case of new FW
                        logger.warn("Invalid value received for channel {}. Ignoring.", channelUID);
                        break;
                }
            } catch (Exception e) {
                logger.warn("Data received is not a valid HOMEBRIDGE OPERATION MODE", e);
            }
            break;
        case DaikinMadokaBindingConstants.CHANNEL_ID_HOMEKIT_TARGET_HEATING_COOLING_MODE:
            try {
                StringType homekitOperationMode = (StringType) command;
                switch(homekitOperationMode.toString()) {
                    case "Off":
                        submitCommand(new SetPowerstateCommand(OnOffType.OFF));
                        break;
                    case "CoolOn":
                        submitCommand(new SetOperationmodeCommand(OperationMode.COOL));
                        if (madokaSettings.getOnOffState() == OnOffType.OFF) {
                            submitCommand(new SetPowerstateCommand(OnOffType.ON));
                        }
                        break;
                    case "HeatOn":
                        submitCommand(new SetOperationmodeCommand(OperationMode.HEAT));
                        if (madokaSettings.getOnOffState() == OnOffType.OFF) {
                            submitCommand(new SetPowerstateCommand(OnOffType.ON));
                        }
                        break;
                    case "Auto":
                        submitCommand(new SetOperationmodeCommand(OperationMode.AUTO));
                        if (madokaSettings.getOnOffState() == OnOffType.OFF) {
                            submitCommand(new SetPowerstateCommand(OnOffType.ON));
                        }
                        break;
                    default:
                        break;
                }
            } catch (Exception e) {
                logger.info("Error while setting mode through HomeKIt received Mode");
            }
        default:
            break;
    }
}
Also used : Temperature(javax.measure.quantity.Temperature) StringType(org.openhab.core.library.types.StringType) SetSetpointCommand(org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.SetSetpointCommand) PercentType(org.openhab.core.library.types.PercentType) RefreshType(org.openhab.core.types.RefreshType) SetPowerstateCommand(org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.SetPowerstateCommand) MadokaParsingException(org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) SetOperationmodeCommand(org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.SetOperationmodeCommand) SetFanspeedCommand(org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.SetFanspeedCommand) OnOffType(org.openhab.core.library.types.OnOffType) QuantityType(org.openhab.core.library.types.QuantityType) DecimalType(org.openhab.core.library.types.DecimalType) SetEyeBrightnessCommand(org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands.SetEyeBrightnessCommand) FanSpeed(org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaProperties.FanSpeed) OperationMode(org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaProperties.OperationMode)

Example 27 with RefreshType

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

the class DaliRgbHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    try {
        if (CHANNEL_COLOR.equals(channelUID.getId())) {
            boolean queryDeviceState = false;
            if (command instanceof HSBType) {
                PercentType[] rgb = ((HSBType) command).toRGB();
                for (int i = 0; i < 3; i++) {
                    byte dimmValue = (byte) ((rgb[i].floatValue() * DALI_SWITCH_100_PERCENT) / 100);
                    getBridgeHandler().sendCommand(new DaliDAPCCommand(DaliAddress.createShortAddress(outputs.get(i)), dimmValue));
                }
            } else if (command instanceof OnOffType) {
                if ((OnOffType) command == OnOffType.ON) {
                    for (Integer output : outputs) {
                        getBridgeHandler().sendCommand(new DaliDAPCCommand(DaliAddress.createShortAddress(output), (byte) DALI_SWITCH_100_PERCENT));
                    }
                } else {
                    for (Integer output : outputs) {
                        getBridgeHandler().sendCommand(DaliStandardCommand.createOffCommand(DaliAddress.createShortAddress(output)));
                    }
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE) {
                    for (Integer output : outputs) {
                        getBridgeHandler().sendCommand(DaliStandardCommand.createUpCommand(DaliAddress.createShortAddress(output)));
                    }
                } else {
                    for (Integer output : outputs) {
                        getBridgeHandler().sendCommand(DaliStandardCommand.createDownCommand(DaliAddress.createShortAddress(output)));
                    }
                }
                queryDeviceState = true;
            } else if (command instanceof RefreshType) {
                queryDeviceState = true;
            }
            if (queryDeviceState) {
                CompletableFuture<@Nullable NumericMask> responseR = getBridgeHandler().sendCommandWithResponse(DaliStandardCommand.createQueryActualLevelCommand(DaliAddress.createShortAddress(outputs.get(0))), DaliResponse.NumericMask.class);
                CompletableFuture<@Nullable NumericMask> responseG = getBridgeHandler().sendCommandWithResponse(DaliStandardCommand.createQueryActualLevelCommand(DaliAddress.createShortAddress(outputs.get(1))), DaliResponse.NumericMask.class);
                CompletableFuture<@Nullable NumericMask> responseB = getBridgeHandler().sendCommandWithResponse(DaliStandardCommand.createQueryActualLevelCommand(DaliAddress.createShortAddress(outputs.get(2))), DaliResponse.NumericMask.class);
                CompletableFuture.allOf(responseR, responseG, responseB).thenAccept(x -> {
                    @Nullable NumericMask r = responseR.join(), g = responseG.join(), b = responseB.join();
                    if (r != null && !r.mask && g != null && !g.mask && b != null && !b.mask) {
                        Integer rValue = r.value != null ? r.value : 0;
                        Integer gValue = g.value != null ? g.value : 0;
                        Integer bValue = b.value != null ? b.value : 0;
                        updateState(channelUID, HSBType.fromRGB((int) (rValue.floatValue() * 255 / DALI_SWITCH_100_PERCENT), (int) (gValue.floatValue() * 255 / DALI_SWITCH_100_PERCENT), (int) (bValue.floatValue() * 255 / DALI_SWITCH_100_PERCENT)));
                    }
                }).exceptionally(e -> {
                    logger.warn("Error querying device status: {}", e.getMessage());
                    return null;
                });
            }
        }
    } catch (DaliException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
    }
}
Also used : IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) LoggerFactory(org.slf4j.LoggerFactory) OnOffType(org.openhab.core.library.types.OnOffType) CompletableFuture(java.util.concurrent.CompletableFuture) DaliDAPCCommand(org.openhab.binding.dali.internal.protocol.DaliDAPCCommand) BigDecimal(java.math.BigDecimal) Thing(org.openhab.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable) ChannelUID(org.openhab.core.thing.ChannelUID) DaliStandardCommand(org.openhab.binding.dali.internal.protocol.DaliStandardCommand) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ThingStatus(org.openhab.core.thing.ThingStatus) Command(org.openhab.core.types.Command) Logger(org.slf4j.Logger) RefreshType(org.openhab.core.types.RefreshType) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) BridgeHandler(org.openhab.core.thing.binding.BridgeHandler) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) List(java.util.List) DaliBindingConstants(org.openhab.binding.dali.internal.DaliBindingConstants) PercentType(org.openhab.core.library.types.PercentType) NumericMask(org.openhab.binding.dali.internal.protocol.DaliResponse.NumericMask) DaliResponse(org.openhab.binding.dali.internal.protocol.DaliResponse) HSBType(org.openhab.core.library.types.HSBType) DaliAddress(org.openhab.binding.dali.internal.protocol.DaliAddress) Bridge(org.openhab.core.thing.Bridge) PercentType(org.openhab.core.library.types.PercentType) DaliDAPCCommand(org.openhab.binding.dali.internal.protocol.DaliDAPCCommand) RefreshType(org.openhab.core.types.RefreshType) DaliResponse(org.openhab.binding.dali.internal.protocol.DaliResponse) OnOffType(org.openhab.core.library.types.OnOffType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) NumericMask(org.openhab.binding.dali.internal.protocol.DaliResponse.NumericMask) HSBType(org.openhab.core.library.types.HSBType)

Example 28 with RefreshType

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

the class DanfossAirUnitHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command instanceof RefreshType) {
        updateAllChannels();
    } else {
        try {
            DanfossAirUnit localAirUnit = this.airUnit;
            if (localAirUnit != null) {
                Channel channel = Channel.getByName(channelUID.getIdWithoutGroup());
                DanfossAirUnitWriteAccessor writeAccessor = channel.getWriteAccessor();
                if (writeAccessor != null) {
                    updateState(channelUID, writeAccessor.access(localAirUnit, command));
                }
            } else {
                updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.NONE, "@text/offline.connection-not-initialized");
                return;
            }
        } catch (IllegalArgumentException e) {
            logger.debug("Ignoring unknown channel id: {}", channelUID.getIdWithoutGroup(), e);
        } catch (IOException ioe) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, ioe.getMessage());
        }
    }
}
Also used : DanfossAirUnit(org.openhab.binding.danfossairunit.internal.DanfossAirUnit) Channel(org.openhab.binding.danfossairunit.internal.Channel) IOException(java.io.IOException) RefreshType(org.openhab.core.types.RefreshType) DanfossAirUnitWriteAccessor(org.openhab.binding.danfossairunit.internal.DanfossAirUnitWriteAccessor)

Example 29 with RefreshType

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

the class DenonMarantzConnector method sendInputCommand.

public void sendInputCommand(Command command, int zone) throws UnsupportedCommandTypeException {
    String zonePrefix;
    switch(zone) {
        case 1:
            zonePrefix = "SI";
            break;
        case 2:
        case 3:
        case 4:
            zonePrefix = "Z" + zone;
            break;
        default:
            throw new UnsupportedCommandTypeException("Zone must be in range [1-4], zone: " + zone);
    }
    String cmd = zonePrefix;
    if (command instanceof StringType) {
        cmd += command.toString();
    } else if (command instanceof RefreshType) {
        cmd += "?";
    } else {
        throw new UnsupportedCommandTypeException();
    }
    internalSendCommand(cmd);
}
Also used : UnsupportedCommandTypeException(org.openhab.binding.denonmarantz.internal.UnsupportedCommandTypeException) StringType(org.openhab.core.library.types.StringType) RefreshType(org.openhab.core.types.RefreshType)

Example 30 with RefreshType

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

the class ElectroluxAirHandler method handleCommand.

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.debug("Command received: {}", command);
    if (CHANNEL_STATUS.equals(channelUID.getId()) || command instanceof RefreshType) {
        update();
    } else {
        ElectroluxPureA9DTO dto = getElectroluxPureA9DTO();
        ElectroluxDeltaAPI api = getElectroluxDeltaAPO();
        if (api != null && dto != null) {
            if (CHANNEL_WORK_MODE.equals(channelUID.getId())) {
                if (command.toString().equals(COMMAND_WORKMODE_POWEROFF)) {
                    api.workModePowerOff(dto.getPncId());
                } else if (command.toString().equals(COMMAND_WORKMODE_AUTO)) {
                    api.workModeAuto(dto.getPncId());
                } else if (command.toString().equals(COMMAND_WORKMODE_MANUAL)) {
                    api.workModeManual(dto.getPncId());
                }
            } else if (CHANNEL_FAN_SPEED.equals(channelUID.getId())) {
                api.setFanSpeedLevel(dto.getPncId(), Integer.parseInt(command.toString()));
            } else if (CHANNEL_IONIZER.equals(channelUID.getId())) {
                if (command == OnOffType.OFF) {
                    api.setIonizer(dto.getPncId(), "false");
                } else if (command == OnOffType.ON) {
                    api.setIonizer(dto.getPncId(), "true");
                } else {
                    logger.debug("Unknown command! {}", command);
                }
            }
        }
    }
}
Also used : ElectroluxDeltaAPI(org.openhab.binding.electroluxair.internal.api.ElectroluxDeltaAPI) ElectroluxPureA9DTO(org.openhab.binding.electroluxair.internal.dto.ElectroluxPureA9DTO) RefreshType(org.openhab.core.types.RefreshType)

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