-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[shelly] Fix support for Shelly Plug US #18775
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
Conversation
missing the "plus" - shellyplugus instead of shellyplusplugus. As a result the thing uses the Gen1 API, which does not work. Signed-off-by: Markus Michels <markus7017@gmail.com>
Signed-off-by: Markus Michels <markus7017@gmail.com>
Signed-off-by: Markus Michels <markus7017@gmail.com>
Are you testing this yourself @markus7017 or if you need others, providing a jar and/or link to a community thread, testing would be made easier and the review/merge proces shorter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. I'm on holiday reviewing on my phone, so could have missed some details. However, two minor things noted.
public static final String THING_TYPE_SHELLYPLUSSMOKE_STR = "shellyplussmoke"; | ||
public static final String THING_TYPE_SHELLYPLUSUNI_STR = "shellyplusuni"; | ||
public static final String THING_TYPE_SHELLYPLUSPLUGS_STR = "shellyplusplug"; | ||
public static final String SVC_TYPE_SHELLYPLUSPLUGUS_STR = "shellyplugus"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is SVC for? All other seem to have THING_TYPE
as prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used a constant to handle this special case. The serviceName from mDNS discovery is shellyplugus whereas the thing type is shellyplusplug. With the missing plus (shellyplusplugus) the detection of a Gen2+ device fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is similar to e.g. THING_TYPE_SHELLYBLUGWG3_STR
, so you could use:
public static final String SVC_TYPE_SHELLYPLUSPLUGUS_STR = "shellyplugus"; | |
public static final String THING_TYPE_SHELLYPLUGUS_STR = "shellyplugus"; |
for consistency, or refactor all "unused"/alias thing types into a group with similar naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, because SVC_TYPE_SHELLYPLUSPLUGUS_STR is the serviceName reported by the device and
THING_TYPE_SHELLYPLUGUS_STR is the thing type.
I'm wondering, because my code shows
public static final String SVC_TYPE_SHELLYPLUSPLUGUS_STR = "shellyplugus";
public static final String THING_TYPE_SHELLYPLUSPLUGUS_STR = "shellyplusplugus";
See the difference between shellyplugus (serviceName) and shellyplusplugus (thingType).
That's the mapping, which is required
if serviceName == shellyplugus map it to thingType shellyplusplugus, which then initializes the V2 API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware of that. As I said, it's the same as for example THING_TYPE_SHELLYBLUGWG3_STR
, so I don't see any reason to use different naming here? And what does SVC
mean?
This is related to #18729 (comment), you might want to have a look and possibly comment if I didn't understand it correctly. We could refactor it further, but probably not in context of this PR here. I would appreciate any input for the direction. Currently the THING_TYPE_*_STR
constants represent id
/serviceName
which has almost a 1:1 relationship with thing type id's. However, a few of them are mapped differently in THING_TYPE_MAPPING
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware of that. As I said, it's the same as for example
THING_TYPE_SHELLYBLUGWG3_STR
, so I don't see any reason to use different naming here? And what doesSVC
mean?
No, it's not.
In case of the BLU GW it's mapping shellyblugw as well as shellyblugwg3 to shellyblugw. shellyblu is recognized as a prefix to enforce APIv2 initialization. shellyblugwg3 is the device's service name announced via mDNS.
In this case here shellyplugus would initialize APIv1
SVC_ stands for Service. SVC_TYPE_SHELLYPLUSPLUGUS_STR is the device's service name announced via mDNS. This is not the thingType. It is just used to do the mapping into the thing type name.
We could also use a different prefix as you prefer, but I need the 2 different values and don't want to hard-code them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware of that. As I said, it's the same as for example
THING_TYPE_SHELLYBLUGWG3_STR
, so I don't see any reason to use different naming here? And what doesSVC
mean?This is related to #18729 (comment), you might want to have a look and possibly comment if I didn't understand it correctly. We could refactor it further, but probably not in context of this PR here. I would appreciate any input for the direction. Currently the
THING_TYPE_*_STR
constants representid
/serviceName
which has almost a 1:1 relationship with thing type id's. However, a few of them are mapped differently inTHING_TYPE_MAPPING
.
I commented the questions in the other comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THING_TYPE_SHELLYBLUGWG3_STR
= "shellyblugwg3" => creates thing type shellyblugw
(thing type shellyblugwg3
doesn't exist).
So let's try the other way around:
In case of the BLU GW it's mapping shellyblugw as well as shellyblugwg3 to shellyblugw. shellyblu is recognized as a prefix to enforce APIv2 initialization. shellyblugwg3 is the device's service name announced via mDNS.
In case of the Shelly Plug US it's mapping shellyplusplugus as well as shellyplugus to shellyplusplugus. shellyplus is recognized as a prefix to enforce APIv2 initialization. shellyplugus is the device's service name announced via mDNS.
I'm not insisting on any specific name, only to keep things consistent, since it's already a bit confusing and error-prone.
Following the BLU GW example (as well as other similar ones), I already made the suggestion here: #18775 (comment). I agree that the THING_TYPE
prefix is confusing when it doesn't actually represent a thing type, however that would be consistent with how things are now.
If you don't want to touch this right now in this PR, I can offer to propose some additional rework, since I don't think we should leave this inconsistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the BLU GW example
That's a different case, because the device reports the correct serviceName > thingType
Gen2: shellyblugw -> shellyblugw
Gen3: shellyblugwg3 > shellyblugw
If you don't want to touch this right now in this PR
I prefer to leave it as is. Any change here could result in significant regression testing
We should merge as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a different case, because the device reports the correct serviceName > thingType
Gen2: shellyblugw -> shellyblugw
Gen3: shellyblugwg3 > shellyblugw
It seems we are still not understanding each other. Maybe it reports "correct" service name, but it's still not mapped directly to a thing type id. shellyblugwg3 is mapped to shellyblugw. So here shellyblugwg3 is the service name, but we don't have a corresponding thing type id. Just like shellyplus is not directly mapped to shellyplugus, but rather shellyplusplugus. You could say that it doesn't have a correct service name, but it really makes no difference from code perspective. It has the service name it has. In either case, we are mapping one service name to a (different) thing type id.
I can merge in the evening, I'll just add one additional line for testing the gen2 property: #18775 (comment). I will then try to propose something to make this more robust. I may start out creating an issue outlining the problem and possible improvements.
bundles/org.openhab.binding.shelly/src/main/resources/OH-INF/i18n/shelly.properties
Outdated
Show resolved
Hide resolved
@markus7017 - since thing type |
Signed-off-by: Markus Michels <markus7017@gmail.com>
@jlaur review changes applied |
Yes it did. |
Thanks for the explanation. I guess when it last worked, it was using the same thing type as the non-US version then, but now it has its own in order to have a different label/description? |
It was integrated a long time ago, when the Gen flag of the mDNS discovery was processed. Then we changed that handling and as a side effect broke support for this device. I'm in the US only from time to time. This time I recognized that it's broken and fixed it here on site. I think there is no user in the US using the binding and having this device. Therefore... |
I meant to simply ask for confirmation that the reason a new thing type was introduced here (which was never there before), is to have a different label and description? Otherwise they are totally the same, correct? |
I need the "plus" in the thingType name to ensure using V2 API |
Ah, right, I forgot this is based on thing type id. So otherwise this method would need to be tweaked: Lines 412 to 417 in 057dedf
Could you also add a testcase for the new thing type id around here to make sure it will keep working? 😉 Lines 70 to 72 in 057dedf
|
I'm thinking to re-implement the handling based on the gen flag from mDNS announcement. This is a clear indicator, everything around names might has gaps, because as Plug US shows even single devices do not implement consistent naming. On the other this gen detected based on mDNS does not cover the scenario when the user adds a thing manually. |
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Fix Shelly Plug US: This is a Gen2 device, but the service name is missing the "plus" - shellyplugus instead of shellyplusplugus. As a result the thing uses the Gen1 API, which does not work. Signed-off-by: Markus Michels <markus7017@gmail.com>
* Fix Shelly Plug US: This is a Gen2 device, but the service name is missing the "plus" - shellyplugus instead of shellyplusplugus. As a result the thing uses the Gen1 API, which does not work. Signed-off-by: Markus Michels <markus7017@gmail.com> Signed-off-by: Paul Smedley <paul@smedley.id.au>
Fix Shelly Plug US: This is a Gen2 device, but the service name is missing the "plus" - shellyplugus instead of shellyplusplugus. As a result the thing uses the Gen1 API, which does not work.
Signed-off-by: Markus Michels markus7017@gmail.com