Handle initial event after entity is added.#6760
Conversation
|
@aequitas, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fabaff, @pvizeli and @martinfrancois to be potential reviewers. |
|
I don't think that is a real bugfix. Maby we can add this for 0.41.0 but it need a future work for make it realy rubust and move some stuff from |
|
It would be nice to have a feed of updates for developers to keep up to date with the latest changes in Core without having to follow every commit and change. Like a summary of (breaking) changes and the directions that are chosen architecture wise, new best practices, etc. There is some nice documentation for developers already. But keeping on track with developments is hard if your not full-time invested in the project or part of the core team. I feel responsible for my contributions and like to support other users with problems. But it frustrates the process when I'm lagging behind on information because I don't have the time to catch up on changes. It is not a complete bugfix indeed as race conditions can occur. But local testing reduced the reported errors to zero so at least this change prevents some of the error chatter for users. Worst case like it is without the change the initial event is not handled by the newly created entity but an error is still logged. I think refactoring to the dispatcher would make sense, I will start a separate PR for that. I used the event bus in a similar fashion before switching to this method as the dispatcher was not implemented back then and the event bus was not designed for this type of events. I don't think passing it to the init is the cleanest solution though. Ignoring the initial event is also not the nicest solution. I will try to figure something out. Feel feel to merge or close this PR. As it currently is not breaking functionality, just causing error messages there should be no harm. |
|
I agree that we can do better with communicating the core changes. If I had more time I would spend some more time on the docs, they are getting somewhat outdated. For what it's worth, I don't expect any more changes in the near future. The core + systems around it are now all as much async as it can be. I'll merge this PR and looking forward to the port to dispatcher. 🐬 |
Description: Make sure entity is not used before it can be used.
Recently entity creation has been made asynchronous. The Rflink codebase assumes it to be synchronous. If an event for a unknown entity is received a new entity object is created and added. The event handler is also directly called on the new object to update the new entities state with the incoming event. The subsequent
async_update_ha_stateis called on an 'unadded' entity which causes errors as described in: #5965