Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions homeassistant/components/group/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections.abc import Iterable
from contextvars import ContextVar
import logging
from typing import Any, cast
from typing import Any, Union, cast

import voluptuous as vol

Expand Down Expand Up @@ -36,6 +36,7 @@
async_process_integration_platforms,
)
from homeassistant.helpers.reload import async_reload_integration_platforms
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass

# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs
Expand Down Expand Up @@ -216,10 +217,12 @@ def groups_with_entity(hass: HomeAssistant, entity_id: str) -> list[str]:
return groups


async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up all groups found defined in the configuration."""
if (component := hass.data.get(DOMAIN)) is None:
component = hass.data[DOMAIN] = EntityComponent(_LOGGER, DOMAIN, hass)
if DOMAIN not in hass.data:
hass.data[DOMAIN] = EntityComponent(_LOGGER, DOMAIN, hass)

component: EntityComponent = hass.data[DOMAIN]

hass.data[REG_KEY] = GroupIntegrationRegistry()

Expand All @@ -229,7 +232,11 @@ async def async_setup(hass, config):

async def reload_service_handler(service: ServiceCall) -> None:
"""Remove all user-defined groups and load new ones from config."""
auto = list(filter(lambda e: not e.user_defined, component.entities))
auto = [
cast(Group, e)
for e in component.entities
if not cast(Group, e).user_defined
]

if (conf := await component.async_prepare_reload()) is None:
return
Expand All @@ -254,7 +261,7 @@ async def groups_service_handler(service: ServiceCall) -> None:
"""Handle dynamic group service functions."""
object_id = service.data[ATTR_OBJECT_ID]
entity_id = f"{DOMAIN}.{object_id}"
group = component.get_entity(entity_id)
group: Group | None = cast(Union[Group, None], component.get_entity(entity_id))

# new group
if service.service == SERVICE_SET and group is None:
Expand Down