mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Enable strict typing for Reolink (#131239)
This commit is contained in:
parent
9e4368cfd4
commit
65652c0adb
@ -385,6 +385,7 @@ homeassistant.components.recollect_waste.*
|
|||||||
homeassistant.components.recorder.*
|
homeassistant.components.recorder.*
|
||||||
homeassistant.components.remote.*
|
homeassistant.components.remote.*
|
||||||
homeassistant.components.renault.*
|
homeassistant.components.renault.*
|
||||||
|
homeassistant.components.reolink.*
|
||||||
homeassistant.components.repairs.*
|
homeassistant.components.repairs.*
|
||||||
homeassistant.components.rest.*
|
homeassistant.components.rest.*
|
||||||
homeassistant.components.rest_command.*
|
homeassistant.components.rest_command.*
|
||||||
|
@ -212,7 +212,7 @@ class ReolinkButtonEntity(ReolinkChannelCoordinatorEntity, ButtonEntity):
|
|||||||
except ReolinkError as err:
|
except ReolinkError as err:
|
||||||
raise HomeAssistantError(err) from 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."""
|
"""PTZ move with speed."""
|
||||||
speed = kwargs[ATTR_SPEED]
|
speed = kwargs[ATTR_SPEED]
|
||||||
try:
|
try:
|
||||||
|
@ -179,7 +179,7 @@ class ReolinkChannelCoordinatorEntity(ReolinkHostCoordinatorEntity):
|
|||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return super().available and self._host.api.camera_online(self._channel)
|
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."""
|
"""Register callback for TCP push events."""
|
||||||
self._host.api.baichuan.register_callback(
|
self._host.api.baichuan.register_callback(
|
||||||
unique_id, self._push_callback, cmd_id, self._channel
|
unique_id, self._push_callback, cmd_id, self._channel
|
||||||
|
@ -262,7 +262,7 @@ class ReolinkHost:
|
|||||||
else:
|
else:
|
||||||
ir.async_delete_issue(self._hass, DOMAIN, f"firmware_update_{key}")
|
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."""
|
"""Check the TCP push subscription."""
|
||||||
if self._api.baichuan.events_active:
|
if self._api.baichuan.events_active:
|
||||||
ir.async_delete_issue(self._hass, DOMAIN, "webhook_url")
|
ir.async_delete_issue(self._hass, DOMAIN, "webhook_url")
|
||||||
@ -323,7 +323,7 @@ class ReolinkHost:
|
|||||||
|
|
||||||
self._cancel_tcp_push_check = 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."""
|
"""Check the ONVIF subscription."""
|
||||||
if self._webhook_reachable:
|
if self._webhook_reachable:
|
||||||
ir.async_delete_issue(self._hass, DOMAIN, "webhook_url")
|
ir.async_delete_issue(self._hass, DOMAIN, "webhook_url")
|
||||||
@ -344,7 +344,7 @@ class ReolinkHost:
|
|||||||
|
|
||||||
self._cancel_onvif_check = 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."""
|
"""Check if ONVIF long polling is working."""
|
||||||
if not self._long_poll_received:
|
if not self._long_poll_received:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
@ -450,7 +450,7 @@ class ReolinkHost:
|
|||||||
err,
|
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."""
|
"""Start ONVIF long polling task."""
|
||||||
if self._long_poll_task is None:
|
if self._long_poll_task is None:
|
||||||
try:
|
try:
|
||||||
@ -495,7 +495,7 @@ class ReolinkHost:
|
|||||||
err,
|
err,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def stop(self, event=None) -> None:
|
async def stop(self, *_: Any) -> None:
|
||||||
"""Disconnect the API."""
|
"""Disconnect the API."""
|
||||||
if self._cancel_poll is not None:
|
if self._cancel_poll is not None:
|
||||||
self._cancel_poll()
|
self._cancel_poll()
|
||||||
@ -651,7 +651,7 @@ class ReolinkHost:
|
|||||||
webhook.async_unregister(self._hass, self.webhook_id)
|
webhook.async_unregister(self._hass, self.webhook_id)
|
||||||
self.webhook_id = None
|
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."""
|
"""Use ONVIF long polling to immediately receive events."""
|
||||||
# This task will be cancelled once _async_stop_long_polling is called
|
# This task will be cancelled once _async_stop_long_polling is called
|
||||||
while True:
|
while True:
|
||||||
@ -688,7 +688,7 @@ class ReolinkHost:
|
|||||||
# Cooldown to prevent CPU over usage on camera freezes
|
# Cooldown to prevent CPU over usage on camera freezes
|
||||||
await asyncio.sleep(LONG_POLL_COOLDOWN)
|
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."""
|
"""Poll motion and AI states until the first ONVIF push is received."""
|
||||||
if (
|
if (
|
||||||
self._api.baichuan.events_active
|
self._api.baichuan.events_active
|
||||||
|
@ -24,6 +24,7 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
|||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .host import ReolinkHost
|
from .host import ReolinkHost
|
||||||
|
from .util import ReolinkConfigEntry
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -48,7 +49,9 @@ def res_name(stream: str) -> str:
|
|||||||
|
|
||||||
def get_host(hass: HomeAssistant, config_entry_id: str) -> ReolinkHost:
|
def get_host(hass: HomeAssistant, config_entry_id: str) -> ReolinkHost:
|
||||||
"""Return the Reolink host from the config entry id."""
|
"""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
|
assert config_entry is not None
|
||||||
return config_entry.runtime_data.host
|
return config_entry.runtime_data.host
|
||||||
|
|
||||||
@ -65,7 +68,9 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
|
|
||||||
async def async_resolve_media(self, item: MediaSourceItem) -> PlayMedia:
|
async def async_resolve_media(self, item: MediaSourceItem) -> PlayMedia:
|
||||||
"""Resolve media to a url."""
|
"""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":
|
if identifier[0] != "FILE":
|
||||||
raise Unresolvable(f"Unknown media item '{item.identifier}'.")
|
raise Unresolvable(f"Unknown media item '{item.identifier}'.")
|
||||||
|
|
||||||
@ -110,7 +115,7 @@ class ReolinkVODMediaSource(MediaSource):
|
|||||||
item: MediaSourceItem,
|
item: MediaSourceItem,
|
||||||
) -> BrowseMediaSource:
|
) -> BrowseMediaSource:
|
||||||
"""Return media."""
|
"""Return media."""
|
||||||
if item.identifier is None:
|
if not item.identifier:
|
||||||
return await self._async_generate_root()
|
return await self._async_generate_root()
|
||||||
|
|
||||||
identifier = item.identifier.split("|", 7)
|
identifier = item.identifier.split("|", 7)
|
||||||
|
@ -213,7 +213,7 @@ class ReolinkUpdateBaseEntity(
|
|||||||
self._reolink_data.device_coordinator.update_interval = None
|
self._reolink_data.device_coordinator.update_interval = None
|
||||||
self._reolink_data.device_coordinator.async_set_updated_data(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)."""
|
"""Resume updating the states using the data update coordinator (after reboots)."""
|
||||||
self._reolink_data.device_coordinator.update_interval = DEVICE_UPDATE_INTERVAL
|
self._reolink_data.device_coordinator.update_interval = DEVICE_UPDATE_INTERVAL
|
||||||
try:
|
try:
|
||||||
@ -221,7 +221,7 @@ class ReolinkUpdateBaseEntity(
|
|||||||
finally:
|
finally:
|
||||||
self._cancel_resume = None
|
self._cancel_resume = None
|
||||||
|
|
||||||
async def _async_update_progress(self, *args) -> None:
|
async def _async_update_progress(self, *args: Any) -> None:
|
||||||
"""Request update."""
|
"""Request update."""
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
if self._installing:
|
if self._installing:
|
||||||
@ -229,7 +229,7 @@ class ReolinkUpdateBaseEntity(
|
|||||||
self.hass, POLL_PROGRESS, self._async_update_progress
|
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."""
|
"""Request update."""
|
||||||
try:
|
try:
|
||||||
await self.async_update()
|
await self.async_update()
|
||||||
|
10
mypy.ini
10
mypy.ini
@ -3606,6 +3606,16 @@ disallow_untyped_defs = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = 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.*]
|
[mypy-homeassistant.components.repairs.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user