Clean webostv notify (#66803)
* Replace conf with attr * Test notify service without data parameter * Clean kwargs access * Replace icon constant * Use data from notifypull/66808/head
parent
ba6d1976df
commit
56d45c49e9
|
@ -7,7 +7,7 @@ from typing import Any
|
|||
from aiowebostv import WebOsClient, WebOsTvPairError
|
||||
|
||||
from homeassistant.components.notify import ATTR_DATA, BaseNotificationService
|
||||
from homeassistant.const import CONF_ICON
|
||||
from homeassistant.const import ATTR_ICON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
|
@ -46,8 +46,8 @@ class LgWebOSNotificationService(BaseNotificationService):
|
|||
if not self._client.is_connected():
|
||||
await self._client.connect()
|
||||
|
||||
data = kwargs.get(ATTR_DATA)
|
||||
icon_path = data.get(CONF_ICON) if data else None
|
||||
data = kwargs[ATTR_DATA]
|
||||
icon_path = data.get(ATTR_ICON) if data else None
|
||||
await self._client.send_message(message, icon_path=icon_path)
|
||||
except WebOsTvPairError:
|
||||
_LOGGER.error("Pairing with TV failed")
|
||||
|
|
|
@ -4,9 +4,13 @@ from unittest.mock import Mock, call
|
|||
from aiowebostv import WebOsTvPairError
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.notify import ATTR_MESSAGE, DOMAIN as NOTIFY_DOMAIN
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_DATA,
|
||||
ATTR_MESSAGE,
|
||||
DOMAIN as NOTIFY_DOMAIN,
|
||||
)
|
||||
from homeassistant.components.webostv import DOMAIN
|
||||
from homeassistant.const import CONF_ICON, CONF_SERVICE_DATA
|
||||
from homeassistant.const import ATTR_ICON
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import setup_webostv
|
||||
|
@ -26,8 +30,8 @@ async def test_notify(hass, client):
|
|||
TV_NAME,
|
||||
{
|
||||
ATTR_MESSAGE: MESSAGE,
|
||||
CONF_SERVICE_DATA: {
|
||||
CONF_ICON: ICON_PATH,
|
||||
ATTR_DATA: {
|
||||
ATTR_ICON: ICON_PATH,
|
||||
},
|
||||
},
|
||||
blocking=True,
|
||||
|
@ -41,7 +45,7 @@ async def test_notify(hass, client):
|
|||
TV_NAME,
|
||||
{
|
||||
ATTR_MESSAGE: MESSAGE,
|
||||
CONF_SERVICE_DATA: {
|
||||
ATTR_DATA: {
|
||||
"OTHER_DATA": "not_used",
|
||||
},
|
||||
},
|
||||
|
@ -51,6 +55,20 @@ async def test_notify(hass, client):
|
|||
assert client.connect.call_count == 1
|
||||
client.send_message.assert_called_with(MESSAGE, icon_path=None)
|
||||
|
||||
await hass.services.async_call(
|
||||
NOTIFY_DOMAIN,
|
||||
TV_NAME,
|
||||
{
|
||||
ATTR_MESSAGE: "only message, no data",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert client.connect.call_count == 1
|
||||
assert client.send_message.call_args == call(
|
||||
"only message, no data", icon_path=None
|
||||
)
|
||||
|
||||
|
||||
async def test_notify_not_connected(hass, client, monkeypatch):
|
||||
"""Test sending a message when client is not connected."""
|
||||
|
@ -63,8 +81,8 @@ async def test_notify_not_connected(hass, client, monkeypatch):
|
|||
TV_NAME,
|
||||
{
|
||||
ATTR_MESSAGE: MESSAGE,
|
||||
CONF_SERVICE_DATA: {
|
||||
CONF_ICON: ICON_PATH,
|
||||
ATTR_DATA: {
|
||||
ATTR_ICON: ICON_PATH,
|
||||
},
|
||||
},
|
||||
blocking=True,
|
||||
|
@ -85,8 +103,8 @@ async def test_icon_not_found(hass, caplog, client, monkeypatch):
|
|||
TV_NAME,
|
||||
{
|
||||
ATTR_MESSAGE: MESSAGE,
|
||||
CONF_SERVICE_DATA: {
|
||||
CONF_ICON: ICON_PATH,
|
||||
ATTR_DATA: {
|
||||
ATTR_ICON: ICON_PATH,
|
||||
},
|
||||
},
|
||||
blocking=True,
|
||||
|
@ -116,8 +134,8 @@ async def test_connection_errors(hass, caplog, client, monkeypatch, side_effect,
|
|||
TV_NAME,
|
||||
{
|
||||
ATTR_MESSAGE: MESSAGE,
|
||||
CONF_SERVICE_DATA: {
|
||||
CONF_ICON: ICON_PATH,
|
||||
ATTR_DATA: {
|
||||
ATTR_ICON: ICON_PATH,
|
||||
},
|
||||
},
|
||||
blocking=True,
|
||||
|
|
Loading…
Reference in New Issue