Move Ambient PWS logger to a package logger (#43448)

This commit is contained in:
Aaron Bach 2020-11-20 13:20:56 -07:00 committed by GitHub
parent a880ef6a4e
commit 8779592952
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -1,6 +1,5 @@
"""Support for Ambient Weather Station Service.""" """Support for Ambient Weather Station Service."""
import asyncio import asyncio
import logging
from aioambient import Client from aioambient import Client
from aioambient.errors import WebsocketError from aioambient.errors import WebsocketError
@ -39,12 +38,11 @@ from .const import (
CONF_APP_KEY, CONF_APP_KEY,
DATA_CLIENT, DATA_CLIENT,
DOMAIN, DOMAIN,
LOGGER,
TYPE_BINARY_SENSOR, TYPE_BINARY_SENSOR,
TYPE_SENSOR, TYPE_SENSOR,
) )
_LOGGER = logging.getLogger(__name__)
DATA_CONFIG = "config" DATA_CONFIG = "config"
DEFAULT_SOCKET_MIN_RETRY = 15 DEFAULT_SOCKET_MIN_RETRY = 15
@ -307,7 +305,7 @@ async def async_setup_entry(hass, config_entry):
hass.loop.create_task(ambient.ws_connect()) hass.loop.create_task(ambient.ws_connect())
hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id] = ambient hass.data[DOMAIN][DATA_CLIENT][config_entry.entry_id] = ambient
except WebsocketError as err: except WebsocketError as err:
_LOGGER.error("Config entry failed: %s", err) LOGGER.error("Config entry failed: %s", err)
raise ConfigEntryNotReady from err raise ConfigEntryNotReady from err
async def _async_disconnect_websocket(*_): async def _async_disconnect_websocket(*_):
@ -337,7 +335,7 @@ async def async_migrate_entry(hass, config_entry):
"""Migrate old entry.""" """Migrate old entry."""
version = config_entry.version version = config_entry.version
_LOGGER.debug("Migrating from version %s", version) LOGGER.debug("Migrating from version %s", version)
# 1 -> 2: Unique ID format changed, so delete and re-import: # 1 -> 2: Unique ID format changed, so delete and re-import:
if version == 1: if version == 1:
@ -350,7 +348,7 @@ async def async_migrate_entry(hass, config_entry):
version = config_entry.version = 2 version = config_entry.version = 2
hass.config_entries.async_update_entry(config_entry) hass.config_entries.async_update_entry(config_entry)
_LOGGER.info("Migration to version %s successful", version) LOGGER.info("Migration to version %s successful", version)
return True return True
@ -377,7 +375,7 @@ class AmbientStation:
try: try:
await connect() await connect()
except WebsocketError as err: except WebsocketError as err:
_LOGGER.error("Error with the websocket connection: %s", err) LOGGER.error("Error with the websocket connection: %s", err)
self._ws_reconnect_delay = min(2 * self._ws_reconnect_delay, 480) self._ws_reconnect_delay = min(2 * self._ws_reconnect_delay, 480)
async_call_later(self._hass, self._ws_reconnect_delay, connect) async_call_later(self._hass, self._ws_reconnect_delay, connect)
@ -386,13 +384,13 @@ class AmbientStation:
def on_connect(): def on_connect():
"""Define a handler to fire when the websocket is connected.""" """Define a handler to fire when the websocket is connected."""
_LOGGER.info("Connected to websocket") LOGGER.info("Connected to websocket")
def on_data(data): def on_data(data):
"""Define a handler to fire when the data is received.""" """Define a handler to fire when the data is received."""
mac_address = data["macAddress"] mac_address = data["macAddress"]
if data != self.stations[mac_address][ATTR_LAST_DATA]: if data != self.stations[mac_address][ATTR_LAST_DATA]:
_LOGGER.debug("New data received: %s", data) LOGGER.debug("New data received: %s", data)
self.stations[mac_address][ATTR_LAST_DATA] = data self.stations[mac_address][ATTR_LAST_DATA] = data
async_dispatcher_send( async_dispatcher_send(
self._hass, f"ambient_station_data_update_{mac_address}" self._hass, f"ambient_station_data_update_{mac_address}"
@ -400,7 +398,7 @@ class AmbientStation:
def on_disconnect(): def on_disconnect():
"""Define a handler to fire when the websocket is disconnected.""" """Define a handler to fire when the websocket is disconnected."""
_LOGGER.info("Disconnected from websocket") LOGGER.info("Disconnected from websocket")
def on_subscribed(data): def on_subscribed(data):
"""Define a handler to fire when the subscription is set.""" """Define a handler to fire when the subscription is set."""
@ -408,7 +406,7 @@ class AmbientStation:
if station["macAddress"] in self.stations: if station["macAddress"] in self.stations:
continue continue
_LOGGER.debug("New station subscription: %s", data) LOGGER.debug("New station subscription: %s", data)
# Only create entities based on the data coming through the socket. # Only create entities based on the data coming through the socket.
# If the user is monitoring brightness (in W/m^2), make sure we also # If the user is monitoring brightness (in W/m^2), make sure we also

View File

@ -1,5 +1,8 @@
"""Define constants for the Ambient PWS component.""" """Define constants for the Ambient PWS component."""
import logging
DOMAIN = "ambient_station" DOMAIN = "ambient_station"
LOGGER = logging.getLogger(__package__)
ATTR_LAST_DATA = "last_data" ATTR_LAST_DATA = "last_data"
ATTR_MONITORED_CONDITIONS = "monitored_conditions" ATTR_MONITORED_CONDITIONS = "monitored_conditions"