-
-
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_TYPEas 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: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
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 doesSVCmean?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_*_STRconstants representid/serviceNamewhich has almost a 1:1 relationship with thing type id's. However, a few of them are mapped differently inTHING_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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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 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 typeshellyblugw(thing typeshellyblugwg3doesn't exist).So let's try the other way around:
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_TYPEprefix 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.
Uh oh!
There was an error while loading. Please reload this page.
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
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.
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.