Add diagnostics to webostv (#81133)

pull/81341/head
Shay Levy 2022-10-28 15:48:16 +03:00 committed by Paulus Schoutsen
parent 6036443d4a
commit 6f3b7d009d
3 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,52 @@
"""Diagnostics support for LG webOS Smart TV."""
from __future__ import annotations
from typing import Any
from aiowebostv import WebOsClient
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_SECRET, CONF_HOST, CONF_UNIQUE_ID
from homeassistant.core import HomeAssistant
from .const import DATA_CONFIG_ENTRY, DOMAIN
TO_REDACT = {
CONF_CLIENT_SECRET,
CONF_UNIQUE_ID,
CONF_HOST,
"device_id",
"deviceUUID",
"icon",
"largeIcon",
}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
client: WebOsClient = hass.data[DOMAIN][DATA_CONFIG_ENTRY][entry.entry_id].client
client_data = {
"is_registered": client.is_registered(),
"is_connected": client.is_connected(),
"current_app_id": client.current_app_id,
"current_channel": client.current_channel,
"apps": client.apps,
"inputs": client.inputs,
"system_info": client.system_info,
"software_info": client.software_info,
"hello_info": client.hello_info,
"sound_output": client.sound_output,
"is_on": client.is_on,
}
return async_redact_data(
{
"entry": entry.as_dict(),
"client": client_data,
},
TO_REDACT,
)

View File

@ -39,6 +39,8 @@ def client_fixture():
client.sound_output = "speaker" client.sound_output = "speaker"
client.muted = False client.muted = False
client.is_on = True client.is_on = True
client.is_registered = Mock(return_value=True)
client.is_connected = Mock(return_value=True)
async def mock_state_update_callback(): async def mock_state_update_callback():
await client.register_state_update_callback.call_args[0][0](client) await client.register_state_update_callback.call_args[0][0](client)

View File

@ -0,0 +1,61 @@
"""Tests for the diagnostics data provided by LG webOS Smart TV."""
from aiohttp import ClientSession
from homeassistant.components.diagnostics import REDACTED
from homeassistant.core import HomeAssistant
from . import setup_webostv
from tests.components.diagnostics import get_diagnostics_for_config_entry
async def test_diagnostics(
hass: HomeAssistant, hass_client: ClientSession, client
) -> None:
"""Test diagnostics."""
entry = await setup_webostv(hass)
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == {
"client": {
"is_registered": True,
"is_connected": True,
"current_app_id": "com.webos.app.livetv",
"current_channel": {
"channelId": "ch1id",
"channelName": "Channel 1",
"channelNumber": "1",
},
"apps": {
"com.webos.app.livetv": {
"icon": REDACTED,
"id": "com.webos.app.livetv",
"largeIcon": REDACTED,
"title": "Live TV",
}
},
"inputs": {
"in1": {"appId": "app0", "id": "in1", "label": "Input01"},
"in2": {"appId": "app1", "id": "in2", "label": "Input02"},
},
"system_info": {"modelName": "TVFAKE"},
"software_info": {"major_ver": "major", "minor_ver": "minor"},
"hello_info": {"deviceUUID": "**REDACTED**"},
"sound_output": "speaker",
"is_on": True,
},
"entry": {
"entry_id": entry.entry_id,
"version": 1,
"domain": "webostv",
"title": "fake_webos",
"data": {
"client_secret": "**REDACTED**",
"host": "**REDACTED**",
},
"options": {},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "user",
"unique_id": REDACTED,
"disabled_by": None,
},
}