g1velo / SNAVXbee2

0 stars 0 forks source link

Event to update items #9

Closed kirantpatil closed 7 years ago

kirantpatil commented 7 years ago

Hi @g1velo,

Why there is no usage of Events to update items ?

Thanks.

kirantpatil commented 7 years ago

Below is code from openhab-1 addon.

private void tryUpdate(final String key, final String value, final String remoteAddress) {
        logger.debug("trying to set {} of {} to {}", key, remoteAddress, value);
        boolean updated = false;
        for (final DiyOnXBeeBindingProvider provider : providers) {

            for (final String itemName : provider.getItemNames()) {
                final String id = provider.getId(itemName);
                final String remote = provider.getRemote(itemName);

                if (key.equals(id) && remote.equals(remoteAddress)) {
                    final List<Class<? extends State>> availableTypes = provider.getAvailableItemTypes(itemName);
                    final State state = parseState(value, availableTypes, provider, itemName);
                    if (state != null) {
                        updated = true;
                        eventPublisher.postUpdate(itemName, state);
                    }
                }
            }
}
g1velo commented 7 years ago

Hi, I took as an example the YahooWeather binding where : updateState(channelUID, getTemperature());

Is used. I have seen no mention of eventPublisher in OH2 binding, but I am not expert enough to tell if we should use it.

In my case the updateState call works fine an items are updated. You can try to run : smarthome:status ItemName

TO check is it is updated.

kirantpatil commented 7 years ago

Yes, events are getting generated. Somehow I overlooked it. Thanks.