Discover new added device at runtime in AVM Fritz!Smarthome#103859
Conversation
|
Hey there @flabbamann, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
mib1185
left a comment
There was a problem hiding this comment.
I've reworked this PR, it should now be less complex.
- the coordinator has two new properties which show the new devices and templates (during init all devices/templates are new)
- all platforms registers to coordinator updates and add new entities if needed
- at each platform init all entities will be added
|
Im sorry to say i think you should partly revert to how you had ut before so something like coordinator update() devices = { platform: standard coordinator listener callback. just add all in devices_new. devices = |
elupus
left a comment
There was a problem hiding this comment.
Looks reasonable. There are some optimizations you could make.
- avoid calling add_entities with empty lists (early return in function)
- calling add_entities with a generator instead of a list so you dont have to pre allocate the list (async_add_entities(Entity(x.ain) for x.in new_devices))
- figuring out if there are som common code. For example s utility function to get the typed coordinator object like get_coordinator(entry.id)
|
Ps. Martin may have some more thoughs. So might be good to wait a bit. |
|
Valid points, will work on the optimizations today evening 👍 |
| if not coordinator.new_devices: | ||
| return | ||
| async_add_entities( | ||
| [ |
There was a problem hiding this comment.
We can remove the brackets to make it a generator expression instead of a list comprehension.
Proposed change
This will add support of creating entities for newly paired devices at runtime.
Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: