Add type hints to google_assistant (#62748)
* Add type hints to google_assistant * Fix pylint * Adjust type hint * Fix black * Revert changes to smart_home Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
d0c4f0fec4
commit
ad7a0d799d
2 changed files with 17 additions and 5 deletions
|
@ -46,7 +46,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def _get_entity_and_device(
|
async def _get_entity_and_device(
|
||||||
hass, entity_id
|
hass: HomeAssistant, entity_id: str
|
||||||
) -> tuple[RegistryEntry, DeviceEntry] | None:
|
) -> tuple[RegistryEntry, DeviceEntry] | None:
|
||||||
"""Fetch the entity and device entries for a entity_id."""
|
"""Fetch the entity and device entries for a entity_id."""
|
||||||
dev_reg, ent_reg = await gather(
|
dev_reg, ent_reg = await gather(
|
||||||
|
@ -60,7 +60,11 @@ async def _get_entity_and_device(
|
||||||
return entity_entry, device_entry
|
return entity_entry, device_entry
|
||||||
|
|
||||||
|
|
||||||
async def _get_area(hass, entity_entry, device_entry) -> AreaEntry | None:
|
async def _get_area(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entity_entry: RegistryEntry | None,
|
||||||
|
device_entry: DeviceEntry | None,
|
||||||
|
) -> AreaEntry | None:
|
||||||
"""Calculate the area for an entity."""
|
"""Calculate the area for an entity."""
|
||||||
if entity_entry and entity_entry.area_id:
|
if entity_entry and entity_entry.area_id:
|
||||||
area_id = entity_entry.area_id
|
area_id = entity_entry.area_id
|
||||||
|
@ -73,7 +77,7 @@ async def _get_area(hass, entity_entry, device_entry) -> AreaEntry | None:
|
||||||
return area_reg.areas.get(area_id)
|
return area_reg.areas.get(area_id)
|
||||||
|
|
||||||
|
|
||||||
async def _get_device_info(device_entry) -> dict[str, str] | None:
|
async def _get_device_info(device_entry: DeviceEntry | None) -> dict[str, str] | None:
|
||||||
"""Retrieve the device info for a device."""
|
"""Retrieve the device info for a device."""
|
||||||
if not device_entry:
|
if not device_entry:
|
||||||
return None
|
return None
|
||||||
|
@ -593,7 +597,9 @@ def deep_update(target, source):
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_get_entities(hass, config) -> list[GoogleEntity]:
|
def async_get_entities(
|
||||||
|
hass: HomeAssistant, config: AbstractConfig
|
||||||
|
) -> list[GoogleEntity]:
|
||||||
"""Return all entities that are supported by Google."""
|
"""Return all entities that are supported by Google."""
|
||||||
entities = []
|
entities = []
|
||||||
for state in hass.states.async_all():
|
for state in hass.states.async_all():
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
"""Support for Google Actions Smart Home Control."""
|
"""Support for Google Actions Smart Home Control."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from aiohttp import ClientError, ClientResponseError
|
from aiohttp import ClientError, ClientResponseError
|
||||||
|
@ -12,6 +15,7 @@ import jwt
|
||||||
# Typing imports
|
# Typing imports
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES, ENTITY_CATEGORIES
|
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES, ENTITY_CATEGORIES
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
@ -52,7 +56,9 @@ def _get_homegraph_jwt(time, iss, key):
|
||||||
return jwt.encode(jwt_raw, key, algorithm="RS256")
|
return jwt.encode(jwt_raw, key, algorithm="RS256")
|
||||||
|
|
||||||
|
|
||||||
async def _get_homegraph_token(hass, jwt_signed):
|
async def _get_homegraph_token(
|
||||||
|
hass: HomeAssistant, jwt_signed: str
|
||||||
|
) -> dict[str, Any] | list[str, Any] | Any:
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {jwt_signed}",
|
"Authorization": f"Bearer {jwt_signed}",
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue