Add strict typing to yalexs_ble (#88086)

* Add strict typing to yalexs_ble

* Add strict typing to yalexs_ble

* Add strict typing to yalexs_ble
This commit is contained in:
J. Nick Koston 2023-02-14 10:38:51 -06:00 committed by GitHub
parent f4ef64a7d7
commit f237bb14ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 7 deletions

View File

@ -333,6 +333,7 @@ homeassistant.components.wiz.*
homeassistant.components.wled.* homeassistant.components.wled.*
homeassistant.components.worldclock.* homeassistant.components.worldclock.*
homeassistant.components.yale_smart_alarm.* homeassistant.components.yale_smart_alarm.*
homeassistant.components.yalexs_ble.*
homeassistant.components.zeroconf.* homeassistant.components.zeroconf.*
homeassistant.components.zodiac.* homeassistant.components.zodiac.*
homeassistant.components.zone.* homeassistant.components.zone.*

View File

@ -33,7 +33,7 @@ _LOGGER = logging.getLogger(__name__)
async def async_validate_lock_or_error( async def async_validate_lock_or_error(
local_name: str, device: BLEDevice, key: str, slot: str local_name: str, device: BLEDevice, key: str, slot: int
) -> dict[str, str]: ) -> dict[str, str]:
"""Validate the lock and return errors if any.""" """Validate the lock and return errors if any."""
if len(key) != 32: if len(key) != 32:
@ -42,7 +42,7 @@ async def async_validate_lock_or_error(
bytes.fromhex(key) bytes.fromhex(key)
except ValueError: except ValueError:
return {CONF_KEY: "invalid_key_format"} return {CONF_KEY: "invalid_key_format"}
if not isinstance(slot, int) or slot < 0 or slot > 255: if not isinstance(slot, int) or not 0 <= slot <= 255:
return {CONF_SLOT: "invalid_key_index"} return {CONF_SLOT: "invalid_key_index"}
try: try:
await PushLock(local_name, device.address, device, key, slot).validate() await PushLock(local_name, device.address, device, key, slot).validate()
@ -184,7 +184,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) )
return await self.async_step_reauth_validate() return await self.async_step_reauth_validate()
async def async_step_reauth_validate(self, user_input=None): async def async_step_reauth_validate(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle reauth and validation.""" """Handle reauth and validation."""
errors = {} errors = {}
reauth_entry = self._reauth_entry reauth_entry = self._reauth_entry
@ -205,7 +207,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
) )
): ):
self.hass.config_entries.async_update_entry( self.hass.config_entries.async_update_entry(
self._reauth_entry, data={**reauth_entry.data, **user_input} reauth_entry, data={**reauth_entry.data, **user_input}
) )
await self.hass.config_entries.async_reload(reauth_entry.entry_id) await self.hass.config_entries.async_reload(reauth_entry.entry_id)
return self.async_abort(reason="reauth_successful") return self.async_abort(reason="reauth_successful")

View File

@ -3094,6 +3094,16 @@ disallow_untyped_defs = true
warn_return_any = true warn_return_any = true
warn_unreachable = true warn_unreachable = true
[mypy-homeassistant.components.yalexs_ble.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.zeroconf.*] [mypy-homeassistant.components.zeroconf.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true

View File

@ -3,6 +3,7 @@ import asyncio
from unittest.mock import patch from unittest.mock import patch
from bleak import BleakError from bleak import BleakError
import pytest
from yalexs_ble import AuthError from yalexs_ble import AuthError
from homeassistant import config_entries from homeassistant import config_entries
@ -26,7 +27,8 @@ from . import (
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
async def test_user_step_success(hass: HomeAssistant) -> None: @pytest.mark.parametrize("slot", [0, 1, 66])
async def test_user_step_success(hass: HomeAssistant, slot: int) -> None:
"""Test user step success path.""" """Test user step success path."""
with patch( with patch(
"homeassistant.components.yalexs_ble.config_flow.async_discovered_service_info", "homeassistant.components.yalexs_ble.config_flow.async_discovered_service_info",
@ -50,7 +52,7 @@ async def test_user_step_success(hass: HomeAssistant) -> None:
{ {
CONF_ADDRESS: YALE_ACCESS_LOCK_DISCOVERY_INFO.address, CONF_ADDRESS: YALE_ACCESS_LOCK_DISCOVERY_INFO.address,
CONF_KEY: "2fd51b8621c6a139eaffbedcb846b60f", CONF_KEY: "2fd51b8621c6a139eaffbedcb846b60f",
CONF_SLOT: 66, CONF_SLOT: slot,
}, },
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -61,7 +63,7 @@ async def test_user_step_success(hass: HomeAssistant) -> None:
CONF_LOCAL_NAME: YALE_ACCESS_LOCK_DISCOVERY_INFO.name, CONF_LOCAL_NAME: YALE_ACCESS_LOCK_DISCOVERY_INFO.name,
CONF_ADDRESS: YALE_ACCESS_LOCK_DISCOVERY_INFO.address, CONF_ADDRESS: YALE_ACCESS_LOCK_DISCOVERY_INFO.address,
CONF_KEY: "2fd51b8621c6a139eaffbedcb846b60f", CONF_KEY: "2fd51b8621c6a139eaffbedcb846b60f",
CONF_SLOT: 66, CONF_SLOT: slot,
} }
assert result2["result"].unique_id == YALE_ACCESS_LOCK_DISCOVERY_INFO.address assert result2["result"].unique_id == YALE_ACCESS_LOCK_DISCOVERY_INFO.address
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1