Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shelly] Fix Gen1 initialization when thing is defined in .things #17009

Merged
merged 1 commit into from
Jul 7, 2024

Conversation

markus7017
Copy link
Contributor

@markus7017 markus7017 commented Jul 7, 2024

Fixes Gen1 initialization when thing is defined in .things (discovered and added thing via UI worked fine, Gen2+3 also)

See also #17006

…ings

Signed-off-by: Markus Michels <markus7017@gmail.com>
@markus7017 markus7017 self-assigned this Jul 7, 2024
@markus7017 markus7017 added the bug An unexpected problem or unintended behavior of an add-on label Jul 7, 2024
@markus7017 markus7017 requested a review from lolodomo July 7, 2024 07:40
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted as a quick fix.

But please continue the discussion to explain why a thing property was used instead of an optional thing configuration setting so that it can be provided in a thing file.

@lolodomo lolodomo merged commit ab385ed into openhab:main Jul 7, 2024
5 checks passed
@lolodomo lolodomo added this to the 4.2 milestone Jul 7, 2024
@jlaur jlaur added critical regression Regression that happened during the development of a release. Not shown on final release notes. labels Jul 7, 2024
@jlaur jlaur changed the title [shelly] Fixes Gen1 initialization when thing is defined in .things [shelly] Fix Gen1 initialization when thing is defined in .things Jul 7, 2024
blu = ShellyDeviceProfile.isBluSeries(thingType);
gen2 = "2".equals(gen) || "3".equals(gen) || blu || ShellyDeviceProfile.isGeneration2(thingType);
Copy link
Contributor

@jlaur jlaur Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can thing type be ambiguous, so that you cannot reliably determine generation from it?

If it can, I guess this will still be broken for users having manually created things?

It it cannot, why check the property at all to determine generation? Would this work:

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

?

Or going further:

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);
}

See also #17006 (comment)

Cc @markus7017, @lolodomo, @maniac103

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is exactly one of my questions in previous @J-N-K PR.

Copy link
Contributor

@lolodomo lolodomo Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on whether this property is only informative or really required to initialize the handler. If required, it should be a configuration setting.

Copy link
Contributor

@jlaur jlaur Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but since the property is still checked in this PR, I wanted to ask it again and even more explicitly to fully understand. I can see only one reason for checking the property at all, and that would be some corner case where thing type is not sufficient. In that case, even this fix would not work for all scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the thing type-based generation checks:

public static boolean isGeneration2(String thingType) {
return thingType.startsWith("shellyplus") || thingType.startsWith("shellypro") || thingType.contains("mini")
|| (thingType.startsWith("shelly") && thingType.contains("g3")) || isBluSeries(thingType);
}
public static boolean isBluSeries(String thingType) {
return thingType.startsWith("shellyblu") && !thingType.startsWith(THING_TYPE_SHELLYBLUGW_STR);
}

I tried to apply this logic the all thing types:

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

Does it look good to you?

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-4-2-milestone-discussion/154316/247

@markus7017
Copy link
Contributor Author

The device reports the device generation as part of the mDNS discovery, that's the source of truth and has to have priority in determining this information, which is then used to select Gen1 or Gen2 API format.
The device generation is a model specific so a device/thing property, not a config optgion

When the thing is manually defined in .things (without proper information) the binding checks the thing type to get the information:

  • shellyplusxxx or shellyproxxx is Gen2, whereas shellyplusxxxg3 is gen3
  • shellyminixxx is Gen 2 whereas shelyminixxxg3 is Gen 3 (but not Gen1)
  • shellybluxxx is Gen2
  • otherwise is Gen1
    there is no guarantee that Allterco keeps that name schema for upcoming devices, therefor detection should be based on the "gen" reported by the device through mDNS Discovery.

Therefore the logic is a proper solution.

@lolodomo
Copy link
Contributor

lolodomo commented Jul 7, 2024

In that case, I understand the property has to be replaced by a configuration parameter so that it can be set either in a thing file or in UI when creating a thing. It will be optional.

The problem is not specific to file configuration, the problem is if discovery is not used.

@markus7017
Copy link
Contributor Author

In that case, I understand the property has to be replaced by a configuration parameter so that it can be set either in a thing file or in UI when creating a thing. It will be optional.

No, strongly disagree. A config parameter is selectable by the use. A Gen1 device has to use a Gen1 API and Gen 2+3 the Gen 2 API. It doesn't make any sense that the use can select Gen 2 API for Gen 1 device and vice versa.

@lolodomo
Copy link
Contributor

lolodomo commented Jul 7, 2024

I give up

@jlaur
Copy link
Contributor

jlaur commented Jul 7, 2024

  • there is no guarantee that Allterco keeps that name schema for upcoming devices, therefor detection should be based on the "gen" reported by the device through mDNS Discovery.

You cannot rely on mDNS for this, this will break manually created things. I think I understand everything you've written, but you still haven't really answered my questions here:

I would really appreciate if you would, because otherwise I'm afraid we'll continue running in circles.

I will ask them again here, slightly differently, can you please answer each question directly so we can avoid further misunderstandings/miscommunication?

First, discovery determines generation from mDNS. It then creates a thing with a specific thingTypeId and with a deviceGeneration property.

  1. Is the generationthingTypeId symmetric, i.e. when you determine thingTypeId from generation, and then determine generation from thingTypeId, will it give you the same result as you started out with? I.e. Gen2 → shellypro1 → Gen2
  2. Will this code work, i.e. skipping the property check?
    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);
    }
  3. If not, why not? (This is connected to question 1).
  4. I spent some time creating this list, can you please verify if it looks good to you? [shelly] Fix Gen1 initialization when thing is defined in .things #17009 (comment)

@jimtng
Copy link
Contributor

jimtng commented Jul 7, 2024

I'm jumping on this without a full understanding, so I apologise beforehand. However, it seems to me that the solution should be:

  • Have a Thing configuration so the user can specify the device generation manually. If it's the wrong generation, it's the user's responsibility (and control) to edit the config and enter the correct generation.
    • An added bonus if the binding can then try other generations until one works, but this is a separate point. Not necessary and I know this would make things more complicated perhaps unnecessarily. If this does get implemented, it can first even try to gather the information from mdns. It then updates the generation property.
  • However, if the generation information is gathered through mdns / discovery, then that information gets stored in thing property, and supersedes the manual configuration.

@markus7017
Copy link
Contributor Author

Re 4) yes, the list is correct until Allterca changes their naming schema
Re 1) I don't understand your question, but yes, thing types starting from shellyplus/pro/mini/blu/*g3 will always be Gen2
Re 2) yes, BLU is Gen2, but requires a more specialized thing handler
Re 3) it does

As I said, this will work unless Allterco brings a new Shelly device with different naming schema, but for now the logic will work and I could change it. I refuse to implement a config option, a Gen1 device will never work with a Gen2 API and vice versa.

Do we agree on 2) and see what happens for users upgrading to the new version?

@markus7017
Copy link
Contributor Author

I verified the change with

  • Shelly 1 defined in .things (Gen1)
  • Shelly Plus Plug in .things (Gen2)
  • A Shelly 1 and a 2.5 discovered by UI (Gen 1)
  • A mix of Gen 2 and Gen 3 devices discovered by the UI

@markus7017
Copy link
Contributor Author

PR #17011 has been created with this change

@jlaur
Copy link
Contributor

jlaur commented Jul 7, 2024

Re 4) yes, the list is correct until Allterca changes their naming schema

I don't understand the correlation here, can you explain? I had a look at this thing type mapping:

private static final Map<String, String> THING_TYPE_MAPPING = new LinkedHashMap<>();
static {
// mapping by device type id
THING_TYPE_MAPPING.put(SHELLYDT_1PM, THING_TYPE_SHELLY1PM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_1L, THING_TYPE_SHELLY1L_STR);
THING_TYPE_MAPPING.put(SHELLYDT_1, THING_TYPE_SHELLY1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_SHPRO, THING_TYPE_SHELLY4PRO_STR);
THING_TYPE_MAPPING.put(SHELLYDT_4PRO, THING_TYPE_SHELLY4PRO_STR);
THING_TYPE_MAPPING.put(SHELLYDT_3EM, THING_TYPE_SHELLY3EM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_EM, THING_TYPE_SHELLYEM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_SHPLG_S, THING_TYPE_SHELLYPLUGS_STR);
THING_TYPE_MAPPING.put(SHELLYDT_SHPLG_U1, THING_TYPE_SHELLYPLUGU1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_GAS, THING_TYPE_SHELLYGAS_STR);
THING_TYPE_MAPPING.put(SHELLYDT_DW, THING_TYPE_SHELLYDOORWIN_STR);
THING_TYPE_MAPPING.put(SHELLYDT_DW2, THING_TYPE_SHELLYDOORWIN2_STR);
THING_TYPE_MAPPING.put(SHELLYDT_DUO, THING_TYPE_SHELLYDUO_STR);
THING_TYPE_MAPPING.put(SHELLYDT_DUORGBW, THING_TYPE_SHELLYDUORGBW_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BULB, THING_TYPE_SHELLYBULB_STR);
THING_TYPE_MAPPING.put(SHELLYDT_VINTAGE, THING_TYPE_SHELLYVINTAGE_STR);
THING_TYPE_MAPPING.put(SHELLYDT_DIMMER, THING_TYPE_SHELLYDIMMER_STR);
THING_TYPE_MAPPING.put(SHELLYDT_DIMMER2, THING_TYPE_SHELLYDIMMER2_STR);
THING_TYPE_MAPPING.put(SHELLYDT_IX3, THING_TYPE_SHELLYIX3_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BUTTON1, THING_TYPE_SHELLYBUTTON1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BUTTON2, THING_TYPE_SHELLYBUTTON2_STR);
THING_TYPE_MAPPING.put(SHELLYDT_UNI, THING_TYPE_SHELLYUNI_STR);
THING_TYPE_MAPPING.put(SHELLYDT_HT, THING_TYPE_SHELLYHT_STR);
THING_TYPE_MAPPING.put(SHELLYDT_TRV, THING_TYPE_SHELLYTRV_STR);
THING_TYPE_MAPPING.put(SHELLYDT_MOTION, THING_TYPE_SHELLYMOTION_STR);
// Plus Series
THING_TYPE_MAPPING.put(SHELLYDT_PLUS1, THING_TYPE_SHELLYPLUS1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUS1PM, THING_TYPE_SHELLYPLUS1PM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUS1UL, THING_TYPE_SHELLYPLUS1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUS1PMUL, THING_TYPE_SHELLYPLUS1PM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_RELAY, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_ROLLER, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_RELAY_2, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUS2PM_ROLLER_2, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGS, THING_TYPE_SHELLYPLUSPLUGS_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGIT, THING_TYPE_SHELLYPLUSPLUGS_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGUK, THING_TYPE_SHELLYPLUSPLUGS_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSPLUGUS, THING_TYPE_SHELLYPLUSPLUGUS_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSI4DC, THING_TYPE_SHELLYPLUSI4DC_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSI4, THING_TYPE_SHELLYPLUSI4_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSHT, THING_TYPE_SHELLYPLUSHT_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSHTG3, THING_TYPE_SHELLYPLUSHTG3_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSSMOKE, THING_TYPE_SHELLYPLUSSMOKE_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSUNI, THING_TYPE_SHELLYUNI_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSDIMMERUS, THING_TYPE_SHELLYPLUSDIMMERUS_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PLUSDIMMER10V, THING_TYPE_SHELLYPLUSDIMMER10V_STR);
// Plus Mini Series
THING_TYPE_MAPPING.put(SHELLYDT_MINI1, THING_TYPE_SHELLYMINI1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_MINIPM, THING_TYPE_SHELLYMINIPM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_MINI1PM, THING_TYPE_SHELLYMINI1PM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_MINI1G3_1, THING_TYPE_SHELLYMINI1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_MINIG3_PM, THING_TYPE_SHELLYMINIPM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_MINIG3_1PM, THING_TYPE_SHELLYMINI1PM_STR);
// Pro Series
THING_TYPE_MAPPING.put(SHELLYDT_PRO1, THING_TYPE_SHELLYPRO1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO1_2, THING_TYPE_SHELLYPRO1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO1_3, THING_TYPE_SHELLYPRO1_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM, THING_TYPE_SHELLYPRO1PM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM_2, THING_TYPE_SHELLYPRO1PM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO1PM_3, THING_TYPE_SHELLYPRO1PM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY, THING_TYPE_SHELLYPRO2_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY_2, THING_TYPE_SHELLYPRO2_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2_RELAY_3, THING_TYPE_SHELLYPRO2_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY, THING_TYPE_SHELLYPRO2PM_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY_2, THING_TYPE_SHELLYPRO2PM_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_RELAY_3, THING_TYPE_SHELLYPRO2PM_RELAY_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER, THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER_2, THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO2PM_ROLLER_3, THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO3, THING_TYPE_SHELLYPRO3_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PROEM50, THING_TYPE_SHELLYPROEM50_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO3EM, THING_TYPE_SHELLYPRO3EM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO4PM, THING_TYPE_SHELLYPRO4PM_STR);
THING_TYPE_MAPPING.put(SHELLYDT_PRO4PM_2, THING_TYPE_SHELLYPRO4PM_STR);
// BLU Series
THING_TYPE_MAPPING.put(SHELLYDT_BLUBUTTON, THING_TYPE_SHELLYBLUBUTTON_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BLUDW, THING_TYPE_SHELLYBLUDW_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BLUMOTION, THING_TYPE_SHELLYBLUMOTION_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BLUHT, THING_TYPE_SHELLYBLUHT_STR);
THING_TYPE_MAPPING.put(SHELLYDT_BLUGW, THING_TYPE_SHELLYBLUGW_STR);
// Wall displays
THING_TYPE_MAPPING.put(SHELLYDT_PLUSWALLDISPLAY, THING_TYPE_SHELLYPLUSWALLDISPLAY_STR);
// mapping by thing type
THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1_STR, THING_TYPE_SHELLY1_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1PM_STR, THING_TYPE_SHELLY1PM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLY1L_STR, THING_TYPE_SHELLY1L_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLY3EM_STR, THING_TYPE_SHELLY3EM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYEM_STR, THING_TYPE_SHELLYEM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLY4PRO_STR, THING_TYPE_SHELLY4PRO_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDIMMER2_STR, THING_TYPE_SHELLYDIMMER2_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDIMMER_STR, THING_TYPE_SHELLYDIMMER_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYIX3_STR, THING_TYPE_SHELLYIX3_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUORGBW_STR, THING_TYPE_SHELLYDUORGBW_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUO_STR, THING_TYPE_SHELLYDUO_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYVINTAGE_STR, THING_TYPE_SHELLYVINTAGE_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBULB_STR, THING_TYPE_SHELLYBULB_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDUO_STR, THING_TYPE_SHELLYDUO_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYHT_STR, THING_TYPE_SHELLYHT_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYSMOKE_STR, THING_TYPE_SHELLYSMOKE_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYGAS_STR, THING_TYPE_SHELLYGAS_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYFLOOD_STR, THING_TYPE_SHELLYFLOOD_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYTRV_STR, THING_TYPE_SHELLYTRV_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDOORWIN_STR, THING_TYPE_SHELLYDOORWIN_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYDOORWIN2_STR, THING_TYPE_SHELLYDOORWIN2_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYSENSE_STR, THING_TYPE_SHELLYSENSE_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYEYE_STR, THING_TYPE_SHELLYEYE_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBUTTON1_STR, THING_TYPE_SHELLYBUTTON1_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYBUTTON2_STR, THING_TYPE_SHELLYBUTTON2_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYUNI_STR, THING_TYPE_SHELLYUNI_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYMOTION2_STR, THING_TYPE_SHELLYMOTION_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1PM_STR, THING_TYPE_SHELLYPLUS1PM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1_STR, THING_TYPE_SHELLYPLUS1_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS1PM_STR, THING_TYPE_SHELLYPLUS1PM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_RELAY_STR, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_ROLLER_STR, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_RELAY_STR, THING_TYPE_SHELLYPLUS2PM_RELAY_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUS2PM_ROLLER_STR, THING_TYPE_SHELLYPLUS2PM_ROLLER_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSPLUGS_STR, THING_TYPE_SHELLYPLUSPLUGS_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSPLUGUS_STR, THING_TYPE_SHELLYPLUSPLUGUS_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSI4DC_STR, THING_TYPE_SHELLYPLUSI4DC_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSI4_STR, THING_TYPE_SHELLYPLUSI4_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSHT_STR, THING_TYPE_SHELLYPLUSHT_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSSMOKE_STR, THING_TYPE_SHELLYPLUSSMOKE_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSUNI_STR, THING_TYPE_SHELLYUNI_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSDIMMERUS_STR, THING_TYPE_SHELLYPLUSDIMMERUS_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSDIMMER10V_STR, THING_TYPE_SHELLYPLUSDIMMER10V_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPLUSWALLDISPLAY_STR, THING_TYPE_SHELLYPLUSWALLDISPLAY_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYMINI1_STR, THING_TYPE_SHELLYMINI1_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYMINIPM_STR, THING_TYPE_SHELLYMINIPM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYMINI1PM_STR, THING_TYPE_SHELLYMINI1PM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO1_STR, THING_TYPE_SHELLYPRO1_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO1PM_STR, THING_TYPE_SHELLYPRO1PM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2PM_RELAY_STR, THING_TYPE_SHELLYPRO2PM_RELAY_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2PM_ROLLER_STR, THING_TYPE_SHELLYPRO2PM_ROLLER_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO2_RELAY_STR, THING_TYPE_SHELLYPRO2_RELAY_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPROEM50_STR, THING_TYPE_SHELLYPROEM50_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO3EM_STR, THING_TYPE_SHELLYPRO3EM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO3_STR, THING_TYPE_SHELLYPRO3_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPRO4PM_STR, THING_TYPE_SHELLYPRO4PM_STR);
THING_TYPE_MAPPING.put(THING_TYPE_SHELLYPROTECTED_STR, THING_TYPE_SHELLYPROTECTED_STR);
}

Once a thing type id is determined and the thing is created, one specific API will be used for that thing type based on the mentioned logic.

If vendor changes naming scheme, I suppose the mapping would need to be updated to determine the correct thing types to create from discovery, correct? That would not break existing things, only things created from discovery. And the work-around would be to create the thing manually, so that the correct corresponding API would be used?

Do we agree on 2) and see what happens for users upgrading to the new version?

If you agree that the proposed approach is reliable, yes - then I agree we should remove any dependency upon properties for determining the API revision to use.

psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Jul 12, 2024
…ings (openhab#17009)

Signed-off-by: Markus Michels <markus7017@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on critical regression Regression that happened during the development of a release. Not shown on final release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants