-
-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Expand file tree
/
Copy path__init__.py
More file actions
64 lines (52 loc) · 1.98 KB
/
Copy path__init__.py
File metadata and controls
64 lines (52 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""The min_max component."""
import logging
from types import MappingProxyType
from homeassistant.components.group import (
CONF_ENTITIES,
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 .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."""
# 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
# 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,
)
await hass.config_entries.async_add(new_config_entry)
await hass.config_entries.async_remove(entry.entry_id)
# 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(
old_entity, config_entry_id=new_config_entry.entry_id
)
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)