mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Type hint additions (#26765)
This commit is contained in:
committed by
Paulus Schoutsen
parent
6a3132344c
commit
54242cd65c
@@ -7,7 +7,7 @@ import random
|
||||
import re
|
||||
from datetime import datetime
|
||||
from functools import wraps
|
||||
from typing import Iterable
|
||||
from typing import Any, Iterable
|
||||
|
||||
import jinja2
|
||||
from jinja2 import contextfilter, contextfunction
|
||||
@@ -25,13 +25,13 @@ from homeassistant.const import (
|
||||
from homeassistant.core import State, callback, split_entity_id, valid_entity_id
|
||||
from homeassistant.exceptions import TemplateError
|
||||
from homeassistant.helpers import location as loc_helper
|
||||
from homeassistant.helpers.typing import TemplateVarsType
|
||||
from homeassistant.helpers.typing import HomeAssistantType, TemplateVarsType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util import convert, dt as dt_util, location as loc_util
|
||||
from homeassistant.util.async_ import run_callback_threadsafe
|
||||
|
||||
|
||||
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
|
||||
# mypy: allow-untyped-calls, allow-untyped-defs
|
||||
# mypy: no-check-untyped-defs, no-warn-return-any
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -106,7 +106,7 @@ def extract_entities(template, variables=None):
|
||||
return MATCH_ALL
|
||||
|
||||
|
||||
def _true(arg) -> bool:
|
||||
def _true(arg: Any) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ class Template:
|
||||
"""Extract all entities for state_changed listener."""
|
||||
return extract_entities(self.template, variables)
|
||||
|
||||
def render(self, variables: TemplateVarsType = None, **kwargs):
|
||||
def render(self, variables: TemplateVarsType = None, **kwargs: Any) -> str:
|
||||
"""Render given template."""
|
||||
if variables is not None:
|
||||
kwargs.update(variables)
|
||||
@@ -201,7 +201,7 @@ class Template:
|
||||
).result()
|
||||
|
||||
@callback
|
||||
def async_render(self, variables: TemplateVarsType = None, **kwargs) -> str:
|
||||
def async_render(self, variables: TemplateVarsType = None, **kwargs: Any) -> str:
|
||||
"""Render given template.
|
||||
|
||||
This method must be run in the event loop.
|
||||
@@ -218,7 +218,7 @@ class Template:
|
||||
|
||||
@callback
|
||||
def async_render_to_info(
|
||||
self, variables: TemplateVarsType = None, **kwargs
|
||||
self, variables: TemplateVarsType = None, **kwargs: Any
|
||||
) -> RenderInfo:
|
||||
"""Render the template and collect an entity filter."""
|
||||
assert self.hass and _RENDER_INFO not in self.hass.data
|
||||
@@ -479,7 +479,7 @@ def _resolve_state(hass, entity_id_or_state):
|
||||
return None
|
||||
|
||||
|
||||
def expand(hass, *args) -> Iterable[State]:
|
||||
def expand(hass: HomeAssistantType, *args: Any) -> Iterable[State]:
|
||||
"""Expand out any groups into entity states."""
|
||||
search = list(args)
|
||||
found = {}
|
||||
@@ -635,7 +635,7 @@ def distance(hass, *args):
|
||||
)
|
||||
|
||||
|
||||
def is_state(hass, entity_id: str, state: State) -> bool:
|
||||
def is_state(hass: HomeAssistantType, entity_id: str, state: State) -> bool:
|
||||
"""Test if a state is a specific value."""
|
||||
state_obj = _get_state(hass, entity_id)
|
||||
return state_obj is not None and state_obj.state == state
|
||||
|
||||
Reference in New Issue
Block a user