-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Create miele devices dynamically #143804
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
base: dev
Are you sure you want to change the base?
Create miele devices dynamically #143804
Conversation
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
if new_devices: | ||
self.known_devices.update(new_devices) | ||
for callback in self.new_device_callbacks: | ||
callback( |
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 think we should test those (e.g. that really all entities get added automatically and we didn't miss/mess up a platform). Set up the integration, add a device, let the freezer tick, then check we have the new devices.
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 did a quick test that all intended platforms are loaded by the default data fixture. To add an extra device after a delay needs some more thinking and I don't think I can make that before beta cut.
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.
Is it really that complicated? Don't you just need to add a device in the get_devices
fixture dict (e.g. by copying one of those in there and changing the name&id) after integration setup, then let the freezer tick?
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 might not be complicated, but it is beyond my comfort zone... And I have some other commitments away from my desk tomorrow.
You mean that I first load default 4_devices.json and then after setup the next get_devices() should get another file (5_devices.json)? Can you point me at an example?
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 don’t think you'll even need a full fixture file just basically get_devices.return_value["deviceB"] = get_devices.return_value["deviceA"]
and then adapt its identifier to make sure we have unique ids. I think I'm doing something like this in tedee
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 am looking into this PR now. There is a race problem in that coordinator.data must be complete with new data before kicking off the platform callbacks. It works fine directly after setup but not when I find added devices within async_update_data(). I have to find a way to move the hunt for new devices a bit later in the chain.
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.
you can just write to self.data
during async_update_data
if that helps
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 have made it work nice and clean IRL. I have issues with the tests though. If I run a single test with pytest ... -k test_function
, it works as intended, but when I run a whole file or all of the tests for the integration it will fail. It seems to be related to the loading of alternate fixture files. It works for a single test, but the alternate is not loaded if other tests have been run before.
There are conflicts and I was talking about the dynamic part: If you add an additional device after the initial setup, still all entities for that new device get added correctly after the initial setup |
If new devices appear in the cloud account, they are automatically added to the integration.
Type of change
Additional information
Checklist
ruff format 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
.To help with the load of incoming pull requests: