-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Deprecate min_max and migrate to group sensor #167718
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
Draft
gjohansson-ST
wants to merge
33
commits into
dev
Choose a base branch
from
gj-20260408-02
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
564280c
Deprecate min_max and migrate to group sensor
gjohansson-ST 5bbfe69
import
gjohansson-ST 7288d19
Mods
gjohansson-ST 6e92ba2
Mods
gjohansson-ST 26d8dfb
Mods
gjohansson-ST d4fca37
Mods
gjohansson-ST 49ce8ed
Mods
gjohansson-ST f821952
Test
gjohansson-ST d25f3c6
Delete
gjohansson-ST f006283
Mods
gjohansson-ST 44b0717
Mods
gjohansson-ST 7f1846b
comments
gjohansson-ST 6d4f5a4
Mods to repair flow
gjohansson-ST d037f33
Fix config flow
gjohansson-ST 983df39
Fixes
gjohansson-ST 787929f
Mods
gjohansson-ST 46a05e4
mod
gjohansson-ST 379c0b1
Fixes
gjohansson-ST 3f69014
strings
gjohansson-ST 00e8a6c
Fix string
gjohansson-ST 9fd0f99
Fix flow
gjohansson-ST e131b21
async_config_entry_title
gjohansson-ST 5079709
Mods
gjohansson-ST 80733a2
Handle missing entity
gjohansson-ST f4bccbb
fix yaml description
gjohansson-ST d8b23df
Mods
gjohansson-ST ee9326d
Somewhat stable id
gjohansson-ST 2e1c4e0
Remove from future
gjohansson-ST fbda661
Restore options flow test
gjohansson-ST 7c6ff3f
Fix review comments
gjohansson-ST 30176c6
Remove issue on config entry removal
gjohansson-ST 9634953
Fixes
gjohansson-ST aad7b6c
docstring
gjohansson-ST File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,76 @@ | ||
| """The min_max component.""" | ||
|
|
||
| from homeassistant.config_entries import ConfigEntry | ||
| from datetime import datetime | ||
| import logging | ||
| from types import MappingProxyType | ||
|
|
||
| from homeassistant.components.group import ( | ||
| CONF_ENTITIES, | ||
| CONF_GROUP_TYPE, | ||
| CONF_HIDE_MEMBERS, | ||
| CONF_IGNORE_NON_NUMERIC, | ||
| DOMAIN as GROUP_DOMAIN, | ||
| ) | ||
| from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN | ||
| from homeassistant.config_entries import SOURCE_USER, ConfigEntry | ||
| from homeassistant.const import Platform | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import entity_registry as er | ||
| from homeassistant.helpers.event import async_call_later | ||
|
|
||
| from .const import CONF_ENTITY_IDS, CONF_ROUND_DIGITS, DOMAIN | ||
|
|
||
| PLATFORMS = [Platform.SENSOR] | ||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Set up Min/Max from a config entry.""" | ||
| await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
|
||
| # Create group config from entry options | ||
| config = dict(entry.options) | ||
| config[CONF_ENTITIES] = config.pop(CONF_ENTITY_IDS) | ||
| config.pop(CONF_ROUND_DIGITS) | ||
| config[CONF_HIDE_MEMBERS] = False | ||
| config[CONF_IGNORE_NON_NUMERIC] = False | ||
|
gjohansson-ST marked this conversation as resolved.
Outdated
|
||
| config[CONF_GROUP_TYPE] = SENSOR_DOMAIN | ||
|
|
||
| # Create new config entry for group component and remove old entry | ||
| new_config_entry = ConfigEntry( | ||
| data={}, | ||
| discovery_keys=MappingProxyType({}), | ||
| domain=GROUP_DOMAIN, | ||
| minor_version=1, | ||
| options=config, | ||
| source=SOURCE_USER, | ||
| subentries_data=[], | ||
| title=entry.title, | ||
| unique_id=None, | ||
| version=1, | ||
| ) | ||
|
gjohansson-ST marked this conversation as resolved.
gjohansson-ST marked this conversation as resolved.
|
||
| await hass.config_entries.async_add(new_config_entry) | ||
|
|
||
| # Migrate entity from old entry to new entry | ||
| entity_reg = er.async_get(hass) | ||
| if old_entity := entity_reg.async_get_entity_id( | ||
| SENSOR_DOMAIN, DOMAIN, entry.entry_id | ||
| ): | ||
| entity_reg.async_update_entity_platform( | ||
| old_entity, GROUP_DOMAIN, new_config_entry_id=new_config_entry.entry_id | ||
| ) | ||
|
gjohansson-ST marked this conversation as resolved.
Outdated
gjohansson-ST marked this conversation as resolved.
Outdated
|
||
|
|
||
| # await hass.config_entries.async_remove(entry.entry_id) | ||
|
|
||
| async def remove_old_entry(now: datetime) -> None: | ||
| """Remove the old config entry after migration.""" | ||
| await hass.config_entries.async_remove(entry.entry_id) | ||
|
|
||
| async_call_later(hass, 60, remove_old_entry) | ||
|
gjohansson-ST marked this conversation as resolved.
Outdated
|
||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
| """Unload a config entry.""" | ||
| return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
|
|
||
| return True | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| { | ||
| "group": { | ||
| "created_at": "2026-04-10T14:33:19.033744+00:00", | ||
| "data": {}, | ||
| "disabled_by": null, | ||
| "discovery_keys": {}, | ||
| "domain": "group", | ||
| "entry_id": "01KNVWZHXSVPAZD4DGFF8TN94Z", | ||
| "minor_version": 1, | ||
| "modified_at": "2026-04-10T14:33:19.033750+00:00", | ||
| "options": { | ||
| "entities": ["sensor.carbon_dioxide", "sensor.carbon_monoxide"], | ||
| "group_type": "sensor", | ||
| "hide_members": false, | ||
| "ignore_non_numeric": false, | ||
| "name": "Olle", | ||
| "round_digits": 2.0, | ||
| "type": "min" | ||
| }, | ||
| "pref_disable_new_entities": false, | ||
| "pref_disable_polling": false, | ||
| "source": "import", | ||
| "subentries": [], | ||
| "title": "Olle", | ||
| "unique_id": null, | ||
| "version": 1 | ||
| }, | ||
| "min_max": { | ||
| "created_at": "2026-04-10T14:13:58.312444+00:00", | ||
| "data": {}, | ||
| "disabled_by": null, | ||
| "discovery_keys": {}, | ||
| "domain": "min_max", | ||
| "entry_id": "01KNVVW4D8NK8ARQF8GCH7CD5A", | ||
| "minor_version": 1, | ||
| "modified_at": "2026-04-10T14:33:19.073168+00:00", | ||
| "options": { | ||
| "entity_ids": ["sensor.carbon_dioxide", "sensor.carbon_monoxide"], | ||
| "name": "Olle", | ||
| "round_digits": 2.0, | ||
| "type": "min" | ||
| }, | ||
| "pref_disable_new_entities": false, | ||
| "pref_disable_polling": false, | ||
| "source": "user", | ||
| "subentries": [], | ||
| "title": "Olle", | ||
| "unique_id": null, | ||
| "version": 2 | ||
| } | ||
| } | ||
|
gjohansson-ST marked this conversation as resolved.
Outdated
gjohansson-ST marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.