mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add vesync debug mode in library (#134571)
* Debug mode pass through * Correct code, shouldn't have been lambda * listener for change * ruff * Update manifest.json * Reflect correct logger title * Ruff fix from merge
This commit is contained in:
parent
60479369b6
commit
2bab7436d3
@ -5,8 +5,13 @@ import logging
|
||||
from pyvesync import VeSync
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.const import (
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
EVENT_LOGGING_CHANGED,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
@ -17,6 +22,7 @@ from .const import (
|
||||
VS_COORDINATOR,
|
||||
VS_DEVICES,
|
||||
VS_DISCOVERY,
|
||||
VS_LISTENERS,
|
||||
VS_MANAGER,
|
||||
)
|
||||
from .coordinator import VeSyncDataCoordinator
|
||||
@ -42,7 +48,13 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
|
||||
time_zone = str(hass.config.time_zone)
|
||||
|
||||
manager = VeSync(username, password, time_zone)
|
||||
manager = VeSync(
|
||||
username=username,
|
||||
password=password,
|
||||
time_zone=time_zone,
|
||||
debug=logging.getLogger("pyvesync.vesync").level == logging.DEBUG,
|
||||
redact=True,
|
||||
)
|
||||
|
||||
login = await hass.async_add_executor_job(manager.login)
|
||||
|
||||
@ -62,6 +74,17 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
||||
@callback
|
||||
def _async_handle_logging_changed(_event: Event) -> None:
|
||||
"""Handle when the logging level changes."""
|
||||
manager.debug = logging.getLogger("pyvesync.vesync").level == logging.DEBUG
|
||||
|
||||
cleanup = hass.bus.async_listen(
|
||||
EVENT_LOGGING_CHANGED, _async_handle_logging_changed
|
||||
)
|
||||
|
||||
hass.data[DOMAIN][VS_LISTENERS] = cleanup
|
||||
|
||||
async def async_new_device_discovery(service: ServiceCall) -> None:
|
||||
"""Discover if new devices should be added."""
|
||||
manager = hass.data[DOMAIN][VS_MANAGER]
|
||||
@ -87,7 +110,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
|
||||
hass.data[DOMAIN][VS_LISTENERS]()
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data.pop(DOMAIN)
|
||||
|
@ -22,6 +22,7 @@ exceeds the quota of 7700.
|
||||
VS_DEVICES = "devices"
|
||||
VS_COORDINATOR = "coordinator"
|
||||
VS_MANAGER = "manager"
|
||||
VS_LISTENERS = "listeners"
|
||||
VS_NUMBERS = "numbers"
|
||||
|
||||
VS_HUMIDIFIER_MODE_AUTO = "auto"
|
||||
|
@ -11,6 +11,6 @@
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/vesync",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["pyvesync"],
|
||||
"loggers": ["pyvesync.vesync"],
|
||||
"requirements": ["pyvesync==2.1.18"]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user