-
-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Also migrate dsmr entries for devices with correct serial #123407
Conversation
When the dsmr code could not find the serial_nr for the gas meter, it creates the gas meter device with the entry_id as identifier. But when there is a correct serial_nr, it will use that as identifier for the dsmr gas device. Now the migration code did not take this into account, so migration to the new name failed since it didn't look for the device with correct serial_nr. This commit fixes this and adds a test for this.
Hey there @RobBie1221, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
) | ||
if not dev_entities: | ||
dev_reg.async_remove_device(device_id) | ||
for dev_id in (mbus_device_id, entry.entry_id): |
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.
We could look for a device with entry.data[CONF_SERIAL_ID_GAS]?
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.
In fact we should stop using CONF_SERIAL_ID_GAS for devices with mbus devices.
Cause CONF_SERIAL_ID_GAS
is a single entity ... while with mbus we have 4 devices that can be linked to the main device, so you can have 4 gas meters in theory.
Better check for the mbus_device_id.
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.
What about non mbus 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.
How you mean? There should be only 1 main SERIAL for the device and then a serial per mbus device.
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 not sure what il saying. I think i would have been more happy with doing a full unique_id check and just iterate over all entities in the config entry instead of per device.
Unique_id, should be just that, unique for the integration. The associated device have nothing to do with it really.
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 still don't like doing a RANDOM_PREFIX_THAT_CAN_BE_ANYTHINGhourly_gas_meter_reading
-> mbus_device_id
. It's very error prone.
ALSO, which missed before: async_entries_for_device can include entities from other platform, like helpers. They are unlikely to have that unique_id, but nothing really stopping them.
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.
But migrating the sensor to the correct/new device is better/cleaner, as before 9118260 for example the device did not have the correct serial like it should.
This will be handled automatically as soon as the device is added to the system so migration code does not need to do that.
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.
But migrating the sensor to the correct/new device is better/cleaner, as before 9118260 for example the device did not have the correct serial like it should.
This will be handled automatically as soon as the device is added to the system so migration code does not need to do that.
As long as we cleanup the old/empty device then :)
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 still don't like doing a
RANDOM_PREFIX_THAT_CAN_BE_ANYTHINGhourly_gas_meter_reading
->mbus_device_id
. It's very error prone.ALSO, which missed before: async_entries_for_device can include entities from other platform, like helpers. They are unlikely to have that unique_id, but nothing really stopping them.
Just need to make sure there are not older versions that created the sensors with even another prefix.
I think not, but might be good to double check.
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.
Ok. Let's do it this way for now. The prefix was weird historically too.
I would like to remove this migration code as soon as we can. But ends up a year in the future i think.
@dupondje Think you would be up for taking on maintainership on this component?
dsmr: also migrate entries for devices with correct serial When the dsmr code could not find the serial_nr for the gas meter, it creates the gas meter device with the entry_id as identifier. But when there is a correct serial_nr, it will use that as identifier for the dsmr gas device. Now the migration code did not take this into account, so migration to the new name failed since it didn't look for the device with correct serial_nr. This commit fixes this and adds a test for this.
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.
Please address the comment in a new PR. Thanks!
ent_reg, device_id, include_disabled_entities=True | ||
) | ||
if not dev_entities: | ||
dev_reg.async_remove_device(device_id) |
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's safer to update the device entry and remove the config entry id. If it was the only config entry id, the device entry will be removed automatically.
When the dsmr code could not find the serial_nr for the gas meter, it creates the gas meter device with the entry_id as identifier.
But when there is a correct serial_nr, it will use that as identifier for the dsmr gas device.
Now the migration code did not take this into account, so migration to the new name failed since it didn't look for the device with correct serial_nr.
This commit fixes this and adds a test for this.
Breaking change
Proposed change
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: