openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

Handler factory: immediate = true necessary ? #5852

Closed lolodomo closed 5 years ago

lolodomo commented 5 years ago

I would like to know if it is expected or not to include "immediate = true" when declaring the handler factory of a binding. Most of the bindings are without this but few of them adds "immediate = true" like for example: Daikin: https://github.com/openhab/openhab2-addons/blob/6c93abcf1b5707db455e47144f42569735d33168/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinHandlerFactory.java#L31 Loxone: https://github.com/openhab/openhab2-addons/blob/d45ee470d57e39cf5daed07f01a6dd151ed04cce/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxHandlerFactory.java#L31

This "immediate = true" seems to be added more generally on all discovery services. Is it expected too ?

cweitkamp commented 5 years ago

if it is expected or not to include "immediate = true" when declaring the handler factory

AFAIK No, it is not. We tried to align the usage more than once: #3672, #4075 and https://github.com/eclipse/smarthome/pull/5511 (see also https://github.com/eclipse/smarthome/issues/5163).

discovery services. Is it expected too ?

Depends. For MDNS or UPNP or similar it is expected, for stand-alone discovery like Astro too, for discovery services created inside a HandlerFactory like Hue not.

@openhab/2-x-add-ons-maintainers Please correct me if I am wrong.

lolodomo commented 5 years ago

For thing handler factory, we have exactly 15 bindings with "immediate = true" in this repo. Z-Wave binding is also concerned.

https://github.com/openhab/openhab2-addons/blob/6c93abcf1b5707db455e47144f42569735d33168/bundles/org.openhab.binding.daikin/src/main/java/org/openhab/binding/daikin/internal/DaikinHandlerFactory.java#L31 https://github.com/openhab/openhab2-addons/blob/d32618d3c8f728841c35b5c4d2cc66966d127e5f/bundles/org.openhab.binding.digiplex/src/main/java/org/openhab/binding/digiplex/internal/DigiplexHandlerFactory.java#L36 https://github.com/openhab/openhab2-addons/blob/8455838fb6476d71d51a46e1407328e59a9812ee/bundles/org.openhab.binding.miio/src/main/java/org/openhab/binding/miio/internal/MiIoHandlerFactory.java#L34 https://github.com/openhab/openhab2-addons/blob/e97d52598a748c576051739b05c48fd147d5b72c/bundles/org.openhab.binding.meteoblue/src/main/java/org/openhab/binding/meteoblue/internal/MeteoBlueHandlerFactory.java#L37 https://github.com/openhab/openhab2-addons/blob/e796b7dc5ed06d1089afd9f08bf9a939276b6308/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/EleroTransmitterStickHandlerFactory.java#L43 https://github.com/openhab/openhab2-addons/blob/b5b4e88118f2583908f773b94327ca16f059c371/bundles/org.openhab.binding.homematic/src/main/java/org/openhab/binding/homematic/internal/handler/HomematicThingHandlerFactory.java#L35 https://github.com/openhab/openhab2-addons/blob/ea05ffc0a48245b1b531e8d464c8959a9d2b98a7/bundles/org.openhab.binding.bosesoundtouch/src/main/java/org/openhab/binding/bosesoundtouch/internal/BoseSoundTouchHandlerFactory.java#L34 https://github.com/openhab/openhab2-addons/blob/25e01d2e2e0696259e5bf5ecbeb0d627eb4552cc/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/UniFiThingHandlerFactory.java#L36 https://github.com/openhab/openhab2-addons/blob/master/bundles/org.openhab.binding.loxone/src/main/java/org/openhab/binding/loxone/internal/LxHandlerFactory.java#L31 https://github.com/openhab/openhab2-addons/blob/9502f2b1cca0249c806c34049bb9df032ea11ffe/bundles/org.openhab.binding.zoneminder/src/main/java/org/openhab/binding/zoneminder/internal/ZoneMinderHandlerFactory.java#L39 https://github.com/openhab/openhab2-addons/blob/5a2b3a4d5d41a28dfa7daa5aa3735c8bcd9d688a/bundles/org.openhab.binding.bluetooth.bluegiga/src/main/java/org/openhab/binding/bluetooth/bluegiga/internal/factory/BlueGigaHandlerFactory.java#L45 https://github.com/openhab/openhab2-addons/blob/0d6a7752aab1f20154b98485fddb203cf51bd3f3/bundles/org.openhab.binding.km200/src/main/java/org/openhab/binding/km200/internal/KM200HandlerFactory.java#L50 https://github.com/openhab/openhab2-addons/blob/9f78dc08eba3782ce34d7f2abd1313213e66f6d1/bundles/org.openhab.binding.harmonyhub/src/main/java/org/openhab/binding/harmonyhub/internal/HarmonyHubHandlerFactory.java#L57 https://github.com/openhab/openhab2-addons/blob/0857906b5a578ed641bf7b0c47e7e49a89d692a2/bundles/org.openhab.binding.spotify/src/main/java/org/openhab/binding/spotify/internal/SpotifyHandlerFactory.java#L48 https://github.com/openhab/openhab2-addons/blob/ca61100899c72c1f9da024890fff17b1e1c5a948/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/NetatmoHandlerFactory.java#L61

lolodomo commented 5 years ago

Please also note that the following bindings are not defining a configurationPid: https://github.com/openhab/openhab2-addons/blob/e97d52598a748c576051739b05c48fd147d5b72c/bundles/org.openhab.binding.meteoblue/src/main/java/org/openhab/binding/meteoblue/internal/MeteoBlueHandlerFactory.java#L37 https://github.com/openhab/openhab2-addons/blob/ddb4a5e61ba23afa75964d12e0763de435090a7f/bundles/org.openhab.binding.snmp/src/main/java/org/openhab/binding/snmp/internal/SnmpHandlerFactory.java#L38 https://github.com/openhab/openhab2-addons/blob/e796b7dc5ed06d1089afd9f08bf9a939276b6308/bundles/org.openhab.binding.elerotransmitterstick/src/main/java/org/openhab/binding/elerotransmitterstick/internal/EleroTransmitterStickHandlerFactory.java#L43 https://github.com/openhab/openhab2-addons/blob/9dbae99479eea9d9552befde5fae13b7fcfb88e1/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/internal/MqttThingHandlerFactory.java#L43 https://github.com/openhab/openhab2-addons/blob/9dbae99479eea9d9552befde5fae13b7fcfb88e1/bundles/org.openhab.binding.mqtt.homeassistant/src/main/java/org/openhab/binding/mqtt/homeassistant/generic/internal/MqttThingHandlerFactory.java#L44 https://github.com/openhab/openhab2-addons/blob/9dbae99479eea9d9552befde5fae13b7fcfb88e1/bundles/org.openhab.binding.mqtt.homie/src/main/java/org/openhab/binding/mqtt/homie/generic/internal/MqttThingHandlerFactory.java#L45

lolodomo commented 5 years ago

For the netatmo binding, the service with two classes looks unusual:

@Component(service = { ThingHandlerFactory.class,
        NetatmoHandlerFactory.class }, immediate = true, configurationPid = "binding.netatmo")

I assume it should be changed to:

@Component(service = ThingHandlerFactory.class, configurationPid = "binding.netatmo")
Hilbrand commented 5 years ago

Related to the netatmo binding. I think it's a left over of a refactoring by someone named @lolodomo :smile: See https://github.com/openhab/openhab2-addons/pull/3253 The NetatmoHandlerFactory was injected before the change, and thus the service was needed. After the refactoring it wasn't used anymore, so it's not needed anymore to have it in the service

lolodomo commented 5 years ago

Ok, I will fix the netatmo binding ;)