foxess_modbus icon indicating copy to clipboard operation
foxess_modbus copied to clipboard

Implement entity schema migrations

Open canton7 opened this issue 1 year ago • 5 comments

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:

  1. Every entity gets tagged with a range of schema versions it supports. The constant LATEST refers to the latest version.
  2. 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.
  3. 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
  4. We provide a button/box in the options flow to manually change the entity schema version if required

  1. We can't store the version in the main config entry, otherwise it gets lost if the use removes/re-adds
  2. 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
  3. We can create a manual store ourselves, but then we need to be able to remove it properly, etc...
  4. A RestoreEntity means that the version is automatically cleared up a week after this entity is removed, which feels like a sensible approach

canton7 avatar Apr 24 '23 13:04 canton7