Skip to content

Commit f237bb1

Browse files
authored
Add strict typing to yalexs_ble (home-assistant#88086)
* Add strict typing to yalexs_ble * Add strict typing to yalexs_ble * Add strict typing to yalexs_ble
1 parent f4ef64a commit f237bb1

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

.strict-typing

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ homeassistant.components.wiz.*
333333
homeassistant.components.wled.*
334334
homeassistant.components.worldclock.*
335335
homeassistant.components.yale_smart_alarm.*
336+
homeassistant.components.yalexs_ble.*
336337
homeassistant.components.zeroconf.*
337338
homeassistant.components.zodiac.*
338339
homeassistant.components.zone.*

homeassistant/components/yalexs_ble/config_flow.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
async def async_validate_lock_or_error(
36-
local_name: str, device: BLEDevice, key: str, slot: str
36+
local_name: str, device: BLEDevice, key: str, slot: int
3737
) -> dict[str, str]:
3838
"""Validate the lock and return errors if any."""
3939
if len(key) != 32:
@@ -42,7 +42,7 @@ async def async_validate_lock_or_error(
4242
bytes.fromhex(key)
4343
except ValueError:
4444
return {CONF_KEY: "invalid_key_format"}
45-
if not isinstance(slot, int) or slot < 0 or slot > 255:
45+
if not isinstance(slot, int) or not 0 <= slot <= 255:
4646
return {CONF_SLOT: "invalid_key_index"}
4747
try:
4848
await PushLock(local_name, device.address, device, key, slot).validate()
@@ -184,7 +184,9 @@ async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> FlowResult:
184184
)
185185
return await self.async_step_reauth_validate()
186186

187-
async def async_step_reauth_validate(self, user_input=None):
187+
async def async_step_reauth_validate(
188+
self, user_input: dict[str, Any] | None = None
189+
) -> FlowResult:
188190
"""Handle reauth and validation."""
189191
errors = {}
190192
reauth_entry = self._reauth_entry
@@ -205,7 +207,7 @@ async def async_step_reauth_validate(self, user_input=None):
205207
)
206208
):
207209
self.hass.config_entries.async_update_entry(
208-
self._reauth_entry, data={**reauth_entry.data, **user_input}
210+
reauth_entry, data={**reauth_entry.data, **user_input}
209211
)
210212
await self.hass.config_entries.async_reload(reauth_entry.entry_id)
211213
return self.async_abort(reason="reauth_successful")

mypy.ini

+10
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,16 @@ disallow_untyped_defs = true
30943094
warn_return_any = true
30953095
warn_unreachable = true
30963096

3097+
[mypy-homeassistant.components.yalexs_ble.*]
3098+
check_untyped_defs = true
3099+
disallow_incomplete_defs = true
3100+
disallow_subclassing_any = true
3101+
disallow_untyped_calls = true
3102+
disallow_untyped_decorators = true
3103+
disallow_untyped_defs = true
3104+
warn_return_any = true
3105+
warn_unreachable = true
3106+
30973107
[mypy-homeassistant.components.zeroconf.*]
30983108
check_untyped_defs = true
30993109
disallow_incomplete_defs = true

tests/components/yalexs_ble/test_config_flow.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest.mock import patch
44

55
from bleak import BleakError
6+
import pytest
67
from yalexs_ble import AuthError
78

89
from homeassistant import config_entries
@@ -26,7 +27,8 @@
2627
from tests.common import MockConfigEntry
2728

2829

29-
async def test_user_step_success(hass: HomeAssistant) -> None:
30+
@pytest.mark.parametrize("slot", [0, 1, 66])
31+
async def test_user_step_success(hass: HomeAssistant, slot: int) -> None:
3032
"""Test user step success path."""
3133
with patch(
3234
"homeassistant.components.yalexs_ble.config_flow.async_discovered_service_info",
@@ -50,7 +52,7 @@ async def test_user_step_success(hass: HomeAssistant) -> None:
5052
{
5153
CONF_ADDRESS: YALE_ACCESS_LOCK_DISCOVERY_INFO.address,
5254
CONF_KEY: "2fd51b8621c6a139eaffbedcb846b60f",
53-
CONF_SLOT: 66,
55+
CONF_SLOT: slot,
5456
},
5557
)
5658
await hass.async_block_till_done()
@@ -61,7 +63,7 @@ async def test_user_step_success(hass: HomeAssistant) -> None:
6163
CONF_LOCAL_NAME: YALE_ACCESS_LOCK_DISCOVERY_INFO.name,
6264
CONF_ADDRESS: YALE_ACCESS_LOCK_DISCOVERY_INFO.address,
6365
CONF_KEY: "2fd51b8621c6a139eaffbedcb846b60f",
64-
CONF_SLOT: 66,
66+
CONF_SLOT: slot,
6567
}
6668
assert result2["result"].unique_id == YALE_ACCESS_LOCK_DISCOVERY_INFO.address
6769
assert len(mock_setup_entry.mock_calls) == 1

0 commit comments

Comments
 (0)