Clean up zwave_js logging and hass.data (#73856)
parent
1ead6d6762
commit
0e674fc597
|
@ -104,8 +104,6 @@ from .services import ZWaveServices
|
|||
CONNECT_TIMEOUT = 10
|
||||
DATA_CLIENT_LISTEN_TASK = "client_listen_task"
|
||||
DATA_START_PLATFORM_TASK = "start_platform_task"
|
||||
DATA_CONNECT_FAILED_LOGGED = "connect_failed_logged"
|
||||
DATA_INVALID_SERVER_VERSION_LOGGED = "invalid_server_version_logged"
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
@ -170,28 +168,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
await async_ensure_addon_running(hass, entry)
|
||||
|
||||
client = ZwaveClient(entry.data[CONF_URL], async_get_clientsession(hass))
|
||||
entry_hass_data: dict = hass.data[DOMAIN].setdefault(entry.entry_id, {})
|
||||
|
||||
# connect and throw error if connection failed
|
||||
try:
|
||||
async with timeout(CONNECT_TIMEOUT):
|
||||
await client.connect()
|
||||
except InvalidServerVersion as err:
|
||||
if not entry_hass_data.get(DATA_INVALID_SERVER_VERSION_LOGGED):
|
||||
LOGGER.error("Invalid server version: %s", err)
|
||||
entry_hass_data[DATA_INVALID_SERVER_VERSION_LOGGED] = True
|
||||
if use_addon:
|
||||
async_ensure_addon_updated(hass)
|
||||
raise ConfigEntryNotReady from err
|
||||
raise ConfigEntryNotReady(f"Invalid server version: {err}") from err
|
||||
except (asyncio.TimeoutError, BaseZwaveJSServerError) as err:
|
||||
if not entry_hass_data.get(DATA_CONNECT_FAILED_LOGGED):
|
||||
LOGGER.error("Failed to connect: %s", err)
|
||||
entry_hass_data[DATA_CONNECT_FAILED_LOGGED] = True
|
||||
raise ConfigEntryNotReady from err
|
||||
raise ConfigEntryNotReady(f"Failed to connect: {err}") from err
|
||||
else:
|
||||
LOGGER.info("Connected to Zwave JS Server")
|
||||
entry_hass_data[DATA_CONNECT_FAILED_LOGGED] = False
|
||||
entry_hass_data[DATA_INVALID_SERVER_VERSION_LOGGED] = False
|
||||
|
||||
dev_reg = device_registry.async_get(hass)
|
||||
ent_reg = entity_registry.async_get(hass)
|
||||
|
@ -202,7 +191,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
async_register_api(hass)
|
||||
|
||||
platform_task = hass.async_create_task(start_platforms(hass, entry, client))
|
||||
entry_hass_data[DATA_START_PLATFORM_TASK] = platform_task
|
||||
hass.data[DOMAIN].setdefault(entry.entry_id, {})[
|
||||
DATA_START_PLATFORM_TASK
|
||||
] = platform_task
|
||||
|
||||
return True
|
||||
|
||||
|
@ -635,9 +626,7 @@ async def disconnect_client(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||
platform_task: asyncio.Task = data[DATA_START_PLATFORM_TASK]
|
||||
listen_task.cancel()
|
||||
platform_task.cancel()
|
||||
platform_setup_tasks = (
|
||||
hass.data[DOMAIN].get(entry.entry_id, {}).get(DATA_PLATFORM_SETUP, {}).values()
|
||||
)
|
||||
platform_setup_tasks = data.get(DATA_PLATFORM_SETUP, {}).values()
|
||||
for task in platform_setup_tasks:
|
||||
task.cancel()
|
||||
|
||||
|
@ -711,8 +700,7 @@ async def async_ensure_addon_running(hass: HomeAssistant, entry: ConfigEntry) ->
|
|||
try:
|
||||
addon_info = await addon_manager.async_get_addon_info()
|
||||
except AddonError as err:
|
||||
LOGGER.error(err)
|
||||
raise ConfigEntryNotReady from err
|
||||
raise ConfigEntryNotReady(err) from err
|
||||
|
||||
usb_path: str = entry.data[CONF_USB_PATH]
|
||||
# s0_legacy_key was saved as network_key before s2 was added.
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
|
||||
from zwave_js_server.client import Client as ZwaveClient
|
||||
from zwave_js_server.const import CommandClass
|
||||
|
@ -30,8 +29,6 @@ from .entity import ZWaveBaseEntity
|
|||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
NOTIFICATION_SMOKE_ALARM = "1"
|
||||
NOTIFICATION_CARBON_MONOOXIDE = "2"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support for Z-Wave cover devices."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any, cast
|
||||
|
||||
from zwave_js_server.client import Client as ZwaveClient
|
||||
|
@ -39,8 +38,6 @@ from .entity import ZWaveBaseEntity
|
|||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""Generic Z-Wave Entity Class."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from zwave_js_server.const import NodeStatus
|
||||
from zwave_js_server.model.driver import Driver
|
||||
from zwave_js_server.model.value import Value as ZwaveValue, get_value_id
|
||||
|
@ -12,12 +10,10 @@ from homeassistant.core import callback
|
|||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, LOGGER
|
||||
from .discovery import ZwaveDiscoveryInfo
|
||||
from .helpers import get_device_id, get_unique_id
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
EVENT_VALUE_UPDATED = "value updated"
|
||||
EVENT_VALUE_REMOVED = "value removed"
|
||||
EVENT_DEAD = "dead"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Support for Z-Wave lights."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any, cast
|
||||
|
||||
from zwave_js_server.client import Client as ZwaveClient
|
||||
|
@ -49,8 +48,6 @@ from .entity import ZWaveBaseEntity
|
|||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
MULTI_COLOR_MAP = {
|
||||
ColorComponent.WARM_WHITE: COLOR_SWITCH_COMBINED_WARM_WHITE,
|
||||
ColorComponent.COLD_WHITE: COLOR_SWITCH_COMBINED_COLD_WHITE,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Representation of Z-Wave locks."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -27,6 +26,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from .const import (
|
||||
DATA_CLIENT,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
SERVICE_CLEAR_LOCK_USERCODE,
|
||||
SERVICE_SET_LOCK_USERCODE,
|
||||
)
|
||||
|
@ -35,8 +35,6 @@ from .entity import ZWaveBaseEntity
|
|||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
STATE_TO_ZWAVE_MAP: dict[int, dict[str, int | bool]] = {
|
||||
CommandClass.DOOR_LOCK: {
|
||||
STATE_UNLOCKED: DoorLockMode.UNSECURED,
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import cast
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -55,6 +54,7 @@ from .const import (
|
|||
ENTITY_DESC_KEY_TEMPERATURE,
|
||||
ENTITY_DESC_KEY_TOTAL_INCREASING,
|
||||
ENTITY_DESC_KEY_VOLTAGE,
|
||||
LOGGER,
|
||||
SERVICE_RESET_METER,
|
||||
)
|
||||
from .discovery import ZwaveDiscoveryInfo
|
||||
|
@ -67,8 +67,6 @@ from .helpers import get_device_id, get_valueless_base_unique_id
|
|||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
STATUS_ICON: dict[NodeStatus, str] = {
|
||||
NodeStatus.ALIVE: "mdi:heart-pulse",
|
||||
NodeStatus.ASLEEP: "mdi:sleep",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Representation of Z-Wave switches."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from zwave_js_server.client import Client as ZwaveClient
|
||||
|
@ -23,8 +22,6 @@ from .entity import ZWaveBaseEntity
|
|||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
|
Loading…
Reference in New Issue