Update typing 09 (#48059)

This commit is contained in:
Marc Mueller 2021-03-18 10:02:00 +01:00 committed by GitHub
parent 2ab640aaef
commit 283b4abe67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 239 additions and 196 deletions

View file

@ -1,8 +1,10 @@
"""The Internet Printing Protocol (IPP) integration."""
from __future__ import annotations
import asyncio
from datetime import timedelta
import logging
from typing import Any, Dict
from typing import Any
from pyipp import IPP, IPPError, Printer as IPPPrinter
@ -39,7 +41,7 @@ SCAN_INTERVAL = timedelta(seconds=60)
_LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: Dict) -> bool:
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
"""Set up the IPP component."""
hass.data.setdefault(DOMAIN, {})
return True
@ -166,7 +168,7 @@ class IPPEntity(CoordinatorEntity):
return self._enabled_default
@property
def device_info(self) -> Dict[str, Any]:
def device_info(self) -> dict[str, Any]:
"""Return device information about this IPP device."""
if self._device_id is None:
return None

View file

@ -1,6 +1,8 @@
"""Config flow to configure the IPP integration."""
from __future__ import annotations
import logging
from typing import Any, Dict, Optional
from typing import Any
from pyipp import (
IPP,
@ -30,7 +32,7 @@ from .const import DOMAIN # pylint: disable=unused-import
_LOGGER = logging.getLogger(__name__)
async def validate_input(hass: HomeAssistantType, data: dict) -> Dict[str, Any]:
async def validate_input(hass: HomeAssistantType, data: dict) -> dict[str, Any]:
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
@ -61,8 +63,8 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
self.discovery_info = {}
async def async_step_user(
self, user_input: Optional[ConfigType] = None
) -> Dict[str, Any]:
self, user_input: ConfigType | None = None
) -> dict[str, Any]:
"""Handle a flow initiated by the user."""
if user_input is None:
return self._show_setup_form()
@ -98,7 +100,7 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
return self.async_create_entry(title=user_input[CONF_HOST], data=user_input)
async def async_step_zeroconf(self, discovery_info: ConfigType) -> Dict[str, Any]:
async def async_step_zeroconf(self, discovery_info: ConfigType) -> dict[str, Any]:
"""Handle zeroconf discovery."""
port = discovery_info[CONF_PORT]
zctype = discovery_info["type"]
@ -166,7 +168,7 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
async def async_step_zeroconf_confirm(
self, user_input: ConfigType = None
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Handle a confirmation flow initiated by zeroconf."""
if user_input is None:
return self.async_show_form(
@ -180,7 +182,7 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN):
data=self.discovery_info,
)
def _show_setup_form(self, errors: Optional[Dict] = None) -> Dict[str, Any]:
def _show_setup_form(self, errors: dict | None = None) -> dict[str, Any]:
"""Show the setup form to the user."""
return self.async_show_form(
step_id="user",

View file

@ -1,6 +1,8 @@
"""Support for IPP sensors."""
from __future__ import annotations
from datetime import timedelta
from typing import Any, Callable, Dict, List, Optional
from typing import Any, Callable
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_LOCATION, DEVICE_CLASS_TIMESTAMP, PERCENTAGE
@ -26,7 +28,7 @@ from .const import (
async def async_setup_entry(
hass: HomeAssistantType,
entry: ConfigEntry,
async_add_entities: Callable[[List[Entity], bool], None],
async_add_entities: Callable[[list[Entity], bool], None],
) -> None:
"""Set up IPP sensor based on a config entry."""
coordinator: IPPDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
@ -63,7 +65,7 @@ class IPPSensor(IPPEntity):
icon: str,
key: str,
name: str,
unit_of_measurement: Optional[str] = None,
unit_of_measurement: str | None = None,
) -> None:
"""Initialize IPP sensor."""
self._unit_of_measurement = unit_of_measurement
@ -117,7 +119,7 @@ class IPPMarkerSensor(IPPSensor):
)
@property
def extra_state_attributes(self) -> Optional[Dict[str, Any]]:
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes of the entity."""
return {
ATTR_MARKER_HIGH_LEVEL: self.coordinator.data.markers[
@ -132,7 +134,7 @@ class IPPMarkerSensor(IPPSensor):
}
@property
def state(self) -> Optional[int]:
def state(self) -> int | None:
"""Return the state of the sensor."""
level = self.coordinator.data.markers[self.marker_index].level
@ -160,7 +162,7 @@ class IPPPrinterSensor(IPPSensor):
)
@property
def extra_state_attributes(self) -> Optional[Dict[str, Any]]:
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes of the entity."""
return {
ATTR_INFO: self.coordinator.data.info.printer_info,
@ -202,6 +204,6 @@ class IPPUptimeSensor(IPPSensor):
return uptime.replace(microsecond=0).isoformat()
@property
def device_class(self) -> Optional[str]:
def device_class(self) -> str | None:
"""Return the class of this sensor."""
return DEVICE_CLASS_TIMESTAMP