Skip to content
Merged
Changes from 5 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
15 changes: 10 additions & 5 deletions homeassistant/components/group/__init__.py
Original file line number Diff line number Diff line change
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,9 @@ 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: list[Group] = [
e for e in component.entities if isinstance(e, Group) and e.user_defined
]

if (conf := await component.async_prepare_reload()) is None:
return
Expand All @@ -254,7 +259,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(Group, component.get_entity(entity_id))
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated

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