Skip to content

Commit

Permalink
Changes as per code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Swamp-Ig committed Mar 21, 2019
1 parent 48ffb71 commit b27fbf6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/websocket_api/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
CANCELLATION_ERRORS = (asyncio.CancelledError, futures.CancelledError)

# Event types
EVENT_WEBSOCKET_CONNECTED = 'websocket_connected'
EVENT_WEBSOCKET_DISCONNECTED = 'websocket_disconnected'
SIGNAL_WEBSOCKET_CONNECTED = 'websocket_connected'
SIGNAL_WEBSOCKET_DISCONNECTED = 'websocket_disconnected'
6 changes: 3 additions & 3 deletions homeassistant/components/websocket_api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from .const import (
MAX_PENDING_MSG, CANCELLATION_ERRORS, URL, ERR_UNKNOWN_ERROR,
EVENT_WEBSOCKET_CONNECTED, EVENT_WEBSOCKET_DISCONNECTED)
SIGNAL_WEBSOCKET_CONNECTED, SIGNAL_WEBSOCKET_DISCONNECTED)
from .auth import AuthPhase, auth_required_message
from .error import Disconnect
from .messages import error_message
Expand Down Expand Up @@ -145,7 +145,7 @@ def handle_hass_stop(event):
self._logger.debug("Received %s", msg)
connection = await auth.async_handle(msg)
self.hass.helpers.dispatcher.async_dispatcher_send(
EVENT_WEBSOCKET_CONNECTED, connection)
SIGNAL_WEBSOCKET_CONNECTED)

# Command phase
while not wsock.closed:
Expand Down Expand Up @@ -197,6 +197,6 @@ def handle_hass_stop(event):
self._logger.warning("Disconnected: %s", disconnect_warn)

self.hass.helpers.dispatcher.async_dispatcher_send(
EVENT_WEBSOCKET_DISCONNECTED, connection, disconnect_warn)
SIGNAL_WEBSOCKET_DISCONNECTED)

return wsock
21 changes: 8 additions & 13 deletions homeassistant/components/websocket_api/sensor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
"""
Entity to track connections to stream API.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.api_streams/
"""
"""Entity to track connections to websocket API."""

from homeassistant.core import callback
from homeassistant.helpers.entity import Entity

from .const import EVENT_WEBSOCKET_CONNECTED, EVENT_WEBSOCKET_DISCONNECTED
from .const import SIGNAL_WEBSOCKET_CONNECTED, SIGNAL_WEBSOCKET_DISCONNECTED


async def async_setup_platform(
Expand All @@ -18,9 +13,9 @@ async def async_setup_platform(

# pylint: disable=protected-access
hass.helpers.dispatcher.async_dispatcher_connect(
EVENT_WEBSOCKET_CONNECTED, entity._increment)
SIGNAL_WEBSOCKET_CONNECTED, entity._increment)
hass.helpers.dispatcher.async_dispatcher_connect(
EVENT_WEBSOCKET_DISCONNECTED, entity._decrement)
SIGNAL_WEBSOCKET_DISCONNECTED, entity._decrement)

async_add_entities([entity])

Expand Down Expand Up @@ -48,11 +43,11 @@ def unit_of_measurement(self):
return "clients"

@callback
def _increment(self, connection):
def _increment(self):
self.count += 1
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

@callback
def _decrement(self, connection, fail_msg):
def _decrement(self):
self.count -= 1
self.schedule_update_ha_state()
self.async_schedule_update_ha_state()

0 comments on commit b27fbf6

Please sign in to comment.