Search in sources :

Example 1 with AbstractOneWireDevicePropertyBindingConfig

use of org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig in project openhab1-addons by openhab.

the class OneWireBinding method bindingChanged.

/*
     * (non-Javadoc)
     *
     * @see
     * org.openhab.core.binding.AbstractBinding#bindingChanged(org.openhab.core
     * .binding.BindingProvider, java.lang.String)
     */
@Override
public void bindingChanged(BindingProvider pvProvider, String pvItemName) {
    logger.debug("bindingChanged() for item {} msg received.", pvItemName);
    if (pvProvider instanceof OneWireBindingProvider) {
        ivCacheItemStates.remove(pvItemName);
        OneWireBindingProvider lvBindingProvider = (OneWireBindingProvider) pvProvider;
        OneWireBindingConfig lvBindingConfig = lvBindingProvider.getBindingConfig(pvItemName);
        // AbstractOneWireControlBindingConfigs
        if (lvBindingConfig != null && lvBindingConfig instanceof AbstractOneWireDevicePropertyBindingConfig) {
            AbstractOneWireDevicePropertyBindingConfig lvDeviceBindingConfig = (AbstractOneWireDevicePropertyBindingConfig) lvBindingConfig;
            logger.debug("Initializing read of item {}.", pvItemName);
            int lvAutoRefreshTimeInSecs = lvDeviceBindingConfig.getAutoRefreshInSecs();
            if (lvAutoRefreshTimeInSecs > -1) {
                ivOneWireReaderScheduler.updateOnce(pvItemName);
            }
            if (lvAutoRefreshTimeInSecs > 0) {
                if (!ivOneWireReaderScheduler.scheduleUpdate(pvItemName, lvAutoRefreshTimeInSecs)) {
                    logger.warn("Couldn't add to OneWireUpdate scheduler", lvDeviceBindingConfig);
                }
            } else {
                logger.debug("Didn't add to OneWireUpdate scheduler, because refresh is <= 0: {}", lvDeviceBindingConfig);
            }
        }
    }
}
Also used : AbstractOneWireDevicePropertyBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig) OneWireBindingProvider(org.openhab.binding.onewire.OneWireBindingProvider)

Example 2 with AbstractOneWireDevicePropertyBindingConfig

use of org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig in project openhab1-addons by openhab.

the class OneWireBinding method scheduleAllBindings.

/**
     * schedule All Bindings to get updated
     *
     * @param pvProvider
     */
private void scheduleAllBindings(BindingProvider pvProvider) {
    if (OneWireConnection.isConnectionEstablished()) {
        logger.debug("scheduleAllBindings");
        if (pvProvider instanceof OneWireBindingProvider) {
            OneWireBindingProvider lvBindingProvider = (OneWireBindingProvider) pvProvider;
            ivOneWireReaderScheduler.clear();
            ivCacheItemStates.clear();
            Map<String, BindingConfig> lvBindigConfigs = lvBindingProvider.getBindingConfigs();
            for (String lvItemName : lvBindigConfigs.keySet()) {
                logger.debug("scheduleAllBindings, now item {}.", lvItemName);
                OneWireBindingConfig lvOneWireBindingConfig = (OneWireBindingConfig) lvBindigConfigs.get(lvItemName);
                if (lvOneWireBindingConfig instanceof AbstractOneWireDevicePropertyBindingConfig) {
                    logger.debug("Initializing read of item {}.", lvItemName);
                    AbstractOneWireDevicePropertyBindingConfig lvDevicePropertyBindingConfig = (AbstractOneWireDevicePropertyBindingConfig) lvOneWireBindingConfig;
                    if (lvDevicePropertyBindingConfig != null) {
                        int lvAutoRefreshTimeInSecs = lvDevicePropertyBindingConfig.getAutoRefreshInSecs();
                        if (lvAutoRefreshTimeInSecs > -1) {
                            ivOneWireReaderScheduler.updateOnce(lvItemName);
                        }
                        if (lvAutoRefreshTimeInSecs > 0) {
                            if (!ivOneWireReaderScheduler.scheduleUpdate(lvItemName, lvAutoRefreshTimeInSecs)) {
                                logger.warn("Couldn't add to OneWireUpdate scheduler", lvDevicePropertyBindingConfig);
                            }
                        }
                    }
                } else {
                    logger.debug("Didn't schedule item {} because it is not a DevicePropertyBinding.", lvItemName);
                }
            }
        }
    }
}
Also used : AbstractOneWireDevicePropertyBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig) OneWireDevicePropertyExecutableBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyExecutableBindingConfig) AbstractOneWireDevicePropertyWritableBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyWritableBindingConfig) BindingConfig(org.openhab.core.binding.BindingConfig) AbstractOneWireControlBindingConfig(org.openhab.binding.onewire.internal.control.AbstractOneWireControlBindingConfig) AbstractOneWireDevicePropertyBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig) OneWireBindingProvider(org.openhab.binding.onewire.OneWireBindingProvider)

Example 3 with AbstractOneWireDevicePropertyBindingConfig

use of org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig in project openhab1-addons by openhab.

the class OneWireBinding method updateItemFromOneWire.

/**
     * Update an item with value from 1-wire device property
     *
     * @param pvItemName
     */
public void updateItemFromOneWire(String pvItemName) {
    if (OneWireConnection.getConnection() != null) {
        AbstractOneWireDevicePropertyBindingConfig pvBindingConfig = (AbstractOneWireDevicePropertyBindingConfig) getBindingConfig(pvItemName);
        if (pvBindingConfig == null) {
            logger.error("no bindingConfig found for itemName={} cannot update! It will be removed from scheduler", pvItemName);
            ivOneWireReaderScheduler.removeItem(pvItemName);
            return;
        }
        String lvReadValue = OneWireConnection.readFromOneWire(pvBindingConfig);
        Item lvItem = getItem(pvItemName);
        if (lvReadValue != null) {
            Type lvNewType = pvBindingConfig.convertReadValueToType(lvReadValue);
            if (lvItem != null) {
                postUpdate(lvItem, lvNewType);
            } else {
                logger.error("There is no Item for ItemName={}", pvItemName);
            }
        } else {
            String lvLogText = "Set Item for itemName=" + pvItemName + " to Undefined, because the readvalue is null";
            if (pvBindingConfig.isIgnoreReadErrors()) {
                logger.debug(lvLogText);
            } else {
                logger.error(lvLogText);
            }
            postUpdate(lvItem, UnDefType.UNDEF);
        }
    }
}
Also used : Item(org.openhab.core.items.Item) Type(org.openhab.core.types.Type) UnDefType(org.openhab.core.types.UnDefType) AbstractOneWireDevicePropertyBindingConfig(org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig)

Aggregations

AbstractOneWireDevicePropertyBindingConfig (org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyBindingConfig)3 OneWireBindingProvider (org.openhab.binding.onewire.OneWireBindingProvider)2 AbstractOneWireControlBindingConfig (org.openhab.binding.onewire.internal.control.AbstractOneWireControlBindingConfig)1 AbstractOneWireDevicePropertyWritableBindingConfig (org.openhab.binding.onewire.internal.deviceproperties.AbstractOneWireDevicePropertyWritableBindingConfig)1 OneWireDevicePropertyExecutableBindingConfig (org.openhab.binding.onewire.internal.deviceproperties.OneWireDevicePropertyExecutableBindingConfig)1 BindingConfig (org.openhab.core.binding.BindingConfig)1 Item (org.openhab.core.items.Item)1 Type (org.openhab.core.types.Type)1 UnDefType (org.openhab.core.types.UnDefType)1