foxess_modbus
foxess_modbus copied to clipboard
Implement entity schema migrations
The aim here:
- We have integration entities which really should be replaced by totals read directly from the inverter
- We have some inconsistent naming of entity ids which we should probably fix
- We should not break anyone who is already using this integration: this could break their automations etc, and could remove statistic history which they might care about. This includes if they remove/readd this integration, as that's the only supported way to change some settings
I think the best way to do this is:
- Every entity gets tagged with a range of schema versions it supports. The constant
LATEST
refers to the latest version. - We create an entity which holds the current schema version. This is a RestoreEntity. This is not linked to any device -- it applies across all devices.
- On startup, we manually load the state of this entity (we can't wait for it to be loaded by HA), then we only load entities whose version range includes this version
- We provide a button/box in the options flow to manually change the entity schema version if required
- We can't store the version in the main config entry, otherwise it gets lost if the use removes/re-adds
- I don't think we can store it in a separate config entry (although we can create additional config entries), as HA will try and load us from that
- We can create a manual store ourselves, but then we need to be able to remove it properly, etc...
- A RestoreEntity means that the version is automatically cleared up a week after this entity is removed, which feels like a sensible approach