Skip to content

Commit

Permalink
Enable strict typing for Reolink (home-assistant#131239)
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG authored Nov 22, 2024
1 parent 9e4368c commit 65652c0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ homeassistant.components.recollect_waste.*
homeassistant.components.recorder.*
homeassistant.components.remote.*
homeassistant.components.renault.*
homeassistant.components.reolink.*
homeassistant.components.repairs.*
homeassistant.components.rest.*
homeassistant.components.rest_command.*
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/reolink/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async def async_press(self) -> None:
except ReolinkError as err:
raise HomeAssistantError(err) from err

async def async_ptz_move(self, **kwargs) -> None:
async def async_ptz_move(self, **kwargs: Any) -> None:
"""PTZ move with speed."""
speed = kwargs[ATTR_SPEED]
try:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/reolink/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def available(self) -> bool:
"""Return True if entity is available."""
return super().available and self._host.api.camera_online(self._channel)

def register_callback(self, unique_id: str, cmd_id) -> None:
def register_callback(self, unique_id: str, cmd_id: int) -> None:
"""Register callback for TCP push events."""
self._host.api.baichuan.register_callback(
unique_id, self._push_callback, cmd_id, self._channel
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/reolink/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ async def async_init(self) -> None:
else:
ir.async_delete_issue(self._hass, DOMAIN, f"firmware_update_{key}")

async def _async_check_tcp_push(self, *_) -> None:
async def _async_check_tcp_push(self, *_: Any) -> None:
"""Check the TCP push subscription."""
if self._api.baichuan.events_active:
ir.async_delete_issue(self._hass, DOMAIN, "webhook_url")
Expand Down Expand Up @@ -323,7 +323,7 @@ async def _async_check_tcp_push(self, *_) -> None:

self._cancel_tcp_push_check = None

async def _async_check_onvif(self, *_) -> None:
async def _async_check_onvif(self, *_: Any) -> None:
"""Check the ONVIF subscription."""
if self._webhook_reachable:
ir.async_delete_issue(self._hass, DOMAIN, "webhook_url")
Expand All @@ -344,7 +344,7 @@ async def _async_check_onvif(self, *_) -> None:

self._cancel_onvif_check = None

async def _async_check_onvif_long_poll(self, *_) -> None:
async def _async_check_onvif_long_poll(self, *_: Any) -> None:
"""Check if ONVIF long polling is working."""
if not self._long_poll_received:
_LOGGER.debug(
Expand Down Expand Up @@ -450,7 +450,7 @@ async def disconnect(self) -> None:
err,
)

async def _async_start_long_polling(self, initial=False) -> None:
async def _async_start_long_polling(self, initial: bool = False) -> None:
"""Start ONVIF long polling task."""
if self._long_poll_task is None:
try:
Expand Down Expand Up @@ -495,7 +495,7 @@ async def _async_stop_long_polling(self) -> None:
err,
)

async def stop(self, event=None) -> None:
async def stop(self, *_: Any) -> None:
"""Disconnect the API."""
if self._cancel_poll is not None:
self._cancel_poll()
Expand Down Expand Up @@ -651,7 +651,7 @@ def unregister_webhook(self) -> None:
webhook.async_unregister(self._hass, self.webhook_id)
self.webhook_id = None

async def _async_long_polling(self, *_) -> None:
async def _async_long_polling(self, *_: Any) -> None:
"""Use ONVIF long polling to immediately receive events."""
# This task will be cancelled once _async_stop_long_polling is called
while True:
Expand Down Expand Up @@ -688,7 +688,7 @@ async def _async_long_polling(self, *_) -> None:
# Cooldown to prevent CPU over usage on camera freezes
await asyncio.sleep(LONG_POLL_COOLDOWN)

async def _async_poll_all_motion(self, *_) -> None:
async def _async_poll_all_motion(self, *_: Any) -> None:
"""Poll motion and AI states until the first ONVIF push is received."""
if (
self._api.baichuan.events_active
Expand Down
11 changes: 8 additions & 3 deletions homeassistant/components/reolink/media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from .const import DOMAIN
from .host import ReolinkHost
from .util import ReolinkConfigEntry

_LOGGER = logging.getLogger(__name__)

Expand All @@ -48,7 +49,9 @@ def res_name(stream: str) -> str:

def get_host(hass: HomeAssistant, config_entry_id: str) -> ReolinkHost:
"""Return the Reolink host from the config entry id."""
config_entry = hass.config_entries.async_get_entry(config_entry_id)
config_entry: ReolinkConfigEntry | None = hass.config_entries.async_get_entry(
config_entry_id
)
assert config_entry is not None
return config_entry.runtime_data.host

Expand All @@ -65,7 +68,9 @@ def __init__(self, hass: HomeAssistant) -> None:

async def async_resolve_media(self, item: MediaSourceItem) -> PlayMedia:
"""Resolve media to a url."""
identifier = item.identifier.split("|", 5)
identifier = ["UNKNOWN"]
if item.identifier is not None:
identifier = item.identifier.split("|", 5)
if identifier[0] != "FILE":
raise Unresolvable(f"Unknown media item '{item.identifier}'.")

Expand Down Expand Up @@ -110,7 +115,7 @@ async def async_browse_media(
item: MediaSourceItem,
) -> BrowseMediaSource:
"""Return media."""
if item.identifier is None:
if not item.identifier:
return await self._async_generate_root()

identifier = item.identifier.split("|", 7)
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/reolink/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,23 @@ async def _pause_update_coordinator(self) -> None:
self._reolink_data.device_coordinator.update_interval = None
self._reolink_data.device_coordinator.async_set_updated_data(None)

async def _resume_update_coordinator(self, *args) -> None:
async def _resume_update_coordinator(self, *args: Any) -> None:
"""Resume updating the states using the data update coordinator (after reboots)."""
self._reolink_data.device_coordinator.update_interval = DEVICE_UPDATE_INTERVAL
try:
await self._reolink_data.device_coordinator.async_refresh()
finally:
self._cancel_resume = None

async def _async_update_progress(self, *args) -> None:
async def _async_update_progress(self, *args: Any) -> None:
"""Request update."""
self.async_write_ha_state()
if self._installing:
self._cancel_progress = async_call_later(
self.hass, POLL_PROGRESS, self._async_update_progress
)

async def _async_update_future(self, *args) -> None:
async def _async_update_future(self, *args: Any) -> None:
"""Request update."""
try:
await self.async_update()
Expand Down
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3606,6 +3606,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true

[mypy-homeassistant.components.reolink.*]
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.repairs.*]
check_untyped_defs = true
disallow_incomplete_defs = true
Expand Down

0 comments on commit 65652c0

Please sign in to comment.