Type hint additions (#26831)

* Type hint additions

* Remove optional from sidebar_icon comment

Co-Authored-By: Franck Nijhof <frenck@frenck.nl>

* Remove optional from sidebar_title comment

Co-Authored-By: Franck Nijhof <frenck@frenck.nl>

* Fix issues after rebase and mypy 0.730
This commit is contained in:
Ville SkyttäandFranck Nijhof authored and GitHub committed 2019-09-29 20:07:49 +03:00
1 parent 4f55235aa2
commit f259ff17d5
27 files changed
+184 -68

No files matched your search

+11 -8
View File
@@ -25,6 +25,9 @@ from .error import Disconnect
from .messages import error_message
# mypy: allow-untyped-calls, allow-untyped-defs
class WebsocketAPIView(HomeAssistantView):
"""View to serve a websockets endpoint."""
@@ -45,7 +48,7 @@ class WebSocketHandler:
self.hass = hass
self.request = request
self.wsock = None
self._to_write = asyncio.Queue(maxsize=MAX_PENDING_MSG)
self._to_write: asyncio.Queue = asyncio.Queue(maxsize=MAX_PENDING_MSG)
self._handle_task = None
self._writer_task = None
self._logger = logging.getLogger("{}.connection.{}".format(__name__, id(self)))
@@ -106,7 +109,7 @@ class WebSocketHandler:
# Py3.7+
if hasattr(asyncio, "current_task"):
# pylint: disable=no-member
self._handle_task = asyncio.current_task()
self._handle_task = asyncio.current_task() # type: ignore
else:
self._handle_task = asyncio.Task.current_task()
@@ -144,13 +147,13 @@ class WebSocketHandler:
raise Disconnect
try:
msg = msg.json()
msg_data = msg.json()
except ValueError:
disconnect_warn = "Received invalid JSON."
raise Disconnect
self._logger.debug("Received %s", msg)
connection = await auth.async_handle(msg)
self._logger.debug("Received %s", msg_data)
connection = await auth.async_handle(msg_data)
self.hass.data[DATA_CONNECTIONS] = (
self.hass.data.get(DATA_CONNECTIONS, 0) + 1
)
@@ -170,13 +173,13 @@ class WebSocketHandler:
break
try:
msg = msg.json()
msg_data = msg.json()
except ValueError:
disconnect_warn = "Received invalid JSON."
break
self._logger.debug("Received %s", msg)
connection.async_handle(msg)
self._logger.debug("Received %s", msg_data)
connection.async_handle(msg_data)
except asyncio.CancelledError:
self._logger.info("Connection closed by client")