From f237bb14caf6fcbdfd1b398310a0d71a45449a4f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 14 Feb 2023 10:38:51 -0600 Subject: [PATCH] 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 --- .strict-typing | 1 + homeassistant/components/yalexs_ble/config_flow.py | 10 ++++++---- mypy.ini | 10 ++++++++++ tests/components/yalexs_ble/test_config_flow.py | 8 +++++--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.strict-typing b/.strict-typing index 8555ee6d47a..13fd49391e9 100644 --- a/.strict-typing +++ b/.strict-typing @@ -333,6 +333,7 @@ homeassistant.components.wiz.* homeassistant.components.wled.* homeassistant.components.worldclock.* homeassistant.components.yale_smart_alarm.* +homeassistant.components.yalexs_ble.* homeassistant.components.zeroconf.* homeassistant.components.zodiac.* homeassistant.components.zone.* diff --git a/homeassistant/components/yalexs_ble/config_flow.py b/homeassistant/components/yalexs_ble/config_flow.py index 9739ca546ac..14a8f937fd3 100644 --- a/homeassistant/components/yalexs_ble/config_flow.py +++ b/homeassistant/components/yalexs_ble/config_flow.py @@ -33,7 +33,7 @@ _LOGGER = logging.getLogger(__name__) 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]: """Validate the lock and return errors if any.""" if len(key) != 32: @@ -42,7 +42,7 @@ async def async_validate_lock_or_error( bytes.fromhex(key) except ValueError: 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"} try: 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() - 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.""" errors = {} reauth_entry = self._reauth_entry @@ -205,7 +207,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) ): 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) return self.async_abort(reason="reauth_successful") diff --git a/mypy.ini b/mypy.ini index cd11c68cf82..db5df3a5b4b 100644 --- a/mypy.ini +++ b/mypy.ini @@ -3094,6 +3094,16 @@ disallow_untyped_defs = true warn_return_any = 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.*] check_untyped_defs = true disallow_incomplete_defs = true diff --git a/tests/components/yalexs_ble/test_config_flow.py b/tests/components/yalexs_ble/test_config_flow.py index b0a4dcf8d59..7c63a568acd 100644 --- a/tests/components/yalexs_ble/test_config_flow.py +++ b/tests/components/yalexs_ble/test_config_flow.py @@ -3,6 +3,7 @@ import asyncio from unittest.mock import patch from bleak import BleakError +import pytest from yalexs_ble import AuthError from homeassistant import config_entries @@ -26,7 +27,8 @@ from . import ( 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.""" with patch( "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_KEY: "2fd51b8621c6a139eaffbedcb846b60f", - CONF_SLOT: 66, + CONF_SLOT: slot, }, ) 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_ADDRESS: YALE_ACCESS_LOCK_DISCOVERY_INFO.address, CONF_KEY: "2fd51b8621c6a139eaffbedcb846b60f", - CONF_SLOT: 66, + CONF_SLOT: slot, } assert result2["result"].unique_id == YALE_ACCESS_LOCK_DISCOVERY_INFO.address assert len(mock_setup_entry.mock_calls) == 1