Add strict typing to modem_callerid (#57683)

This commit is contained in:
Robert Hillis 2021-10-22 16:04:06 -04:00 committed by GitHub
parent f1091b80a7
commit 23710d1496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View File

@ -70,6 +70,7 @@ homeassistant.components.lookin.*
homeassistant.components.mailbox.* homeassistant.components.mailbox.*
homeassistant.components.media_player.* homeassistant.components.media_player.*
homeassistant.components.modbus.* homeassistant.components.modbus.*
homeassistant.components.modem_callerid.*
homeassistant.components.mysensors.* homeassistant.components.mysensors.*
homeassistant.components.nam.* homeassistant.components.nam.*
homeassistant.components.nanoleaf.* homeassistant.components.nanoleaf.*

View File

@ -6,6 +6,7 @@ from typing import Any
from phone_modem import DEFAULT_PORT, PhoneModem from phone_modem import DEFAULT_PORT, PhoneModem
import serial.tools.list_ports import serial.tools.list_ports
from serial.tools.list_ports_common import ListPortInfo
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
@ -20,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema({"name": str, "device": str}) DATA_SCHEMA = vol.Schema({"name": str, "device": str})
def _generate_unique_id(port: Any) -> str: def _generate_unique_id(port: ListPortInfo) -> str:
"""Generate unique id from usb attributes.""" """Generate unique id from usb attributes."""
return f"{port.vid}:{port.pid}_{port.serial_number}_{port.manufacturer}_{port.description}" return f"{port.vid}:{port.pid}_{port.serial_number}_{port.manufacturer}_{port.description}"

View File

@ -63,7 +63,7 @@ async def async_setup_entry(
] ]
) )
async def _async_on_hass_stop(self) -> None: async def _async_on_hass_stop() -> None:
"""HA is shutting down, close modem port.""" """HA is shutting down, close modem port."""
if hass.data[DOMAIN][entry.entry_id][DATA_KEY_API]: if hass.data[DOMAIN][entry.entry_id][DATA_KEY_API]:
await hass.data[DOMAIN][entry.entry_id][DATA_KEY_API].close() await hass.data[DOMAIN][entry.entry_id][DATA_KEY_API].close()
@ -104,7 +104,7 @@ class ModemCalleridSensor(SensorEntity):
await super().async_added_to_hass() await super().async_added_to_hass()
@callback @callback
def _async_incoming_call(self, new_state) -> None: def _async_incoming_call(self, new_state: str) -> None:
"""Handle new states.""" """Handle new states."""
self._attr_extra_state_attributes = {} self._attr_extra_state_attributes = {}
if self.api.cid_name: if self.api.cid_name:

View File

@ -781,6 +781,17 @@ no_implicit_optional = true
warn_return_any = true warn_return_any = true
warn_unreachable = true warn_unreachable = true
[mypy-homeassistant.components.modem_callerid.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.mysensors.*] [mypy-homeassistant.components.mysensors.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true