Search in sources :

Example 1 with FHTBindingConfig

use of org.openhab.binding.fht.FHTBindingConfig in project openhab1-addons by openhab.

the class FHTBinding method receivedFHTState.

private void receivedFHTState(String device, String state) {
    logger.debug("Received state " + state + " for FHT device " + device);
    int stateValue = Integer.parseInt(state, 16);
    FHTBindingConfig config = getConfig(device, Datapoint.BATTERY);
    OnOffType batteryAlarm = null;
    if (stateValue % 2 == 0) {
        batteryAlarm = OnOffType.OFF;
    } else {
        stateValue = stateValue - 1;
        batteryAlarm = OnOffType.ON;
    }
    if (config != null) {
        logger.debug("Updating item " + config.getItem().getName() + " with battery state");
        eventPublisher.postUpdate(config.getItem().getName(), batteryAlarm);
    }
    OpenClosedType windowState = null;
    if (stateValue == 0) {
        windowState = OpenClosedType.CLOSED;
    } else {
        windowState = OpenClosedType.OPEN;
    }
    config = getConfig(device, Datapoint.WINDOW);
    if (config != null) {
        logger.debug("Updating item " + config.getItem().getName() + " with window state");
        eventPublisher.postUpdate(config.getItem().getName(), windowState);
    } else {
        logger.debug("Received FHT state from unknown device " + device);
    }
}
Also used : FHTBindingConfig(org.openhab.binding.fht.FHTBindingConfig) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) Datapoint(org.openhab.binding.fht.FHTBindingConfig.Datapoint)

Example 2 with FHTBindingConfig

use of org.openhab.binding.fht.FHTBindingConfig in project openhab1-addons by openhab.

the class FHTBinding method receivedNewValveOpening.

private void receivedNewValveOpening(String device, int actuatorNumber, double valve) {
    String fullAddress = device + "0" + actuatorNumber;
    FHTBindingConfig config = getConfig(fullAddress, Datapoint.VALVE);
    if (config != null) {
        logger.debug("Updating item " + config.getItem().getName() + " with new valve opening");
        DecimalType state = new DecimalType(valve);
        eventPublisher.postUpdate(config.getItem().getName(), state);
    } else {
        logger.debug("Received valve opening of unknown actuator with address " + fullAddress);
    }
}
Also used : FHTBindingConfig(org.openhab.binding.fht.FHTBindingConfig) DecimalType(org.openhab.core.library.types.DecimalType)

Example 3 with FHTBindingConfig

use of org.openhab.binding.fht.FHTBindingConfig in project openhab1-addons by openhab.

the class FHTBinding method receivedNewFHT8bState.

private void receivedNewFHT8bState(String device, FHTState state) {
    FHTBindingConfig config = null;
    if (state == FHTState.BATTERY_LOW) {
        config = getConfig(device, Datapoint.BATTERY);
    } else {
        config = getConfig(device, Datapoint.WINDOW);
    }
    if (config != null) {
        logger.debug("Updating item " + config.getItem().getName() + " with new FHT state " + state.toString());
        State newState = null;
        if (state == FHTState.BATTERY_LOW) {
            // Battery alarm goes on
            newState = OnOffType.ON;
        } else if (state == FHTState.WINDOW_OPEN) {
            newState = OpenClosedType.OPEN;
        } else if (state == FHTState.WINDOW_CLOSED) {
            newState = OpenClosedType.CLOSED;
        }
        if (newState != null) {
            eventPublisher.postUpdate(config.getItem().getName(), newState);
        } else {
            logger.warn("Unknown FHT8b state, which is unmapped to openHAB state " + state.toString());
        }
    } else {
        logger.debug("Received FHT8b state for unknown device with address " + device);
    }
}
Also used : FHTBindingConfig(org.openhab.binding.fht.FHTBindingConfig) State(org.openhab.core.types.State)

Example 4 with FHTBindingConfig

use of org.openhab.binding.fht.FHTBindingConfig in project openhab1-addons by openhab.

the class FHTGenericBindingProvider method processBindingConfiguration.

/**
     * Binding in the type of
     * {fht="housecode=<housecode>;address=<optional>;datapoint=<optional>"}
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    String[] configParts = bindingConfig.split(";");
    String housecode = null;
    String address = null;
    Datapoint datapoint = null;
    for (String s : configParts) {
        String[] entryParts = s.split("=");
        if ("housecode".equals(entryParts[0])) {
            housecode = entryParts[1];
        } else if ("address".equals(entryParts[0])) {
            address = entryParts[1];
        } else if ("datapoint".equals(entryParts[0])) {
            datapoint = Datapoint.valueOf(entryParts[1]);
        }
    }
    if (housecode == null) {
        throw new BindingConfigParseException("housecode mustn't be null");
    }
    if (datapoint == null) {
        throw new BindingConfigParseException("datapoint must be one of MEASURED_TEMP, DESIRED_TEMP, BATTERY, WINDOW or VALVE");
    }
    if ((datapoint == Datapoint.WINDOW || datapoint == Datapoint.VALVE) && address == null) {
        throw new BindingConfigParseException("Address of window contact needed");
    }
    FHTBindingConfig config = new FHTBindingConfig(item, housecode, address, datapoint);
    addBindingConfig(item, config);
}
Also used : Datapoint(org.openhab.binding.fht.FHTBindingConfig.Datapoint) FHTBindingConfig(org.openhab.binding.fht.FHTBindingConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 5 with FHTBindingConfig

use of org.openhab.binding.fht.FHTBindingConfig in project openhab1-addons by openhab.

the class FHTBinding method receivedNewMeasuredTemperature.

private void receivedNewMeasuredTemperature(String deviceAddress, double temperature) {
    FHTBindingConfig config = getConfig(deviceAddress, Datapoint.MEASURED_TEMP);
    if (config != null) {
        logger.debug("Updating item " + config.getItem().getName() + " with new measured temperature " + temperature);
        DecimalType state = new DecimalType(temperature);
        eventPublisher.postUpdate(config.getItem().getName(), state);
    } else {
        logger.debug("Received new measured temp for unknown device with address " + deviceAddress);
    }
}
Also used : FHTBindingConfig(org.openhab.binding.fht.FHTBindingConfig) DecimalType(org.openhab.core.library.types.DecimalType)

Aggregations

FHTBindingConfig (org.openhab.binding.fht.FHTBindingConfig)7 DecimalType (org.openhab.core.library.types.DecimalType)4 Datapoint (org.openhab.binding.fht.FHTBindingConfig.Datapoint)2 FHTBindingProvider (org.openhab.binding.fht.FHTBindingProvider)1 OnOffType (org.openhab.core.library.types.OnOffType)1 OpenClosedType (org.openhab.core.library.types.OpenClosedType)1 State (org.openhab.core.types.State)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1