Update typing 10 (#48071)
This commit is contained in:
parent
00dca88024
commit
25a13d1554
73 changed files with 412 additions and 333 deletions
|
@ -1,10 +1,12 @@
|
|||
"""Handle MySensors gateways."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections import defaultdict
|
||||
import logging
|
||||
import socket
|
||||
import sys
|
||||
from typing import Any, Callable, Coroutine, Dict, Optional
|
||||
from typing import Any, Callable, Coroutine
|
||||
|
||||
import async_timeout
|
||||
from mysensors import BaseAsyncGateway, Message, Sensor, mysensors
|
||||
|
@ -63,7 +65,7 @@ def is_socket_address(value):
|
|||
raise vol.Invalid("Device is not a valid domain name or ip address") from err
|
||||
|
||||
|
||||
async def try_connect(hass: HomeAssistantType, user_input: Dict[str, str]) -> bool:
|
||||
async def try_connect(hass: HomeAssistantType, user_input: dict[str, str]) -> bool:
|
||||
"""Try to connect to a gateway and report if it worked."""
|
||||
if user_input[CONF_DEVICE] == MQTT_COMPONENT:
|
||||
return True # dont validate mqtt. mqtt gateways dont send ready messages :(
|
||||
|
@ -73,7 +75,7 @@ async def try_connect(hass: HomeAssistantType, user_input: Dict[str, str]) -> bo
|
|||
def on_conn_made(_: BaseAsyncGateway) -> None:
|
||||
gateway_ready.set()
|
||||
|
||||
gateway: Optional[BaseAsyncGateway] = await _get_gateway(
|
||||
gateway: BaseAsyncGateway | None = await _get_gateway(
|
||||
hass,
|
||||
device=user_input[CONF_DEVICE],
|
||||
version=user_input[CONF_VERSION],
|
||||
|
@ -110,7 +112,7 @@ async def try_connect(hass: HomeAssistantType, user_input: Dict[str, str]) -> bo
|
|||
|
||||
def get_mysensors_gateway(
|
||||
hass: HomeAssistantType, gateway_id: GatewayId
|
||||
) -> Optional[BaseAsyncGateway]:
|
||||
) -> BaseAsyncGateway | None:
|
||||
"""Return the Gateway for a given GatewayId."""
|
||||
if MYSENSORS_GATEWAYS not in hass.data[DOMAIN]:
|
||||
hass.data[DOMAIN][MYSENSORS_GATEWAYS] = {}
|
||||
|
@ -120,7 +122,7 @@ def get_mysensors_gateway(
|
|||
|
||||
async def setup_gateway(
|
||||
hass: HomeAssistantType, entry: ConfigEntry
|
||||
) -> Optional[BaseAsyncGateway]:
|
||||
) -> BaseAsyncGateway | None:
|
||||
"""Set up the Gateway for the given ConfigEntry."""
|
||||
|
||||
ready_gateway = await _get_gateway(
|
||||
|
@ -145,14 +147,14 @@ async def _get_gateway(
|
|||
device: str,
|
||||
version: str,
|
||||
event_callback: Callable[[Message], None],
|
||||
persistence_file: Optional[str] = None,
|
||||
baud_rate: Optional[int] = None,
|
||||
tcp_port: Optional[int] = None,
|
||||
topic_in_prefix: Optional[str] = None,
|
||||
topic_out_prefix: Optional[str] = None,
|
||||
persistence_file: str | None = None,
|
||||
baud_rate: int | None = None,
|
||||
tcp_port: int | None = None,
|
||||
topic_in_prefix: str | None = None,
|
||||
topic_out_prefix: str | None = None,
|
||||
retain: bool = False,
|
||||
persistence: bool = True, # old persistence option has been deprecated. kwarg is here so we can run try_connect() without persistence
|
||||
) -> Optional[BaseAsyncGateway]:
|
||||
) -> BaseAsyncGateway | None:
|
||||
"""Return gateway after setup of the gateway."""
|
||||
|
||||
if persistence_file is not None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue