Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update typing 08 #48058

Merged
merged 2 commits into from Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions homeassistant/components/habitica/config_flow.py
@@ -1,6 +1,7 @@
"""Config flow for habitica integration."""
from __future__ import annotations

import logging
from typing import Dict

from aiohttp import ClientResponseError
from habitipy.aio import HabitipyAsync
Expand All @@ -25,8 +26,8 @@


async def validate_input(
hass: core.HomeAssistant, data: Dict[str, str]
) -> Dict[str, str]:
hass: core.HomeAssistant, data: dict[str, str]
) -> dict[str, str]:
"""Validate the user input allows us to connect."""

websession = async_get_clientsession(hass)
Expand Down
14 changes: 8 additions & 6 deletions homeassistant/components/hassio/__init__.py
@@ -1,9 +1,11 @@
"""Support for Hass.io."""
from __future__ import annotations

import asyncio
from datetime import timedelta
import logging
import os
from typing import Any, Dict, List, Optional
from typing import Any

import voluptuous as vol

Expand Down Expand Up @@ -236,7 +238,7 @@ async def async_set_addon_options(
@bind_hass
async def async_get_addon_discovery_info(
hass: HomeAssistantType, slug: str
) -> Optional[dict]:
) -> dict | None:
"""Return discovery data for an add-on."""
hassio = hass.data[DOMAIN]
data = await hassio.retrieve_discovery_messages()
Expand Down Expand Up @@ -545,7 +547,7 @@ async def async_unload_entry(

@callback
def async_register_addons_in_dev_reg(
entry_id: str, dev_reg: DeviceRegistry, addons: List[Dict[str, Any]]
entry_id: str, dev_reg: DeviceRegistry, addons: list[dict[str, Any]]
) -> None:
"""Register addons in the device registry."""
for addon in addons:
Expand All @@ -564,7 +566,7 @@ def async_register_addons_in_dev_reg(

@callback
def async_register_os_in_dev_reg(
entry_id: str, dev_reg: DeviceRegistry, os_dict: Dict[str, Any]
entry_id: str, dev_reg: DeviceRegistry, os_dict: dict[str, Any]
) -> None:
"""Register OS in the device registry."""
params = {
Expand All @@ -581,7 +583,7 @@ def async_register_os_in_dev_reg(

@callback
def async_remove_addons_from_dev_reg(
dev_reg: DeviceRegistry, addons: List[Dict[str, Any]]
dev_reg: DeviceRegistry, addons: list[dict[str, Any]]
) -> None:
"""Remove addons from the device registry."""
for addon_slug in addons:
Expand All @@ -607,7 +609,7 @@ def __init__(
self.dev_reg = dev_reg
self.is_hass_os = "hassos" in get_info(self.hass)

async def _async_update_data(self) -> Dict[str, Any]:
async def _async_update_data(self) -> dict[str, Any]:
"""Update data via library."""
new_data = {}
addon_data = get_supervisor_info(self.hass)
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/hassio/binary_sensor.py
@@ -1,5 +1,7 @@
"""Binary sensor platform for Hass.io addons."""
from typing import Callable, List
from __future__ import annotations

from typing import Callable

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.config_entries import ConfigEntry
Expand All @@ -14,7 +16,7 @@
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: Callable[[List[Entity], bool], None],
async_add_entities: Callable[[list[Entity], bool], None],
) -> None:
"""Binary sensor set up for Hass.io config entry."""
coordinator = hass.data[ADDONS_COORDINATOR]
Expand Down
14 changes: 8 additions & 6 deletions homeassistant/components/hassio/entity.py
@@ -1,5 +1,7 @@
"""Base for Hass.io entities."""
from typing import Any, Dict
from __future__ import annotations

from typing import Any

from homeassistant.const import ATTR_NAME
from homeassistant.helpers.update_coordinator import CoordinatorEntity
Expand All @@ -14,7 +16,7 @@ class HassioAddonEntity(CoordinatorEntity):
def __init__(
self,
coordinator: HassioDataUpdateCoordinator,
addon: Dict[str, Any],
addon: dict[str, Any],
attribute_name: str,
sensor_name: str,
) -> None:
Expand All @@ -27,7 +29,7 @@ def __init__(
super().__init__(coordinator)

@property
def addon_info(self) -> Dict[str, Any]:
def addon_info(self) -> dict[str, Any]:
"""Return add-on info."""
return self.coordinator.data[self._data_key][self.addon_slug]

Expand All @@ -47,7 +49,7 @@ def unique_id(self) -> str:
return f"{self.addon_slug}_{self.attribute_name}"

@property
def device_info(self) -> Dict[str, Any]:
def device_info(self) -> dict[str, Any]:
"""Return device specific attributes."""
return {"identifiers": {(DOMAIN, self.addon_slug)}}

Expand All @@ -68,7 +70,7 @@ def __init__(
super().__init__(coordinator)

@property
def os_info(self) -> Dict[str, Any]:
def os_info(self) -> dict[str, Any]:
"""Return OS info."""
return self.coordinator.data[self._data_key]

Expand All @@ -88,6 +90,6 @@ def unique_id(self) -> str:
return f"home_assistant_os_{self.attribute_name}"

@property
def device_info(self) -> Dict[str, Any]:
def device_info(self) -> dict[str, Any]:
"""Return device specific attributes."""
return {"identifiers": {(DOMAIN, "OS")}}
9 changes: 5 additions & 4 deletions homeassistant/components/hassio/http.py
@@ -1,9 +1,10 @@
"""HTTP Support for Hass.io."""
from __future__ import annotations

import asyncio
import logging
import os
import re
from typing import Dict, Union

import aiohttp
from aiohttp import web
Expand Down Expand Up @@ -57,7 +58,7 @@ def __init__(self, host: str, websession: aiohttp.ClientSession):

async def _handle(
self, request: web.Request, path: str
) -> Union[web.Response, web.StreamResponse]:
) -> web.Response | web.StreamResponse:
"""Route data to Hass.io."""
hass = request.app["hass"]
if _need_auth(hass, path) and not request[KEY_AUTHENTICATED]:
Expand All @@ -71,7 +72,7 @@ async def _handle(

async def _command_proxy(
self, path: str, request: web.Request
) -> Union[web.Response, web.StreamResponse]:
) -> web.Response | web.StreamResponse:
"""Return a client request with proxy origin for Hass.io supervisor.

This method is a coroutine.
Expand Down Expand Up @@ -131,7 +132,7 @@ async def _command_proxy(
raise HTTPBadGateway()


def _init_header(request: web.Request) -> Dict[str, str]:
def _init_header(request: web.Request) -> dict[str, str]:
"""Create initial header."""
headers = {
X_HASSIO: os.environ.get("HASSIO_TOKEN", ""),
Expand Down
13 changes: 6 additions & 7 deletions homeassistant/components/hassio/ingress.py
@@ -1,9 +1,10 @@
"""Hass.io Add-on ingress service."""
from __future__ import annotations

import asyncio
from ipaddress import ip_address
import logging
import os
from typing import Dict, Union

import aiohttp
from aiohttp import hdrs, web
Expand Down Expand Up @@ -46,7 +47,7 @@ def _create_url(self, token: str, path: str) -> str:

async def _handle(
self, request: web.Request, token: str, path: str
) -> Union[web.Response, web.StreamResponse, web.WebSocketResponse]:
) -> web.Response | web.StreamResponse | web.WebSocketResponse:
"""Route data to Hass.io ingress service."""
try:
# Websocket
Expand Down Expand Up @@ -114,7 +115,7 @@ async def _handle_websocket(

async def _handle_request(
self, request: web.Request, token: str, path: str
) -> Union[web.Response, web.StreamResponse]:
) -> web.Response | web.StreamResponse:
"""Ingress route for request."""
url = self._create_url(token, path)
data = await request.read()
Expand Down Expand Up @@ -159,9 +160,7 @@ async def _handle_request(
return response


def _init_header(
request: web.Request, token: str
) -> Union[CIMultiDict, Dict[str, str]]:
def _init_header(request: web.Request, token: str) -> CIMultiDict | dict[str, str]:
"""Create initial header."""
headers = {}

Expand Down Expand Up @@ -208,7 +207,7 @@ def _init_header(
return headers


def _response_header(response: aiohttp.ClientResponse) -> Dict[str, str]:
def _response_header(response: aiohttp.ClientResponse) -> dict[str, str]:
"""Create response header."""
headers = {}

Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/hassio/sensor.py
@@ -1,5 +1,7 @@
"""Sensor platform for Hass.io addons."""
from typing import Callable, List
from __future__ import annotations

from typing import Callable

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
Expand All @@ -13,7 +15,7 @@
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: Callable[[List[Entity], bool], None],
async_add_entities: Callable[[list[Entity], bool], None],
) -> None:
"""Sensor set up for Hass.io config entry."""
coordinator = hass.data[ADDONS_COORDINATOR]
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/heatmiser/climate.py
@@ -1,6 +1,7 @@
"""Support for the PRT Heatmiser themostats using the V3 protocol."""
from __future__ import annotations

import logging
from typing import List

from heatmiserV3 import connection, heatmiser
import voluptuous as vol
Expand Down Expand Up @@ -103,7 +104,7 @@ def hvac_mode(self) -> str:
return self._hvac_mode

@property
def hvac_modes(self) -> List[str]:
def hvac_modes(self) -> list[str]:
"""Return the list of available hvac operation modes.

Need to be a subset of HVAC_MODES.
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/heos/__init__.py
@@ -1,8 +1,9 @@
"""Denon HEOS Media Player."""
from __future__ import annotations

import asyncio
from datetime import timedelta
import logging
from typing import Dict

from pyheos import Heos, HeosError, const as heos_const
import voluptuous as vol
Expand Down Expand Up @@ -191,7 +192,7 @@ async def _heos_event(self, event):
# Update players
self._hass.helpers.dispatcher.async_dispatcher_send(SIGNAL_HEOS_UPDATED)

def update_ids(self, mapped_ids: Dict[int, int]):
def update_ids(self, mapped_ids: dict[int, int]):
"""Update the IDs in the device and entity registry."""
# mapped_ids contains the mapped IDs (new:old)
for new_id, old_id in mapped_ids.items():
Expand Down
16 changes: 9 additions & 7 deletions homeassistant/components/here_travel_time/sensor.py
@@ -1,7 +1,9 @@
"""Support for HERE travel time sensors."""
from __future__ import annotations

from datetime import datetime, timedelta
import logging
from typing import Callable, Dict, Optional, Union
from typing import Callable

import herepy
import voluptuous as vol
Expand Down Expand Up @@ -143,9 +145,9 @@

async def async_setup_platform(
hass: HomeAssistant,
config: Dict[str, Union[str, bool]],
config: dict[str, str | bool],
async_add_entities: Callable,
discovery_info: Optional[DiscoveryInfoType] = None,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the HERE travel time platform."""
api_key = config[CONF_API_KEY]
Expand Down Expand Up @@ -255,7 +257,7 @@ def delayed_sensor_update(event):
)

@property
def state(self) -> Optional[str]:
def state(self) -> str | None:
"""Return the state of the sensor."""
if self._here_data.traffic_mode:
if self._here_data.traffic_time is not None:
Expand All @@ -273,7 +275,7 @@ def name(self) -> str:
@property
def extra_state_attributes(
self,
) -> Optional[Dict[str, Union[None, float, str, bool]]]:
) -> dict[str, None | float | str | bool] | None:
"""Return the state attributes."""
if self._here_data.base_time is None:
return None
Expand Down Expand Up @@ -324,7 +326,7 @@ async def async_update(self) -> None:

await self.hass.async_add_executor_job(self._here_data.update)

async def _get_location_from_entity(self, entity_id: str) -> Optional[str]:
async def _get_location_from_entity(self, entity_id: str) -> str | None:
"""Get the location from the entity state or attributes."""
entity = self.hass.states.get(entity_id)

Expand Down Expand Up @@ -480,7 +482,7 @@ def update(self) -> None:
self.destination_name = waypoint[1]["mappedRoadName"]

@staticmethod
def _build_hass_attribution(source_attribution: Dict) -> Optional[str]:
def _build_hass_attribution(source_attribution: dict) -> str | None:
"""Build a hass frontend ready string out of the sourceAttribution."""
suppliers = source_attribution.get("supplier")
if suppliers is not None:
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/history/__init__.py
@@ -1,11 +1,13 @@
"""Provide pre-made queries on top of the recorder component."""
from __future__ import annotations

from collections import defaultdict
from datetime import datetime as dt, timedelta
from itertools import groupby
import json
import logging
import time
from typing import Iterable, Optional, cast
from typing import Iterable, cast

from aiohttp import web
from sqlalchemy import and_, bindparam, func, not_, or_
Expand Down Expand Up @@ -462,7 +464,7 @@ def __init__(self, filters, use_include_order):
self.use_include_order = use_include_order

async def get(
self, request: web.Request, datetime: Optional[str] = None
self, request: web.Request, datetime: str | None = None
) -> web.Response:
"""Return history over a period of time."""
datetime_ = None
Expand Down