Search in sources :

Example 1 with WagoBindingConfig

use of org.openhab.binding.wago.internal.WagoGenericBindingProvider.WagoBindingConfig in project openhab1-addons by openhab.

the class WagoBinding method updateItem.

public void updateItem(String itemName, String couplerName, int module, boolean[] states) {
    for (WagoBindingProvider provider : providers) {
        if (provider.providesBindingFor(itemName)) {
            WagoBindingConfig conf = provider.getConfig(itemName);
            if (conf.couplerName.equals(couplerName) && conf.module == module) {
                State currentState = conf.getItemState();
                State newState = conf.translateBoolean2State(states[conf.channel]);
                if (!newState.equals(currentState)) {
                    eventPublisher.postUpdate(itemName, newState);
                }
            }
        }
    }
}
Also used : WagoBindingConfig(org.openhab.binding.wago.internal.WagoGenericBindingProvider.WagoBindingConfig) WagoBindingProvider(org.openhab.binding.wago.WagoBindingProvider) State(org.openhab.core.types.State)

Example 2 with WagoBindingConfig

use of org.openhab.binding.wago.internal.WagoGenericBindingProvider.WagoBindingConfig in project openhab1-addons by openhab.

the class WagoBinding method updateItemPWM.

public void updateItemPWM(String itemName, String couplerName, int module, int[] values) {
    for (WagoBindingProvider provider : providers) {
        if (provider.providesBindingFor(itemName)) {
            WagoBindingConfig conf = provider.getConfig(itemName);
            if (conf.couplerName.equals(couplerName) && conf.module == module) {
                State currentState = conf.getItemState();
                State newState;
                if (conf.getItem() instanceof DimmerItem) {
                    newState = new PercentType((int) ((float) values[conf.channel] / 1023 * 100));
                } else if (conf.getItem() instanceof SwitchItem) {
                    if (values[conf.channel] == 0) {
                        newState = OnOffType.OFF;
                    } else {
                        newState = OnOffType.ON;
                    }
                } else {
                    logger.debug("Unsupported Itemtype");
                    return;
                }
                if (!newState.equals(currentState)) {
                    eventPublisher.postUpdate(itemName, newState);
                }
            }
        }
    }
}
Also used : WagoBindingConfig(org.openhab.binding.wago.internal.WagoGenericBindingProvider.WagoBindingConfig) WagoBindingProvider(org.openhab.binding.wago.WagoBindingProvider) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) PercentType(org.openhab.core.library.types.PercentType) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 3 with WagoBindingConfig

use of org.openhab.binding.wago.internal.WagoGenericBindingProvider.WagoBindingConfig in project openhab1-addons by openhab.

the class WagoBinding method internalReceiveCommand.

/**
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    for (WagoBindingProvider provider : providers) {
        if (provider.providesBindingFor(itemName)) {
            WagoBindingConfig conf = provider.getConfig(itemName);
            FBCoupler coupler = getCoupler(conf.couplerName);
            coupler.executeCommand(command, conf);
        }
    }
}
Also used : WagoBindingConfig(org.openhab.binding.wago.internal.WagoGenericBindingProvider.WagoBindingConfig) WagoBindingProvider(org.openhab.binding.wago.WagoBindingProvider)

Aggregations

WagoBindingProvider (org.openhab.binding.wago.WagoBindingProvider)3 WagoBindingConfig (org.openhab.binding.wago.internal.WagoGenericBindingProvider.WagoBindingConfig)3 State (org.openhab.core.types.State)2 DimmerItem (org.openhab.core.library.items.DimmerItem)1 SwitchItem (org.openhab.core.library.items.SwitchItem)1 PercentType (org.openhab.core.library.types.PercentType)1