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

Rethink how entity dependencies work #30

Closed
infeeeee opened this issue Dec 20, 2022 · 2 comments · Fixed by #57
Closed

Rethink how entity dependencies work #30

infeeeee opened this issue Dec 20, 2022 · 2 comments · Fixed by #57

Comments

@infeeeee
Copy link
Collaborator

infeeeee commented Dec 20, 2022

I think the current flow is not really efficient, and not easily maintainable.

The problems:

  • You have to be careful which parts of an init goes to Initialize() and PostInitialize(). it's easy to miss it accidentally, and init flow differ between entities, but it could be similar. Sometimes RegisterEntitySensor() is in Initialize() sometimes it's in PostInitialize(). Chaotic.
  • It's not possible to create longer dependency chains. What if Entity A depends on B, but B depends on C. Current flow doesn't support this.
  • The only entities others depends on (de and os) are actually just providing static information, which usually shouldn't change at all. MyApp.App also provides static data, but it's not an Entity but a separate submodule.
  • On the config workflow it's annoying that it tells you that you need another dependency, but it doesn't add it for you automatically.

Possible solutions:

A:
Remove the whole dependency system. Move all the base methods to submodules, just like MyApp. Convert os and de entities similar to AppInfo. If in the future some part of an Entity needed in another one, move that methods to a submodule, or create the new entity as a subclass.

Maybe this new module could be merged with MyApp, to create a single source for all static info. I recommend this solution.

This solution could also help with the config flow, as elements not available could be hidden from the list.

B:
Build correct dependency chain in EntityManager. Evaluate which entity depends on which and initialize them in the correct order.

What do you think @richibrics ? What is your plan with the dependency system?

@richibrics
Copy link
Owner

Hi @infeeee, been busy these days.
Thank you for all your work, I'll watch it in the following days.

I think the choice will be to keep Entity dependencies so I'll create a flow to initialize everything in the correct order.
It will be like:

  • create at runtime the order, based on enabled entities dependencies
  • also check if there are cycles in dependencies

@infeeeee
Copy link
Collaborator Author

Ok, thanks, no rush. I just had too much free time nowadays.

The main problem, I don't understand what is the point of dependencies. They are only checked during Initialize and during normal runtime they don't even matter. What else do you plan to add as dependency source beside existing os and de?

It seems they add a huge avoidable complexity to the code. Remember the KISS principle. I will create proof of concept to show what I'm trying to say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants