From 1614de02d463a2cf252158ae63abca247fd5098f Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Thu, 31 Oct 2024 13:48:13 +0100 Subject: [PATCH] Fix mypy findings (#184) --- devolo_home_control_api/backend/mprm_rest.py | 2 +- devolo_home_control_api/backend/mprm_websocket.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/devolo_home_control_api/backend/mprm_rest.py b/devolo_home_control_api/backend/mprm_rest.py index f26983f..f5e0e78 100644 --- a/devolo_home_control_api/backend/mprm_rest.py +++ b/devolo_home_control_api/backend/mprm_rest.py @@ -90,7 +90,7 @@ def set_binary_switch(self, uid: str, state: bool) -> bool: :param state: True if switching on, False if switching off :return: True if successfully switched, false otherwise """ - data = {"method": "FIM/invokeOperation", "params": [uid, "turnOn" if state else "turnOff", []]} + data: dict[str, str | list] = {"method": "FIM/invokeOperation", "params": [uid, "turnOn" if state else "turnOff", []]} response = self._post(data) return self._evaluate_response(uid=uid, value=state, response=response) diff --git a/devolo_home_control_api/backend/mprm_websocket.py b/devolo_home_control_api/backend/mprm_websocket.py index 8c65df8..310e167 100644 --- a/devolo_home_control_api/backend/mprm_websocket.py +++ b/devolo_home_control_api/backend/mprm_websocket.py @@ -36,7 +36,7 @@ class MprmWebsocket(MprmRest, ABC): def __init__(self) -> None: """Initialize websocket communication.""" super().__init__() - self._ws: websocket.WebSocketApp = None + self._ws: websocket.WebSocketApp | None = None self._connected = False # This attribute saves, if the websocket is fully established self._reachable = True # This attribute saves, if the a new session can be established self._event_sequence = 0 @@ -110,6 +110,10 @@ def websocket_connect(self) -> None: def websocket_disconnect(self, event: str = "") -> None: """Close the websocket connection.""" + if not self._ws: + self._logger.info("Not connected to the web socket.") + return + self._logger.info("Closing web socket connection.") if event: self._logger.info("Reason: %s", event)