Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Nov 13, 2024
1 parent b9adea5 commit 5de8dd6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions custom_components/sector/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING

from homeassistant.components.alarm_control_panel import (
AlarmControlPanelEntity,
Expand Down Expand Up @@ -79,6 +80,8 @@ def alarm_state(self) -> AlarmControlPanelState | None:

async def async_alarm_arm_away(self, code: str | None = None) -> None:
"""Send arm away command."""
if TYPE_CHECKING:
assert code is not None
if not self._is_valid_code(code):
raise ServiceValidationError("Invalid code length")
_LOGGER.debug("Arming away with code: %s", code)
Expand All @@ -87,6 +90,8 @@ async def async_alarm_arm_away(self, code: str | None = None) -> None:

async def async_alarm_arm_home(self, code: str | None = None) -> None:
"""Send arm home command."""
if TYPE_CHECKING:
assert code is not None
if not self._is_valid_code(code):
raise ServiceValidationError("Invalid code length")
_LOGGER.debug("Arming home with code: %s", code)
Expand All @@ -95,6 +100,8 @@ async def async_alarm_arm_home(self, code: str | None = None) -> None:

async def async_alarm_disarm(self, code: str | None = None) -> None:
"""Send disarm command."""
if TYPE_CHECKING:
assert code is not None
if not self._is_valid_code(code):
raise ServiceValidationError("Invalid code length")
_LOGGER.debug("Disarming with code: %s", code)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sector/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, hass: HomeAssistant, email, password, panel_id):
self.password = password
self.panel_id = panel_id
self.access_token = None
self.headers = {}
self.headers:dict[str,str] = {}
self.session = None
self.data_endpoints = get_data_endpoints(self.panel_id)
self.action_endpoints = get_action_endpoints()
Expand Down
8 changes: 4 additions & 4 deletions custom_components/sector/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class SectorAlarmConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 4

def __init__(self):
self.email: str | None = None
self.password: str | None = None
self.code_format: int | None = None
self.panel_ids: dict[str, str] = {}
self.email: str | None
self.password: str | None
self.code_format: int | None
self.panel_ids: dict[str, str]

async def async_step_reauth(
self, entry_data: Mapping[str, Any]
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sector/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async def _async_update_data(self) -> dict[str, Any]:

def _process_devices(self, api_data) -> tuple[dict[str, Any], dict[str, Any]]:
"""Process device data from the API, including humidity, closed, and alarm sensors."""
devices = {}
devices:dict[str,Any] = {}
panel_status = api_data.get("Panel Status", {})

for category_name, category_data in api_data.items():
Expand Down
8 changes: 6 additions & 2 deletions custom_components/sector/lock.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Locks for Sector Alarm."""

import logging
from typing import Any
from typing import TYPE_CHECKING, Any

from homeassistant.components.lock import LockEntity
from homeassistant.const import ATTR_CODE
Expand All @@ -28,7 +28,7 @@ async def async_setup_entry(

for serial_no, device_info in devices.items():
if device_info.get("model") == "Smart Lock":
device_name = device_info.get("name")
device_name:str = device_info["name"]
entities.append(
SectorAlarmLock(
coordinator, code_format, serial_no, device_name, "Smart Lock"
Expand Down Expand Up @@ -78,6 +78,8 @@ def is_locked(self) -> bool:
async def async_lock(self, **kwargs) -> None:
"""Lock the device."""
code: str | None = kwargs.get(ATTR_CODE)
if TYPE_CHECKING:
assert code is not None
_LOGGER.debug("Lock requested for lock %s. Code: %s", self._serial_no, code)
success = await self.coordinator.api.lock_door(self._serial_no, code=code)
if success:
Expand All @@ -86,6 +88,8 @@ async def async_lock(self, **kwargs) -> None:
async def async_unlock(self, **kwargs) -> None:
"""Unlock the device."""
code: str | None = kwargs.get(ATTR_CODE)
if TYPE_CHECKING:
assert code is not None
_LOGGER.debug("Unlock requested for lock %s. Code: %s", self._serial_no, code)
success = await self.coordinator.api.unlock_door(self._serial_no, code=code)
if success:
Expand Down

0 comments on commit 5de8dd6

Please sign in to comment.