Proposal: Add helper for deprecating entities #1133
Unanswered
sdb9696
asked this question in
Entity Models
Replies: 1 comment 1 reply
-
I think what's missing is the "when/if/how" for notifications to the user in this proposal. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
It is sometimes necessary for integrations to stop providing an entity. This could be due to a migration to a new entity that provides richer/better support (e.g.
switch
->siren
,binary_sensor
->event
) or could be removing the entity without a replacement for various reasons.The best practice in these instances is to give users 6 months to migrate any scripts or automations to the new entity. If the entity is being removed with no replacement, I believe it would also be considered best practice to give 6 months notice if possible.
It is a common pattern to implement a check if a deprecated entity is being used in any issues or scripts and create an issue in the issue log accordingly.
The lutron and ring examples (ring PR was based on the lutron PR) have additional functionality which immediately prevents the deprecated entity being created if it does not already exist, and, if the entity is currently disabled it is deleted from the entity registry.
Once the
breaks_in_ha_version
is reached the codeowner will need to go back into the codebase to remove the entity (and usually remove the checking and issue creation code.)Proposal
The proposal is to add a
DeprecatedInfo
class to the coreentity
and use this info during theentity_platform
setup to determine whether to create the entity and raise issues. The principal advantages are:Some other potential advantages are:
DeprecatedInfo
classes that have gone past theirbreaks_in_ha_version
and flag for cleanup.The following draft PR shows a migration from the ring integration implementing it's own checking/issue raising to what a core implementation could look like.
When to raise issues
EDIT: The example raises issues based on the logic in the lutron and ring implementations. i.e. issues are only raised if the entity is referenced used in automations or scripts. Otherwise issues are not raised. If the user disables the entity it will be removed from the entity registry on the next restart.
N.B. The example has
issue_items_fn
configurable as part of theDeprecatedInfo
class. An alternative would be for this to be a non-configurable default function but for now it was a bit too complicated to check scripts and automations from within theentity_platform
module.Other considered alternatives
Do nothing
Keep the status quo of each integration implementing it's own deprecation logic.
Add helper functions but don't extend the core
entity
andentity_platform
The
async_check_create_deprecated
function being removed from the integration in the draft PR could be added tohomeassistant.helpers.deprecation
and imported and called as part of the integration logic to decide whether to create an entity:async_add_entities( RingBinarySensor(device, listen_coordinator, description) for description in BINARY_SENSOR_TYPES for device in ring_data.devices.all_devices if device.has_capability(description.capability) + and async_check_create_deprecated(hass, Platform.BINARY_SENSOR, f"{device.id}-{description.key}", description,) )
The advantage of this is that it's less intrusive as the core
entity
andentity_platform
do not need to change.The disadvantages are:
Beta Was this translation helpful? Give feedback.
All reactions