mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Improve annotation styling (#118032)
This commit is contained in:
parent
2308ff2cbf
commit
dd22ee3dac
@ -27,7 +27,7 @@ class HomeAssistantTCPSite(web.BaseSite):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
runner: web.BaseRunner,
|
runner: web.BaseRunner,
|
||||||
host: None | str | list[str],
|
host: str | list[str] | None,
|
||||||
port: int,
|
port: int,
|
||||||
*,
|
*,
|
||||||
ssl_context: SSLContext | None = None,
|
ssl_context: SSLContext | None = None,
|
||||||
|
@ -414,7 +414,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
async def handle_webhook(
|
async def handle_webhook(
|
||||||
hass: HomeAssistant, webhook_id: str, request: Request
|
hass: HomeAssistant, webhook_id: str, request: Request
|
||||||
) -> None | Response:
|
) -> Response | None:
|
||||||
"""Handle webhook callback."""
|
"""Handle webhook callback."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -110,7 +110,7 @@ def setup_mysensors_platform(
|
|||||||
device_class: type[MySensorsChildEntity]
|
device_class: type[MySensorsChildEntity]
|
||||||
| Mapping[SensorType, type[MySensorsChildEntity]],
|
| Mapping[SensorType, type[MySensorsChildEntity]],
|
||||||
device_args: (
|
device_args: (
|
||||||
None | tuple
|
tuple | None
|
||||||
) = None, # extra arguments that will be given to the entity constructor
|
) = None, # extra arguments that will be given to the entity constructor
|
||||||
async_add_entities: Callable | None = None,
|
async_add_entities: Callable | None = None,
|
||||||
) -> list[MySensorsChildEntity] | None:
|
) -> list[MySensorsChildEntity] | None:
|
||||||
|
@ -85,7 +85,7 @@ def _reset_enabled_adapters(adapters: list[Adapter]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _ifaddr_adapter_to_ha(
|
def _ifaddr_adapter_to_ha(
|
||||||
adapter: ifaddr.Adapter, next_hop_address: None | IPv4Address | IPv6Address
|
adapter: ifaddr.Adapter, next_hop_address: IPv4Address | IPv6Address | None
|
||||||
) -> Adapter:
|
) -> Adapter:
|
||||||
"""Convert an ifaddr adapter to ha."""
|
"""Convert an ifaddr adapter to ha."""
|
||||||
ip_v4s: list[IPv4ConfiguredAddress] = []
|
ip_v4s: list[IPv4ConfiguredAddress] = []
|
||||||
|
@ -113,7 +113,7 @@ class NibeClimateEntity(CoordinatorEntity[Coordinator], ClimateEntity):
|
|||||||
|
|
||||||
self._coil_current = _get(climate.current)
|
self._coil_current = _get(climate.current)
|
||||||
self._coil_setpoint_heat = _get(climate.setpoint_heat)
|
self._coil_setpoint_heat = _get(climate.setpoint_heat)
|
||||||
self._coil_setpoint_cool: None | Coil
|
self._coil_setpoint_cool: Coil | None
|
||||||
try:
|
try:
|
||||||
self._coil_setpoint_cool = _get(climate.setpoint_cool)
|
self._coil_setpoint_cool = _get(climate.setpoint_cool)
|
||||||
except CoilNotFoundException:
|
except CoilNotFoundException:
|
||||||
|
@ -76,7 +76,7 @@ async def handle_add_product(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def product_search(api_client: PicnicAPI, product_name: str | None) -> None | str:
|
def product_search(api_client: PicnicAPI, product_name: str | None) -> str | None:
|
||||||
"""Query the api client for the product name."""
|
"""Query the api client for the product name."""
|
||||||
if product_name is None:
|
if product_name is None:
|
||||||
return None
|
return None
|
||||||
|
@ -83,7 +83,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
async def _can_use_icmp_lib_with_privilege() -> None | bool:
|
async def _can_use_icmp_lib_with_privilege() -> bool | None:
|
||||||
"""Verify we can create a raw socket."""
|
"""Verify we can create a raw socket."""
|
||||||
try:
|
try:
|
||||||
await async_ping("127.0.0.1", count=0, timeout=0, privileged=True)
|
await async_ping("127.0.0.1", count=0, timeout=0, privileged=True)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""A pool for sqlite connections."""
|
"""A pool for sqlite connections."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
@ -51,7 +53,7 @@ class RecorderPool(SingletonThreadPool, NullPool):
|
|||||||
self.recorder_and_worker_thread_ids = recorder_and_worker_thread_ids
|
self.recorder_and_worker_thread_ids = recorder_and_worker_thread_ids
|
||||||
SingletonThreadPool.__init__(self, creator, **kw)
|
SingletonThreadPool.__init__(self, creator, **kw)
|
||||||
|
|
||||||
def recreate(self) -> "RecorderPool":
|
def recreate(self) -> RecorderPool:
|
||||||
"""Recreate the pool."""
|
"""Recreate the pool."""
|
||||||
self.logger.info("Pool recreating")
|
self.logger.info("Pool recreating")
|
||||||
return self.__class__(
|
return self.__class__(
|
||||||
|
@ -44,7 +44,7 @@ DURATION_SECONDS = "duration_in_s"
|
|||||||
POSITION_SECONDS = "position_in_s"
|
POSITION_SECONDS = "position_in_s"
|
||||||
|
|
||||||
|
|
||||||
def _timespan_secs(timespan: str | None) -> None | int:
|
def _timespan_secs(timespan: str | None) -> int | None:
|
||||||
"""Parse a time-span into number of seconds."""
|
"""Parse a time-span into number of seconds."""
|
||||||
if timespan in UNAVAILABLE_VALUES:
|
if timespan in UNAVAILABLE_VALUES:
|
||||||
return None
|
return None
|
||||||
|
@ -148,7 +148,7 @@ def _format_err(name: str, *args: Any) -> str:
|
|||||||
async def async_register_callback(
|
async def async_register_callback(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
callback: Callable[[SsdpServiceInfo, SsdpChange], Coroutine[Any, Any, None] | None],
|
callback: Callable[[SsdpServiceInfo, SsdpChange], Coroutine[Any, Any, None] | None],
|
||||||
match_dict: None | dict[str, str] = None,
|
match_dict: dict[str, str] | None = None,
|
||||||
) -> Callable[[], None]:
|
) -> Callable[[], None]:
|
||||||
"""Register to receive a callback on ssdp broadcast.
|
"""Register to receive a callback on ssdp broadcast.
|
||||||
|
|
||||||
@ -317,7 +317,7 @@ class Scanner:
|
|||||||
return list(self._device_tracker.devices.values())
|
return list(self._device_tracker.devices.values())
|
||||||
|
|
||||||
async def async_register_callback(
|
async def async_register_callback(
|
||||||
self, callback: SsdpHassJobCallback, match_dict: None | dict[str, str] = None
|
self, callback: SsdpHassJobCallback, match_dict: dict[str, str] | None = None
|
||||||
) -> Callable[[], None]:
|
) -> Callable[[], None]:
|
||||||
"""Register a callback."""
|
"""Register a callback."""
|
||||||
if match_dict is None:
|
if match_dict is None:
|
||||||
|
@ -205,7 +205,7 @@ class SubaruSensor(
|
|||||||
self._attr_unique_id = f"{self.vin}_{description.key}"
|
self._attr_unique_id = f"{self.vin}_{description.key}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> None | int | float:
|
def native_value(self) -> int | float | None:
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
vehicle_data = self.coordinator.data[self.vin]
|
vehicle_data = self.coordinator.data[self.vin]
|
||||||
current_value = vehicle_data[VEHICLE_STATUS].get(self.entity_description.key)
|
current_value = vehicle_data[VEHICLE_STATUS].get(self.entity_description.key)
|
||||||
|
@ -483,7 +483,7 @@ class AutoOffExtraStoredData(ExtraStoredData):
|
|||||||
|
|
||||||
def as_dict(self) -> dict[str, Any]:
|
def as_dict(self) -> dict[str, Any]:
|
||||||
"""Return a dict representation of additional data."""
|
"""Return a dict representation of additional data."""
|
||||||
auto_off_time: datetime | None | dict[str, str] = self.auto_off_time
|
auto_off_time: datetime | dict[str, str] | None = self.auto_off_time
|
||||||
if isinstance(auto_off_time, datetime):
|
if isinstance(auto_off_time, datetime):
|
||||||
auto_off_time = {
|
auto_off_time = {
|
||||||
"__type": str(type(auto_off_time)),
|
"__type": str(type(auto_off_time)),
|
||||||
|
@ -257,7 +257,7 @@ class SensorTemplate(TemplateEntity, SensorEntity):
|
|||||||
self._attr_device_class = config.get(CONF_DEVICE_CLASS)
|
self._attr_device_class = config.get(CONF_DEVICE_CLASS)
|
||||||
self._attr_state_class = config.get(CONF_STATE_CLASS)
|
self._attr_state_class = config.get(CONF_STATE_CLASS)
|
||||||
self._template: template.Template = config[CONF_STATE]
|
self._template: template.Template = config[CONF_STATE]
|
||||||
self._attr_last_reset_template: None | template.Template = config.get(
|
self._attr_last_reset_template: template.Template | None = config.get(
|
||||||
ATTR_LAST_RESET
|
ATTR_LAST_RESET
|
||||||
)
|
)
|
||||||
if (object_id := config.get(CONF_OBJECT_ID)) is not None:
|
if (object_id := config.get(CONF_OBJECT_ID)) is not None:
|
||||||
|
@ -189,7 +189,7 @@ class _TemplateAttribute:
|
|||||||
self,
|
self,
|
||||||
event: Event[EventStateChangedData] | None,
|
event: Event[EventStateChangedData] | None,
|
||||||
template: Template,
|
template: Template,
|
||||||
last_result: str | None | TemplateError,
|
last_result: str | TemplateError | None,
|
||||||
result: str | TemplateError,
|
result: str | TemplateError,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle a template result event callback."""
|
"""Handle a template result event callback."""
|
||||||
|
@ -342,8 +342,8 @@ class TibberSensor(SensorEntity):
|
|||||||
self._home_name = tibber_home.info["viewer"]["home"]["address"].get(
|
self._home_name = tibber_home.info["viewer"]["home"]["address"].get(
|
||||||
"address1", ""
|
"address1", ""
|
||||||
)
|
)
|
||||||
self._device_name: None | str = None
|
self._device_name: str | None = None
|
||||||
self._model: None | str = None
|
self._model: str | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
|
@ -352,7 +352,7 @@ async def async_not_from_config(
|
|||||||
|
|
||||||
def numeric_state(
|
def numeric_state(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity: None | str | State,
|
entity: str | State | None,
|
||||||
below: float | str | None = None,
|
below: float | str | None = None,
|
||||||
above: float | str | None = None,
|
above: float | str | None = None,
|
||||||
value_template: Template | None = None,
|
value_template: Template | None = None,
|
||||||
@ -373,7 +373,7 @@ def numeric_state(
|
|||||||
|
|
||||||
def async_numeric_state(
|
def async_numeric_state(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity: None | str | State,
|
entity: str | State | None,
|
||||||
below: float | str | None = None,
|
below: float | str | None = None,
|
||||||
above: float | str | None = None,
|
above: float | str | None = None,
|
||||||
value_template: Template | None = None,
|
value_template: Template | None = None,
|
||||||
@ -545,7 +545,7 @@ def async_numeric_state_from_config(config: ConfigType) -> ConditionCheckerType:
|
|||||||
|
|
||||||
def state(
|
def state(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity: None | str | State,
|
entity: str | State | None,
|
||||||
req_state: Any,
|
req_state: Any,
|
||||||
for_period: timedelta | None = None,
|
for_period: timedelta | None = None,
|
||||||
attribute: str | None = None,
|
attribute: str | None = None,
|
||||||
@ -803,7 +803,7 @@ def time(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
before: dt_time | str | None = None,
|
before: dt_time | str | None = None,
|
||||||
after: dt_time | str | None = None,
|
after: dt_time | str | None = None,
|
||||||
weekday: None | str | Container[str] = None,
|
weekday: str | Container[str] | None = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Test if local time condition matches.
|
"""Test if local time condition matches.
|
||||||
|
|
||||||
@ -902,8 +902,8 @@ def time_from_config(config: ConfigType) -> ConditionCheckerType:
|
|||||||
|
|
||||||
def zone(
|
def zone(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
zone_ent: None | str | State,
|
zone_ent: str | State | None,
|
||||||
entity: None | str | State,
|
entity: str | State | None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Test if zone-condition matches.
|
"""Test if zone-condition matches.
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ def _format_err[*_Ts](
|
|||||||
|
|
||||||
def _generate_job[*_Ts](
|
def _generate_job[*_Ts](
|
||||||
signal: SignalType[*_Ts] | str, target: Callable[[*_Ts], Any] | Callable[..., Any]
|
signal: SignalType[*_Ts] | str, target: Callable[[*_Ts], Any] | Callable[..., Any]
|
||||||
) -> HassJob[..., None | Coroutine[Any, Any, None]]:
|
) -> HassJob[..., Coroutine[Any, Any, None] | None]:
|
||||||
"""Generate a HassJob for a signal and target."""
|
"""Generate a HassJob for a signal and target."""
|
||||||
job_type = get_hassjob_callable_job_type(target)
|
job_type = get_hassjob_callable_job_type(target)
|
||||||
return HassJob(
|
return HassJob(
|
||||||
|
@ -201,8 +201,8 @@ def async_track_state_change(
|
|||||||
action: Callable[
|
action: Callable[
|
||||||
[str, State | None, State | None], Coroutine[Any, Any, None] | None
|
[str, State | None, State | None], Coroutine[Any, Any, None] | None
|
||||||
],
|
],
|
||||||
from_state: None | str | Iterable[str] = None,
|
from_state: str | Iterable[str] | None = None,
|
||||||
to_state: None | str | Iterable[str] = None,
|
to_state: str | Iterable[str] | None = None,
|
||||||
) -> CALLBACK_TYPE:
|
) -> CALLBACK_TYPE:
|
||||||
"""Track specific state changes.
|
"""Track specific state changes.
|
||||||
|
|
||||||
@ -1866,7 +1866,7 @@ track_time_change = threaded_listener_factory(async_track_time_change)
|
|||||||
|
|
||||||
|
|
||||||
def process_state_match(
|
def process_state_match(
|
||||||
parameter: None | str | Iterable[str], invert: bool = False
|
parameter: str | Iterable[str] | None, invert: bool = False
|
||||||
) -> Callable[[str | None], bool]:
|
) -> Callable[[str | None], bool]:
|
||||||
"""Convert parameter to function that matches input against parameter."""
|
"""Convert parameter to function that matches input against parameter."""
|
||||||
if parameter is None or parameter == MATCH_ALL:
|
if parameter is None or parameter == MATCH_ALL:
|
||||||
|
@ -833,7 +833,7 @@ def async_set_service_schema(
|
|||||||
def _get_permissible_entity_candidates(
|
def _get_permissible_entity_candidates(
|
||||||
call: ServiceCall,
|
call: ServiceCall,
|
||||||
entities: dict[str, Entity],
|
entities: dict[str, Entity],
|
||||||
entity_perms: None | (Callable[[str, str], bool]),
|
entity_perms: Callable[[str, str], bool] | None,
|
||||||
target_all_entities: bool,
|
target_all_entities: bool,
|
||||||
all_referenced: set[str] | None,
|
all_referenced: set[str] | None,
|
||||||
) -> list[Entity]:
|
) -> list[Entity]:
|
||||||
@ -889,7 +889,7 @@ async def entity_service_call(
|
|||||||
|
|
||||||
Calls all platforms simultaneously.
|
Calls all platforms simultaneously.
|
||||||
"""
|
"""
|
||||||
entity_perms: None | (Callable[[str, str], bool]) = None
|
entity_perms: Callable[[str, str], bool] | None = None
|
||||||
return_response = call.return_response
|
return_response = call.return_response
|
||||||
|
|
||||||
if call.context.user_id:
|
if call.context.user_id:
|
||||||
|
@ -36,7 +36,7 @@ def _async_at_core_state(
|
|||||||
hass.async_run_hass_job(at_start_job, hass)
|
hass.async_run_hass_job(at_start_job, hass)
|
||||||
return lambda: None
|
return lambda: None
|
||||||
|
|
||||||
unsub: None | CALLBACK_TYPE = None
|
unsub: CALLBACK_TYPE | None = None
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _matched_event(event: Event) -> None:
|
def _matched_event(event: Event) -> None:
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""Common fixtures for Anova."""
|
"""Common fixtures for Anova."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import json
|
import json
|
||||||
@ -40,7 +42,7 @@ class MockedAnovaWebsocketStream:
|
|||||||
"""Initialize a Anova Websocket Stream that can be manipulated for tests."""
|
"""Initialize a Anova Websocket Stream that can be manipulated for tests."""
|
||||||
self.messages = messages
|
self.messages = messages
|
||||||
|
|
||||||
def __aiter__(self) -> "MockedAnovaWebsocketStream":
|
def __aiter__(self) -> MockedAnovaWebsocketStream:
|
||||||
"""Handle async iteration."""
|
"""Handle async iteration."""
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ async def test_update_device(
|
|||||||
client: MockHAClientWebSocket,
|
client: MockHAClientWebSocket,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
payload_key: str,
|
payload_key: str,
|
||||||
payload_value: str | None | dr.DeviceEntryDisabler,
|
payload_value: str | dr.DeviceEntryDisabler | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test update entry."""
|
"""Test update entry."""
|
||||||
entry = MockConfigEntry(title=None)
|
entry = MockConfigEntry(title=None)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""Tests for the Ruckus Unleashed integration."""
|
"""Tests for the Ruckus Unleashed integration."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from aioruckus import AjaxSession, RuckusAjaxApi
|
from aioruckus import AjaxSession, RuckusAjaxApi
|
||||||
@ -181,7 +183,7 @@ class RuckusAjaxApiPatchContext:
|
|||||||
|
|
||||||
def _patched_async_create(
|
def _patched_async_create(
|
||||||
host: str, username: str, password: str
|
host: str, username: str, password: str
|
||||||
) -> "AjaxSession":
|
) -> AjaxSession:
|
||||||
return AjaxSession(None, host, username, password)
|
return AjaxSession(None, host, username, password)
|
||||||
|
|
||||||
self.patchers.append(
|
self.patchers.append(
|
||||||
|
@ -81,10 +81,10 @@ class MockApiResponseKey(str, Enum):
|
|||||||
|
|
||||||
def mock_uptimerobot_api_response(
|
def mock_uptimerobot_api_response(
|
||||||
data: dict[str, Any]
|
data: dict[str, Any]
|
||||||
| None
|
|
||||||
| list[UptimeRobotMonitor]
|
| list[UptimeRobotMonitor]
|
||||||
| UptimeRobotAccount
|
| UptimeRobotAccount
|
||||||
| UptimeRobotApiError = None,
|
| UptimeRobotApiError
|
||||||
|
| None = None,
|
||||||
status: APIStatus = APIStatus.OK,
|
status: APIStatus = APIStatus.OK,
|
||||||
key: MockApiResponseKey = MockApiResponseKey.MONITORS,
|
key: MockApiResponseKey = MockApiResponseKey.MONITORS,
|
||||||
) -> UptimeRobotApiResponse:
|
) -> UptimeRobotApiResponse:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user