1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Fix websocket connection sensor (#22923)

* Fix for #22890

* Singleton count
This commit is contained in:
Penny Wood
2019-04-14 01:48:40 +08:00
committed by Paulus Schoutsen
parent 479511ee42
commit 2527731865
3 changed files with 22 additions and 16 deletions

View File

@@ -15,7 +15,8 @@ from homeassistant.helpers.json import JSONEncoder
from .const import (
MAX_PENDING_MSG, CANCELLATION_ERRORS, URL, ERR_UNKNOWN_ERROR,
SIGNAL_WEBSOCKET_CONNECTED, SIGNAL_WEBSOCKET_DISCONNECTED)
SIGNAL_WEBSOCKET_CONNECTED, SIGNAL_WEBSOCKET_DISCONNECTED,
DATA_CONNECTIONS)
from .auth import AuthPhase, auth_required_message
from .error import Disconnect
from .messages import error_message
@@ -145,6 +146,8 @@ class WebSocketHandler:
self._logger.debug("Received %s", msg)
connection = await auth.async_handle(msg)
self.hass.data[DATA_CONNECTIONS] = \
self.hass.data.get(DATA_CONNECTIONS, 0) + 1
self.hass.helpers.dispatcher.async_dispatcher_send(
SIGNAL_WEBSOCKET_CONNECTED)
@@ -197,6 +200,7 @@ class WebSocketHandler:
else:
self._logger.warning("Disconnected: %s", disconnect_warn)
self.hass.data[DATA_CONNECTIONS] -= 1
self.hass.helpers.dispatcher.async_dispatcher_send(
SIGNAL_WEBSOCKET_DISCONNECTED)