Search in sources :

Example 6 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class KNXCoreTypeMapper method toDPTValue.

/*
     * (non-Javadoc)
     *
     * @see org.openhab.binding.knx.config.KNXTypeMapper#toDPTValue(org.openhab.core.types.Type, java.lang.String)
     */
@Override
public String toDPTValue(Type type, String dptID) {
    DPT dpt;
    int mainNumber = getMainNumber(dptID);
    if (mainNumber == -1) {
        logger.error("toDPTValue couldn't identify mainnumber in dptID: {}", dptID);
        return null;
    }
    try {
        DPTXlator translator = TranslatorTypes.createTranslator(mainNumber, dptID);
        dpt = translator.getType();
    } catch (KNXException e) {
        e.printStackTrace();
        return null;
    }
    // check for HSBType first, because it extends PercentType as well
    if (type instanceof HSBType) {
        Color color = ((HSBType) type).toColor();
        return "r:" + Integer.toString(color.getRed()) + " g:" + Integer.toString(color.getGreen()) + " b:" + Integer.toString(color.getBlue());
    } else if (type instanceof OnOffType) {
        return type.equals(OnOffType.OFF) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof UpDownType) {
        return type.equals(UpDownType.UP) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof IncreaseDecreaseType) {
        DPT valueDPT = ((DPTXlator3BitControlled.DPT3BitControlled) dpt).getControlDPT();
        return type.equals(IncreaseDecreaseType.DECREASE) ? valueDPT.getLowerValue() + " 5" : valueDPT.getUpperValue() + " 5";
    } else if (type instanceof OpenClosedType) {
        return type.equals(OpenClosedType.CLOSED) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof StopMoveType) {
        return type.equals(StopMoveType.STOP) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof PercentType) {
        return type.toString();
    } else if (type instanceof DecimalType) {
        switch(mainNumber) {
            case 2:
                DPT valueDPT = ((DPTXlator1BitControlled.DPT1BitControlled) dpt).getValueDPT();
                switch(((DecimalType) type).intValue()) {
                    case 0:
                        return "0 " + valueDPT.getLowerValue();
                    case 1:
                        return "0 " + valueDPT.getUpperValue();
                    case 2:
                        return "1 " + valueDPT.getLowerValue();
                    default:
                        return "1 " + valueDPT.getUpperValue();
                }
            case 18:
                int intVal = ((DecimalType) type).intValue();
                if (intVal > 63) {
                    return "learn " + (intVal - 0x80);
                } else {
                    return "activate " + intVal;
                }
            default:
                return type.toString();
        }
    } else if (type instanceof StringType) {
        return type.toString();
    } else if (type instanceof DateTimeType) {
        return formatDateTime((DateTimeType) type, dptID);
    }
    logger.debug("toDPTValue: Couldn't get value for {} dpt id {} (no mapping).", type, dptID);
    return null;
}
Also used : KNXException(tuwien.auto.calimero.exception.KNXException) StringType(org.openhab.core.library.types.StringType) Color(java.awt.Color) DPT(tuwien.auto.calimero.dptxlator.DPT) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) Datapoint(tuwien.auto.calimero.datapoint.Datapoint) StopMoveType(org.openhab.core.library.types.StopMoveType) DateTimeType(org.openhab.core.library.types.DateTimeType) DPTXlator(tuwien.auto.calimero.dptxlator.DPTXlator) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DPTXlator3BitControlled(tuwien.auto.calimero.dptxlator.DPTXlator3BitControlled) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) DPTXlator1BitControlled(tuwien.auto.calimero.dptxlator.DPTXlator1BitControlled) HSBType(org.openhab.core.library.types.HSBType)

Example 7 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class Ipx800OutputItem method updateStateInternal.

@Override
protected boolean updateStateInternal(Type state) {
    boolean changed = false;
    if (state instanceof OnOffType) {
        OnOffType commandState = (OnOffType) state;
        if (!lastState.equals(commandState)) {
            changed = true;
            lastState = commandState;
        }
    }
    if (changed && fromItem != null) {
        fromItem.updateStateToCore(lastState);
    }
    return changed;
}
Also used : OnOffType(org.openhab.core.library.types.OnOffType)

Example 8 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class SappBinding method executeSappCommand.

/**
     * executes the real command on pnmas device
     */
private void executeSappCommand(String itemName, Command command) {
    SappBindingProvider provider = findFirstMatchingBindingProvider(itemName);
    if (provider == null) {
        logger.error("cannot find a provider, skipping command");
    }
    try {
        Item item = itemRegistry.getItem(itemName);
        logger.debug("found item {}", item);
        if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
            SappBindingConfigSwitchItem sappBindingConfigSwitchItem = (SappBindingConfigSwitchItem) provider.getBindingConfig(itemName);
            logger.debug("found binding {}", sappBindingConfigSwitchItem);
            if (sappBindingConfigSwitchItem.isPollerSuspender()) {
                if (pollingEnabled) {
                    // turning off polling
                    pollingEnabled = false;
                    // force updates of polling switches because polling is
                    updatePollingSwitchesState(provider);
                // off
                } else {
                    // turning on polling
                    provider.getSappUpdatePendingRequests().replaceAllPendingUpdateRequests(ALL_UPDATE_REQUEST_KEY);
                    pollingEnabled = true;
                }
            } else {
                SappAddressOnOffControl controlAddress = sappBindingConfigSwitchItem.getControl();
                if (!provider.getPnmasMap().containsKey(controlAddress.getPnmasId())) {
                    logger.error("bad pnmas id ({}) in binding ({}) ... skipping", controlAddress.getPnmasId(), sappBindingConfigSwitchItem);
                    return;
                }
                try {
                    if (command instanceof OnOffType) {
                        switch(controlAddress.getAddressType()) {
                            case VIRTUAL:
                                {
                                    // mask bits on previous value
                                    int previousValue = getVirtualValue(provider, controlAddress.getPnmasId(), controlAddress.getAddress(), controlAddress.getSubAddress(), false);
                                    int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(controlAddress.getSubAddress(), command.equals(OnOffType.ON) ? controlAddress.getOnValue() : controlAddress.getOffValue(), previousValue);
                                    // update pnmas
                                    SappPnmas pnmas = provider.getPnmasMap().get(controlAddress.getPnmasId());
                                    SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
                                    sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), controlAddress.getAddress(), newValue);
                                    break;
                                }
                            default:
                                logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), controlAddress.getAddressType());
                                break;
                        }
                    } else {
                        logger.error("command {} not applicable", command.getClass().getSimpleName());
                    }
                } catch (SappException e) {
                    logger.error("could not run sappcommand", e);
                }
            }
        } else if (item instanceof NumberItem) {
            SappBindingConfigNumberItem sappBindingConfigNumberItem = (SappBindingConfigNumberItem) provider.getBindingConfig(itemName);
            logger.debug("found binding {}", sappBindingConfigNumberItem);
            SappAddressDecimal address = sappBindingConfigNumberItem.getStatus();
            if (!provider.getPnmasMap().containsKey(address.getPnmasId())) {
                logger.error("bad pnmas id ({}) in binding ({}) ... skipping", address.getPnmasId(), sappBindingConfigNumberItem);
                return;
            }
            try {
                if (command instanceof DecimalType) {
                    switch(address.getAddressType()) {
                        case VIRTUAL:
                            {
                                // mask bits on previous value
                                int previousValue = getVirtualValue(provider, address.getPnmasId(), address.getAddress(), address.getSubAddress(), false);
                                int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(address.getSubAddress(), address.backScaledValue(((DecimalType) command).toBigDecimal()), previousValue);
                                // update pnmas
                                SappPnmas pnmas = provider.getPnmasMap().get(address.getPnmasId());
                                SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
                                sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), address.getAddress(), newValue);
                                break;
                            }
                        default:
                            logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), address.getAddressType());
                            break;
                    }
                } else {
                    logger.error("command {} not applicable", command.getClass().getSimpleName());
                }
            } catch (SappException e) {
                logger.error("could not run sappcommand", e);
            }
        } else if (item instanceof RollershutterItem) {
            SappBindingConfigRollershutterItem sappBindingConfigRollershutterItem = (SappBindingConfigRollershutterItem) provider.getBindingConfig(itemName);
            logger.debug("found binding {}", sappBindingConfigRollershutterItem);
            SappAddressRollershutterControl controlAddress = null;
            if (command instanceof UpDownType && ((UpDownType) command) == UpDownType.UP) {
                controlAddress = sappBindingConfigRollershutterItem.getUpControl();
            } else if (command instanceof UpDownType && ((UpDownType) command) == UpDownType.DOWN) {
                controlAddress = sappBindingConfigRollershutterItem.getDownControl();
            } else if (command instanceof StopMoveType && ((StopMoveType) command) == StopMoveType.STOP) {
                controlAddress = sappBindingConfigRollershutterItem.getStopControl();
            }
            if (controlAddress != null) {
                if (!provider.getPnmasMap().containsKey(controlAddress.getPnmasId())) {
                    logger.error("bad pnmas id ({}) in binding ({}) ... skipping", controlAddress.getPnmasId(), sappBindingConfigRollershutterItem);
                    return;
                }
                try {
                    switch(controlAddress.getAddressType()) {
                        case VIRTUAL:
                            {
                                // mask bits on previous value
                                int previousValue = getVirtualValue(provider, controlAddress.getPnmasId(), controlAddress.getAddress(), controlAddress.getSubAddress(), false);
                                int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(controlAddress.getSubAddress(), controlAddress.getActivateValue(), previousValue);
                                // update pnmas
                                SappPnmas pnmas = provider.getPnmasMap().get(controlAddress.getPnmasId());
                                SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
                                sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), controlAddress.getAddress(), newValue);
                                break;
                            }
                        default:
                            logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), controlAddress.getAddressType());
                            break;
                    }
                } catch (SappException e) {
                    logger.error("could not run sappcommand", e);
                }
            } else {
                logger.error("command {} not applicable", command.getClass().getSimpleName());
            }
        } else if (item instanceof DimmerItem) {
            SappBindingConfigDimmerItem sappBindingConfigDimmerItem = (SappBindingConfigDimmerItem) provider.getBindingConfig(itemName);
            logger.debug("found binding {}", sappBindingConfigDimmerItem);
            SappAddressDimmer address = sappBindingConfigDimmerItem.getStatus();
            if (!provider.getPnmasMap().containsKey(address.getPnmasId())) {
                logger.error("bad pnmas id ({}) in binding ({}) ... skipping", address.getPnmasId(), sappBindingConfigDimmerItem);
                return;
            }
            try {
                if (command instanceof OnOffType) {
                    switch(address.getAddressType()) {
                        case VIRTUAL:
                            {
                                // mask bits on previous value
                                int previousValue = getVirtualValue(provider, address.getPnmasId(), address.getAddress(), address.getSubAddress(), false);
                                int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(address.getSubAddress(), ((OnOffType) command) == OnOffType.ON ? address.getOriginalMaxScale() : address.getOriginalMinScale(), previousValue);
                                // update pnmas
                                SappPnmas pnmas = provider.getPnmasMap().get(address.getPnmasId());
                                SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
                                sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), address.getAddress(), newValue);
                                break;
                            }
                        default:
                            logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), address.getAddressType());
                            break;
                    }
                } else if (command instanceof IncreaseDecreaseType) {
                    switch(address.getAddressType()) {
                        case VIRTUAL:
                            {
                                // mask bits on previous value
                                int previousValue = getVirtualValue(provider, address.getPnmasId(), address.getAddress(), address.getSubAddress(), false);
                                int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(address.getSubAddress(), ((IncreaseDecreaseType) command) == IncreaseDecreaseType.INCREASE ? Math.min(previousValue + address.getIncrement(), address.getOriginalMaxScale()) : Math.max(previousValue - address.getIncrement(), address.getOriginalMinScale()), previousValue);
                                // update pnmas
                                SappPnmas pnmas = provider.getPnmasMap().get(address.getPnmasId());
                                SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
                                sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), address.getAddress(), newValue);
                                break;
                            }
                        default:
                            logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), address.getAddressType());
                            break;
                    }
                } else if (command instanceof PercentType) {
                    switch(address.getAddressType()) {
                        case VIRTUAL:
                            {
                                // mask bits on previous value
                                int previousValue = getVirtualValue(provider, address.getPnmasId(), address.getAddress(), address.getSubAddress(), false);
                                int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(address.getSubAddress(), address.backScaledValue(((PercentType) command).toBigDecimal()), previousValue);
                                // update pnmas
                                SappPnmas pnmas = provider.getPnmasMap().get(address.getPnmasId());
                                SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
                                sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), address.getAddress(), newValue);
                                break;
                            }
                        default:
                            logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), address.getAddressType());
                            break;
                    }
                } else {
                    logger.error("command {} not applicable", command.getClass().getSimpleName());
                }
            } catch (SappException e) {
                logger.error("could not run sappcommand", e);
            }
        } else {
            logger.error("unimplemented item type: {}", item.getClass().getSimpleName());
        }
    } catch (ItemNotFoundException e) {
        logger.error("Item {} not found", itemName);
    }
}
Also used : SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) SappBindingProvider(org.openhab.binding.sapp.SappBindingProvider) StopMoveType(org.openhab.core.library.types.StopMoveType) SappBindingConfigContactItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem) NumberItem(org.openhab.core.library.items.NumberItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) Item(org.openhab.core.items.Item) ContactItem(org.openhab.core.library.items.ContactItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SwitchItem(org.openhab.core.library.items.SwitchItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) SappPnmas(org.openhab.binding.sapp.internal.model.SappPnmas) SappAddressRollershutterControl(org.openhab.binding.sapp.internal.model.SappAddressRollershutterControl) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) SappCentralExecuter(org.openhab.binding.sapp.internal.executer.SappCentralExecuter) SappAddressOnOffControl(org.openhab.binding.sapp.internal.model.SappAddressOnOffControl) NumberItem(org.openhab.core.library.items.NumberItem) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) SappAddressDimmer(org.openhab.binding.sapp.internal.model.SappAddressDimmer) SappAddressDecimal(org.openhab.binding.sapp.internal.model.SappAddressDecimal) OnOffType(org.openhab.core.library.types.OnOffType) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) SappException(com.github.paolodenti.jsapp.core.command.base.SappException) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 9 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class ItemStateRequestProcessor method getState.

private StateTransformable getState(Item item) {
    StateTransformable state = null;
    if (item.getState() instanceof HSBType) {
        HSBType hsb = (HSBType) item.getState();
        state = new HSBData(hsb.getHue().longValue(), hsb.getHue().longValue(), hsb.getHue().longValue());
    } else if (item.getState() instanceof DateTimeType) {
        DateTimeType dt = (DateTimeType) item.getState();
        DateTimeDataType data = new DateTimeDataType(dt.toString());
        state = new DateTimeData(data);
    } else if (item.getState() instanceof DecimalType) {
    } else if (item.getState() instanceof OnOffType) {
    } else if (item.getState() instanceof OpenClosedType) {
    } else if (item.getState() instanceof PercentType) {
    } else if (item.getState() instanceof UpDownType) {
    }
    return state;
}
Also used : DateTimeType(org.openhab.core.library.types.DateTimeType) DateTimeDataType(org.creek.mailcontrol.model.types.DateTimeDataType) StateTransformable(org.creek.mailcontrol.model.data.StateTransformable) HSBData(org.creek.mailcontrol.model.data.HSBData) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DecimalType(org.openhab.core.library.types.DecimalType) DateTimeData(org.creek.mailcontrol.model.data.DateTimeData) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) HSBType(org.openhab.core.library.types.HSBType)

Example 10 with OnOffType

use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.

the class MaxCubeBinding method execute.

/**
     * {@inheritDoc}
     */
@Override
public synchronized void execute() {
    if (ip == null) {
        logger.debug("Update prior to completion of interface IP configuration");
        return;
    }
    try {
        String raw = null;
        if (maxRequestsPerConnection > 0 && requestCount >= maxRequestsPerConnection) {
            logger.debug("maxRequestsPerConnection reached, reconnecting.");
            socket.close();
            this.socketConnect();
        }
        if (socket == null) {
            this.socketConnect();
        } else {
            /*
                 * if the connection is already open (this happens in exclusive mode), just send a "l:\r\n" to get the
                 * latest live informations
                 * note that "L:\r\n" or "l:\n" would not work.
                 */
            logger.debug("Sending state request #" + this.requestCount + " to Maxcube");
            writer.write("l:" + '\r' + '\n');
            writer.flush();
            requestCount++;
        }
        boolean cont = true;
        while (cont) {
            raw = reader.readLine();
            if (raw == null) {
                cont = false;
                continue;
            }
            Message message = null;
            try {
                this.messageProcessor.addReceivedLine(raw);
                if (this.messageProcessor.isMessageAvailable()) {
                    message = this.messageProcessor.pull();
                } else {
                    continue;
                }
                message.debug(logger);
                if (message != null) {
                    message.debug(logger);
                    if (message.getType() == MessageType.M) {
                        M_Message msg = (M_Message) message;
                        for (DeviceInformation di : msg.devices) {
                            Configuration c = null;
                            for (Configuration conf : configurations) {
                                if (conf.getSerialNumber().equalsIgnoreCase(di.getSerialNumber())) {
                                    c = conf;
                                    break;
                                }
                            }
                            if (c != null) {
                                configurations.remove(c);
                            }
                            c = Configuration.create(di);
                            configurations.add(c);
                            c.setRoomId(di.getRoomId());
                        }
                    } else if (message.getType() == MessageType.C) {
                        Configuration c = null;
                        for (Configuration conf : configurations) {
                            if (conf.getSerialNumber().equalsIgnoreCase(((C_Message) message).getSerialNumber())) {
                                c = conf;
                                break;
                            }
                        }
                        if (c == null) {
                            configurations.add(Configuration.create(message));
                        } else {
                            c.setValues((C_Message) message);
                        }
                    } else if (message.getType() == MessageType.S) {
                        sMessageProcessing((S_Message) message);
                        cont = false;
                    } else if (message.getType() == MessageType.L) {
                        ((L_Message) message).updateDevices(devices, configurations);
                        logger.debug("{} devices found.", devices.size());
                        // the L message is the last one, while the reader
                        // would hang trying to read a new line and
                        // eventually the
                        // cube will fail to establish
                        // new connections for some time
                        cont = false;
                    }
                }
            } catch (IncorrectMultilineIndexException ex) {
                logger.info("Incorrect MAX!Cube multiline message detected. Stopping processing and continue with next Line.");
                this.messageProcessor.reset();
            } catch (NoMessageAvailableException ex) {
                logger.info("Could not process MAX!Cube message. Stopping processing and continue with next Line.");
                this.messageProcessor.reset();
            } catch (IncompleteMessageException ex) {
                logger.info("Error while parsing MAX!Cube multiline message. Stopping processing, and continue with next Line.");
                this.messageProcessor.reset();
            } catch (UnprocessableMessageException ex) {
                logger.info("Error while parsing MAX!Cube message. Stopping processing, and continue with next Line.");
                this.messageProcessor.reset();
            } catch (UnsupportedMessageTypeException ex) {
                logger.info("Unsupported MAX!Cube message detected. Ignoring and continue with next Line.");
                this.messageProcessor.reset();
            } catch (MessageIsWaitingException ex) {
                logger.info("There was an unhandled message waiting. Ignoring and continue with next Line.");
                this.messageProcessor.reset();
            } catch (Exception e) {
                logger.info("Failed to process message received by MAX! protocol.");
                logger.debug(Utils.getStackTrace(e));
                this.messageProcessor.reset();
            }
        }
        if (!exclusive) {
            socketClose();
        }
        for (MaxCubeBindingProvider provider : providers) {
            for (String itemName : provider.getItemNames()) {
                String serialNumber = provider.getSerialNumber(itemName);
                Device device = findDevice(serialNumber, devices);
                if (device == null) {
                    logger.info("Cannot find MAX!cube device with serial number '{}'", serialNumber);
                    logAvailableMaxDevices();
                    continue;
                }
                // all devices have a battery state, so this is type-independent
                if (provider.getBindingType(itemName) == BindingType.BATTERY) {
                    if (device.battery().isChargeUpdated()) {
                        eventPublisher.postUpdate(itemName, device.battery().getCharge());
                    }
                } else if (provider.getBindingType(itemName) == BindingType.CONNECTION_ERROR) {
                    if (device.isErrorUpdated()) {
                        OnOffType connectionError = device.isError() ? OnOffType.ON : OnOffType.OFF;
                        eventPublisher.postUpdate(itemName, connectionError);
                    }
                } else {
                    switch(device.getType()) {
                        case HeatingThermostatPlus:
                        case HeatingThermostat:
                            if (provider.getBindingType(itemName) == BindingType.VALVE && ((HeatingThermostat) device).isValvePositionUpdated()) {
                                eventPublisher.postUpdate(itemName, ((HeatingThermostat) device).getValvePosition());
                                break;
                            }
                        // omitted break, fall through
                        case // and also HeatingThermostat
                        WallMountedThermostat:
                            if (provider.getBindingType(itemName) == BindingType.MODE && ((HeatingThermostat) device).isModeUpdated()) {
                                eventPublisher.postUpdate(itemName, ((HeatingThermostat) device).getModeString());
                            } else if (provider.getBindingType(itemName) == BindingType.ACTUAL && ((HeatingThermostat) device).isTemperatureActualUpdated()) {
                                eventPublisher.postUpdate(itemName, ((HeatingThermostat) device).getTemperatureActual());
                            } else if (((HeatingThermostat) device).isTemperatureSetpointUpdated() && provider.getBindingType(itemName) == null) {
                                eventPublisher.postUpdate(itemName, ((HeatingThermostat) device).getTemperatureSetpoint());
                            }
                            break;
                        case ShutterContact:
                            if (((ShutterContact) device).isShutterStateUpdated()) {
                                eventPublisher.postUpdate(itemName, ((ShutterContact) device).getShutterState());
                            }
                            break;
                        default:
                    }
                }
            }
        }
    } catch (UnknownHostException e) {
        logger.info("Host error occurred while connecting to MAX! Cube lan gateway '{}': {}", ip, e.getMessage());
        socketClose();
    } catch (IOException e) {
        logger.info("IO error occurred while connecting to MAX! Cube lan gateway '{}': {}", ip, e.getMessage());
        // reconnect on next execution
        socketClose();
    } catch (Exception e) {
        logger.info("Error occurred while connecting to MAX! Cube lan gateway '{}': {}", ip, e.getMessage());
        logger.info(Utils.getStackTrace(e));
        // reconnect on next execution
        socketClose();
    }
}
Also used : MaxCubeBindingProvider(org.openhab.binding.maxcube.MaxCubeBindingProvider) ShutterContact(org.openhab.binding.maxcube.internal.message.ShutterContact) S_Message(org.openhab.binding.maxcube.internal.message.S_Message) M_Message(org.openhab.binding.maxcube.internal.message.M_Message) C_Message(org.openhab.binding.maxcube.internal.message.C_Message) L_Message(org.openhab.binding.maxcube.internal.message.L_Message) Message(org.openhab.binding.maxcube.internal.message.Message) Configuration(org.openhab.binding.maxcube.internal.message.Configuration) UnknownHostException(java.net.UnknownHostException) Device(org.openhab.binding.maxcube.internal.message.Device) HeatingThermostat(org.openhab.binding.maxcube.internal.message.HeatingThermostat) IncompleteMessageException(org.openhab.binding.maxcube.internal.exceptions.IncompleteMessageException) IOException(java.io.IOException) NoMessageAvailableException(org.openhab.binding.maxcube.internal.exceptions.NoMessageAvailableException) UnprocessableMessageException(org.openhab.binding.maxcube.internal.exceptions.UnprocessableMessageException) IncompleteMessageException(org.openhab.binding.maxcube.internal.exceptions.IncompleteMessageException) UnprocessableMessageException(org.openhab.binding.maxcube.internal.exceptions.UnprocessableMessageException) UnsupportedMessageTypeException(org.openhab.binding.maxcube.internal.exceptions.UnsupportedMessageTypeException) ConfigurationException(org.osgi.service.cm.ConfigurationException) MessageIsWaitingException(org.openhab.binding.maxcube.internal.exceptions.MessageIsWaitingException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NoMessageAvailableException(org.openhab.binding.maxcube.internal.exceptions.NoMessageAvailableException) IncorrectMultilineIndexException(org.openhab.binding.maxcube.internal.exceptions.IncorrectMultilineIndexException) OnOffType(org.openhab.core.library.types.OnOffType) C_Message(org.openhab.binding.maxcube.internal.message.C_Message) IncorrectMultilineIndexException(org.openhab.binding.maxcube.internal.exceptions.IncorrectMultilineIndexException) M_Message(org.openhab.binding.maxcube.internal.message.M_Message) MessageIsWaitingException(org.openhab.binding.maxcube.internal.exceptions.MessageIsWaitingException) DeviceInformation(org.openhab.binding.maxcube.internal.message.DeviceInformation) UnsupportedMessageTypeException(org.openhab.binding.maxcube.internal.exceptions.UnsupportedMessageTypeException)

Aggregations

OnOffType (org.openhab.core.library.types.OnOffType)50 DecimalType (org.openhab.core.library.types.DecimalType)22 PercentType (org.openhab.core.library.types.PercentType)15 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)12 OpenClosedType (org.openhab.core.library.types.OpenClosedType)11 StringType (org.openhab.core.library.types.StringType)11 UpDownType (org.openhab.core.library.types.UpDownType)9 IOException (java.io.IOException)8 State (org.openhab.core.types.State)7 StopMoveType (org.openhab.core.library.types.StopMoveType)6 DateTimeType (org.openhab.core.library.types.DateTimeType)5 HSBType (org.openhab.core.library.types.HSBType)5 UnknownHostException (java.net.UnknownHostException)4 ConfigurationException (org.osgi.service.cm.ConfigurationException)4 RFXComException (org.openhab.binding.rfxcom.internal.RFXComException)3 Item (org.openhab.core.items.Item)3 SwitchItem (org.openhab.core.library.items.SwitchItem)3 Color (java.awt.Color)2 DatagramPacket (java.net.DatagramPacket)2 SocketTimeoutException (java.net.SocketTimeoutException)2