Remove unnecessary TYPE_CHECKING declarations in SimpliSafe (#65750)

This commit is contained in:
Aaron Bach
2022-02-05 00:41:40 -07:00
committed by GitHub
parent 3387e8368b
commit fbe4d42729
4 changed files with 16 additions and 26 deletions

View File

@@ -4,7 +4,7 @@ from __future__ import annotations
import asyncio
from collections.abc import Callable, Iterable
from datetime import timedelta
from typing import TYPE_CHECKING, Any, cast
from typing import Any, cast
from simplipy import API
from simplipy.device import Device, DeviceTypes
@@ -235,7 +235,6 @@ def _async_get_system_for_service_call(
) is None:
raise vol.Invalid("Invalid device ID specified")
if TYPE_CHECKING:
assert alarm_control_panel_device_entry.via_device_id
if (
@@ -494,7 +493,6 @@ class SimpliSafe:
async def _async_start_websocket_loop(self) -> None:
"""Start a websocket reconnection loop."""
if TYPE_CHECKING:
assert self._api.websocket
should_reconnect = True
@@ -527,7 +525,6 @@ class SimpliSafe:
LOGGER.debug("Websocket reconnection task successfully canceled")
self._websocket_reconnect_task = None
if TYPE_CHECKING:
assert self._api.websocket
await self._api.websocket.async_disconnect()
@@ -565,7 +562,6 @@ class SimpliSafe:
async def async_init(self) -> None:
"""Initialize the SimpliSafe "manager" class."""
if TYPE_CHECKING:
assert self._api.refresh_token
assert self._api.websocket
@@ -576,9 +572,7 @@ class SimpliSafe:
async def async_websocket_disconnect_listener(_: Event) -> None:
"""Define an event handler to disconnect from the websocket."""
if TYPE_CHECKING:
assert self._api.websocket
await self._async_cancel_websocket_loop()
self.entry.async_on_unload(
@@ -625,10 +619,8 @@ class SimpliSafe:
"""Handle a new refresh token."""
async_save_refresh_token(token)
if TYPE_CHECKING:
assert self._api.websocket
# Open a new websocket connection with the fresh token:
assert self._api.websocket
await self._async_cancel_websocket_loop()
self._websocket_reconnect_task = self._hass.async_create_task(
self._async_start_websocket_loop()

View File

@@ -1,8 +1,6 @@
"""Support for SimpliSafe alarm control panels."""
from __future__ import annotations
from typing import TYPE_CHECKING
from simplipy.errors import SimplipyError
from simplipy.system import SystemStates
from simplipy.system.v3 import SystemV3
@@ -240,8 +238,9 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
def async_update_from_websocket_event(self, event: WebsocketEvent) -> None:
"""Update the entity when new data comes from the websocket."""
self._attr_changed_by = event.changed_by
if TYPE_CHECKING:
assert event.event_type
if state := STATE_MAP_FROM_WEBSOCKET_EVENT.get(event.event_type):
self._attr_state = state
self.async_reset_error_count()

View File

@@ -1,7 +1,7 @@
"""Config flow to configure the SimpliSafe component."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any, NamedTuple
from typing import Any, NamedTuple
from simplipy import API
from simplipy.errors import InvalidCredentialsError, SimplipyError
@@ -97,7 +97,6 @@ class SimpliSafeFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if user_input is None:
return self._async_show_form()
if TYPE_CHECKING:
assert self._oauth_values
errors = {}

View File

@@ -1,7 +1,7 @@
"""Support for SimpliSafe locks."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from typing import Any
from simplipy.device.lock import Lock, LockStates
from simplipy.errors import SimplipyError
@@ -100,8 +100,8 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
@callback
def async_update_from_websocket_event(self, event: WebsocketEvent) -> None:
"""Update the entity when new data comes from the websocket."""
if TYPE_CHECKING:
assert event.event_type
if state := STATE_MAP_FROM_WEBSOCKET_EVENT.get(event.event_type) is not None:
self._attr_is_locked = state
self.async_reset_error_count()