diff --git a/homeassistant/components/webostv/notify.py b/homeassistant/components/webostv/notify.py index 46f0086e0f6a0ce9371a313fb7bc0086f8a82b99..82e618561879050fb671448662fc2efb4990e156 100644 --- a/homeassistant/components/webostv/notify.py +++ b/homeassistant/components/webostv/notify.py @@ -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") diff --git a/tests/components/webostv/test_notify.py b/tests/components/webostv/test_notify.py index 7e150c6eb7828d526dc544663d06e90ab2a8bc84..92fb151c1b34e60008c2fd60ee8a74fbc65ae58d 100644 --- a/tests/components/webostv/test_notify.py +++ b/tests/components/webostv/test_notify.py @@ -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,