Type hint additions (#26831)

* Type hint additions

* Remove optional from sidebar_icon comment

Co-Authored-By: Franck Nijhof <frenck@frenck.nl>

* Remove optional from sidebar_title comment

Co-Authored-By: Franck Nijhof <frenck@frenck.nl>

* Fix issues after rebase and mypy 0.730
This commit is contained in:
Ville SkyttäandFranck Nijhof authored and GitHub committed 2019-09-29 20:07:49 +03:00
1 parent 4f55235aa2
commit f259ff17d5
27 files changed
+184 -68

No files matched your search

+10 -4
View File
@@ -1,6 +1,7 @@
"""Provide the functionality to group entities."""
import asyncio
import logging
from typing import Any, Iterable, List, Optional, cast
import voluptuous as vol
@@ -32,9 +33,12 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.event import async_track_state_change
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import ENTITY_SERVICE_SCHEMA
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util.async_ import run_coroutine_threadsafe
# mypy: allow-untyped-calls, allow-untyped-defs
DOMAIN = "group"
ENTITY_ID_FORMAT = DOMAIN + ".{}"
@@ -143,12 +147,12 @@ def is_on(hass, entity_id):
@bind_hass
def expand_entity_ids(hass, entity_ids):
def expand_entity_ids(hass: HomeAssistantType, entity_ids: Iterable[Any]) -> List[str]:
"""Return entity_ids with group entity ids replaced by their members.
Async friendly.
"""
found_ids = []
found_ids: List[str] = []
for entity_id in entity_ids:
if not isinstance(entity_id, str):
continue
@@ -182,7 +186,9 @@ def expand_entity_ids(hass, entity_ids):
@bind_hass
def get_entity_ids(hass, entity_id, domain_filter=None):
def get_entity_ids(
hass: HomeAssistantType, entity_id: str, domain_filter: Optional[str] = None
) -> List[str]:
"""Get members of this group.
Async friendly.
@@ -194,7 +200,7 @@ def get_entity_ids(hass, entity_id, domain_filter=None):
entity_ids = group.attributes[ATTR_ENTITY_ID]
if not domain_filter:
return entity_ids
return cast(List[str], entity_ids)
domain_filter = domain_filter.lower() + "."