-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Emulating Alexa Devices on Segments #3822
Emulating Alexa Devices on Segments #3822
Conversation
Hi, can you explain a bit more about the logic of your software design? Especially I'm curious to know how you handle the fact that segments are very volatile in nature. Basicially each click in the segments or presets UI panels can lead to segments being deleted, reordered, or re-allocated - also many interactions with the JSON API will cause deletion of all existing segments. 1/ This implies that any change in presets or segments will lead to deletion and re-announcement of alexa devices? 2/ Also it looks like you keep a Segment pointer with each segment-specific alexa instance... I think that when you later try to modify a segment using the pointer, this could cause access to unallocated memory (use-after-free). Because its basicially impossible to verify that an old pointer (copied when the segment did exist) is still a valid segment pointer when an alexa command arrives. |
Maybe there is a better way to emulate different devices, but I don't see anything close to segments for full control. I know segments are not that suitable for this, but it's the closest thing I can use for separating devices. WLED's architecture is not easily changeable to get a better fit, so this was my 'uncomplicated' solution.
I am passing the index to the lambda function and fetch the segment there. When the index is out of bounds, strip.getSegment() will return the main segment, which is not the right way I guess but won't result in accessing a segment which is deleted. A simple index >= _segments.size() before calling the onSegmentChange and getSegment functions should be enough. |
Another topic - please make sure that your changes will compile on esp32, esp8266 and -S3/-S2/-C3. There is a build error currently on esp32:
Edit: the solution could be to only use the arduino |
…d stuff, little sanity check on segments whether the segment index is existing on alexa change callbacks
@softhack007 I've made some adjustments and added additional sanity checks. If you have a moment, I'd appreciate it if you could review my PR. It should be nearly ready unless there are any suggestions regarding the behavior I've described above. The feature is intended to behave as follows:
|
@blazoncek may I pass this review on to you? I think you're the best one to double-check that |
@geforcefan I think the failed CI builds are not "your responsibility" - looks like something is broken with the platformIO repository in general today.
|
First off, re-base this for 0_15 branch and squash (follow the Wiki). Then I can have a look. |
@blazoncek @softhack007 I apologize for responding late. I was unwell this week due to a severe infection, but I am now feeling better. I have a question for you all: How does Alexa determine the initial values (such as color and brightness) of the device? |
Unfortunately I do not own Alexa and have no knowledge of its workings. |
@geforcefan are you still working towards this PR to be accepted? |
@MadTooler Unfortunately, there wasn't much response or interest in this project. Additionally, none of the project's authors were available to review the logic I adjusted during my refactoring. As a result, I haven't made any further changes since then. While it is functional, I still need to pull the latest changes from the main branch to ensure it works correctly. However, I believe there isn't significant interest in this feature |
@geforcefan Thanks for the reply. it is too bad you were not able to get others on board. If I was working from scratch, I would not be involving alexa devices, but I am adding lighting and features to a family member's home that already has them in place. I will try plugging in your files and see what happens. Thanks again. |
The feature is intended to behave as follows:
Technical Refactorings