openhab / openhab-addons

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

[shelly] Improve reliability in API determination #17013

Closed jlaur closed 1 week ago

jlaur commented 1 week ago

See https://github.com/openhab/openhab-addons/pull/17009#discussion_r1667631650

Suggested approach for replacing:

https://github.com/openhab/openhab-addons/blob/ab385ed2f35612cc447dbe992896d6c0e0c487fb/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/handler/ShellyBaseHandler.java#L156-L162

to remove dependency towards property deviceGeneration:

blu = ShellyDeviceProfile.isBluSeries(thingType);
gen2 = ShellyDeviceProfile.isGeneration2(thingType);

if (blu) {
    this.api = new ShellyBluApi(thingName, thingTable, this);
} else if (gen2) {
    this.api = new Shelly2ApiRpc(thingName, thingTable, this);
} else {
    this.api = new Shelly1HttpApi(thingName, this);
}

This logic determines API revision from thing type id:

https://github.com/openhab/openhab-addons/blob/ab385ed2f35612cc447dbe992896d6c0e0c487fb/bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api/ShellyDeviceProfile.java#L406-L413

This will result in the following API determination based on thing type ids (with documented generation):

Thing Type ID Label Result Documentation Comment
shellyblubutton Shelly BLU Button blu Shelly BLU
shellybludw Shelly BLU Door/Window blu Shelly BLU
shellyblumotion Shelly BLU Motion blu Shelly BLU
shellybluht Shelly BLU H&T blu Shelly BLU
shellyblugw Shelly BLU Gateway gen1 Not documented
shellybulb Shelly Bulb gen1 Shelly Bulb
shellybulbduo Shelly Duo gen1 Generation 1
shellycolorbulb Shelly Color Bulb gen1 Generation 1
shellyvintage Shelly Vintage gen1 Generation 1
shellyrgbw2-color Shelly RGBW2 Color Mode gen1 Generation 1
shellyrgbw2-white Shelly RGBW2 White Mode gen1 Generation 1
shelly1 Shelly 1 gen1 Generation 1
shelly1l Shelly 1L gen1 Generation 1
shelly1pm Shelly 1PM gen1 Generation 1
shellyem Shelly EM gen1 Generation 1
shellyem3 Shelly EM3 gen1 Generation 1
shelly2-relay Shelly 2 Relay gen1 Generation 1
shelly2-roller Shelly 2 Roller gen1 Generation 1
shelly25-relay Shelly 2.5 Relay gen1 Generation 1
shelly25-roller Shelly 2.5 Roller gen1 Generation 1
shelly4pro Shelly 4 Pro Relay gen1 Generation 1
shellyplug Shelly Plug gen1 Generation 1
shellyplugs Shelly Plug-S gen1 Generation 1
shellyplugu1 Shelly Plug US gen1 Not documented
shellyuni Shelly UNI gen1 Generation 1
shellydimmer Shelly Dimmer gen1 Generation 1
shellydimmer2 Shelly Dimmer 2 gen1 Generation 1
shellyix3 Shelly ix3 gen1 Generation 1
shellyht Shelly H&T gen1 Generation 1
shellysmoke Shelly Smoke gen1 Generation 1
shellygas Shelly Gas gen1 Generation 1
shellyflood Shelly Flood gen1 Generation 1
shellydw Shelly Door/Window gen1 Generation 1
shellydw2 Shelly Door/Window gen1 Generation 1
shellysense Shelly Sense gen1 Generation 1
shellybutton1 Shelly Button 1 gen1 Generation 1
shellybutton2 Shelly Button 2 gen1 Generation 1
shellymotion Shelly Motion gen1 Generation 1
shellytrv Shelly TRV gen1 Generation 1
shellyplus1 ShellyPlus 1 gen2 Generation 2 Plus series
shellyplus1pm ShellyPlus 1PM gen2 Generation 2 Plus series
shellyplus2pm-relay ShellyPlus 2 Relay gen2 Generation 2 Plus series
shellyplus2pm-roller ShellyPlus 2PM Roller gen2 Generation 2 Plus series
shellyplusplug ShellyPlus Plug gen2 Generation 2 Plus series
shellyplusi4 ShellyPlus i4 gen2 Generation 2 Plus series
shellyplusi4dc ShellyPlus i4DC gen2 Generation 2 Plus series
shelly1mini ShellyPlus 1 Mini gen2 shellymini1?
shellypmmini ShellyPlus PM Mini gen2 shellyminipm?
shelly1pmmini ShellyPlus 1PM Mini gen2 shellymini1pm?
shellypro1 ShellyPro 1 gen2 Generation 2 Pro series
shellypro1pm ShellyPro 1PM gen2 Generation 2 Pro series
shellypro2-relay ShellyPro 2 Relay gen2 Generation 2 Pro series
shellypro2pm-relay ShellyPro 2PM Relay gen2 Generation 2 Pro series
shellypro2pm-roller ShellyPro 2PM Roller gen2 Generation 2 Pro series
shellypro3 ShellyPro 3 gen2 Generation 2 Pro series
shellypro3em Shelly Pro 3EM gen2 Generation 2 Pro series
shellyproem50 Shelly Pro EM-50 gen2 Not documented
shellypro4pm ShellyPro 4PM gen2 Generation 2 Pro series
shellypluswdus Shelly Plus Dimmer US gen2 Shelly Plus Wall Dimmer US
shellyplus10v Shelly Plus Dimmer 10V gen2 Shelly Plus Dimmer 10v
shellyhtg3 ShellyPlus H&T Gen 3 gen2 Generation 2 Plus series
shellyplussmoke Shelly Plus Smoke gen2 Generation 2 Plus series
shellywalldisplay Shelly Wall Display gen1 Generation 2 Plus series Different!
shellydevice Shelly Device gen1 Generation 1
shellyunknown Unknown Shelly Device gen1 Not documented
jlaur commented 1 week ago

@markus7017 - please see revised table above.

Besides a few documentation issues, it seems shellywalldisplay will be determined as gen1, but it's documented as "Generation 2 Plus series".

shelly1mini is probably mistakenly documented as shellymini1. Likewise for shellypmmini vs. shellyminipm and shelly1pmmini vs. shellymini1pm.

FYI @lolodomo, @maniac103, @jimtng as participants in #17009 discussions.

jlaur commented 1 week ago

To be further discussed - how will vendor changes in naming scheme affect the mappings in the binding, and how can we reliably anticipate such changes? See https://github.com/openhab/openhab-addons/pull/17009#issuecomment-2212471709

jlaur commented 1 week ago

shelly1mini is probably mistakenly documented as shellymini1. Likewise for shellypmmini vs. shellyminipm and shelly1pmmini vs. shellymini1pm.

This is not only documentation, but also I18N strings: https://github.com/openhab/openhab-addons/blob/ab385ed2f35612cc447dbe992896d6c0e0c487fb/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties#L106-L109

https://github.com/openhab/openhab-addons/blob/ab385ed2f35612cc447dbe992896d6c0e0c487fb/bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/thing/shellyGen2_relay.xml#L132-L168

Example here: https://github.com/openhab/openhab-addons/issues/17014#issuecomment-2212504838

jlaur commented 1 week ago

shelly1mini is probably mistakenly documented as shellymini1. Likewise for shellypmmini vs. shellyminipm and shelly1pmmini vs. shellymini1pm.

@markus7017, I will create a PR for this since this is not related to API determination.

markus7017 commented 1 week ago

Now we have 2 PRs. I would suggest to continue with #17015

jlaur commented 1 week ago

Now we have 2 PRs. I would suggest to continue with #17015

No, #17015 is only about fixing the thing type descriptions, it is not related to, and will not conflict with, your PR for improving the API determination reliability.