-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diagnostics and error checking (#12)
* Just a test PR * Add diagnostics.py Restructure fan config constants Fix error handling on unsupported fan * Update Readme
- Loading branch information
1 parent
bd8f0fb
commit dec13ef
Showing
6 changed files
with
104 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Diagnostics support for VeSync.""" | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from .pydreo import PyDreo, PyDreoBaseDevice | ||
|
||
from homeassistant.components.diagnostics import REDACTED | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import entity_registry as er | ||
from homeassistant.helpers.device_registry import DeviceEntry | ||
|
||
from .const import * | ||
|
||
KEYS_TO_REDACT = {"sn", "_sn", "wifi_ssid", "module_hardware_mac"} | ||
|
||
|
||
async def async_get_config_entry_diagnostics(hass: HomeAssistant, entry: ConfigEntry) -> dict[str, Any]: | ||
"""Return diagnostics for a config entry.""" | ||
manager: PyDreo = hass.data[DOMAIN][DREO_MANAGER] | ||
|
||
data = { | ||
DOMAIN: { | ||
"fan_count": len(manager.fans), | ||
"raw_devicelist": _redact_values(manager.raw_response) | ||
}, | ||
"devices": { | ||
"fans": [_redact_values(device.__dict__) for device in manager.fans], | ||
}, | ||
} | ||
|
||
return data | ||
|
||
def _redact_values(data: dict) -> dict: | ||
"""Rebuild and redact values of a dictionary, recursively""" | ||
|
||
new_data = {} | ||
|
||
for key, item in data.items(): | ||
if key not in KEYS_TO_REDACT: | ||
if isinstance(item, dict): | ||
new_data[key] = _redact_values(item) | ||
else: | ||
new_data[key] = item | ||
else: | ||
new_data[key] = REDACTED | ||
|
||
return new_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters