mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Clean webostv notify (#66803)
* Replace conf with attr * Test notify service without data parameter * Clean kwargs access * Replace icon constant * Use data from notify
This commit is contained in:
parent
ba6d1976df
commit
56d45c49e9
@ -7,7 +7,7 @@ from typing import Any
|
|||||||
from aiowebostv import WebOsClient, WebOsTvPairError
|
from aiowebostv import WebOsClient, WebOsTvPairError
|
||||||
|
|
||||||
from homeassistant.components.notify import ATTR_DATA, BaseNotificationService
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
@ -46,8 +46,8 @@ class LgWebOSNotificationService(BaseNotificationService):
|
|||||||
if not self._client.is_connected():
|
if not self._client.is_connected():
|
||||||
await self._client.connect()
|
await self._client.connect()
|
||||||
|
|
||||||
data = kwargs.get(ATTR_DATA)
|
data = kwargs[ATTR_DATA]
|
||||||
icon_path = data.get(CONF_ICON) if data else None
|
icon_path = data.get(ATTR_ICON) if data else None
|
||||||
await self._client.send_message(message, icon_path=icon_path)
|
await self._client.send_message(message, icon_path=icon_path)
|
||||||
except WebOsTvPairError:
|
except WebOsTvPairError:
|
||||||
_LOGGER.error("Pairing with TV failed")
|
_LOGGER.error("Pairing with TV failed")
|
||||||
|
@ -4,9 +4,13 @@ from unittest.mock import Mock, call
|
|||||||
from aiowebostv import WebOsTvPairError
|
from aiowebostv import WebOsTvPairError
|
||||||
import pytest
|
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.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 homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import setup_webostv
|
from . import setup_webostv
|
||||||
@ -26,8 +30,8 @@ async def test_notify(hass, client):
|
|||||||
TV_NAME,
|
TV_NAME,
|
||||||
{
|
{
|
||||||
ATTR_MESSAGE: MESSAGE,
|
ATTR_MESSAGE: MESSAGE,
|
||||||
CONF_SERVICE_DATA: {
|
ATTR_DATA: {
|
||||||
CONF_ICON: ICON_PATH,
|
ATTR_ICON: ICON_PATH,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
@ -41,7 +45,7 @@ async def test_notify(hass, client):
|
|||||||
TV_NAME,
|
TV_NAME,
|
||||||
{
|
{
|
||||||
ATTR_MESSAGE: MESSAGE,
|
ATTR_MESSAGE: MESSAGE,
|
||||||
CONF_SERVICE_DATA: {
|
ATTR_DATA: {
|
||||||
"OTHER_DATA": "not_used",
|
"OTHER_DATA": "not_used",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -51,6 +55,20 @@ async def test_notify(hass, client):
|
|||||||
assert client.connect.call_count == 1
|
assert client.connect.call_count == 1
|
||||||
client.send_message.assert_called_with(MESSAGE, icon_path=None)
|
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):
|
async def test_notify_not_connected(hass, client, monkeypatch):
|
||||||
"""Test sending a message when client is not connected."""
|
"""Test sending a message when client is not connected."""
|
||||||
@ -63,8 +81,8 @@ async def test_notify_not_connected(hass, client, monkeypatch):
|
|||||||
TV_NAME,
|
TV_NAME,
|
||||||
{
|
{
|
||||||
ATTR_MESSAGE: MESSAGE,
|
ATTR_MESSAGE: MESSAGE,
|
||||||
CONF_SERVICE_DATA: {
|
ATTR_DATA: {
|
||||||
CONF_ICON: ICON_PATH,
|
ATTR_ICON: ICON_PATH,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
@ -85,8 +103,8 @@ async def test_icon_not_found(hass, caplog, client, monkeypatch):
|
|||||||
TV_NAME,
|
TV_NAME,
|
||||||
{
|
{
|
||||||
ATTR_MESSAGE: MESSAGE,
|
ATTR_MESSAGE: MESSAGE,
|
||||||
CONF_SERVICE_DATA: {
|
ATTR_DATA: {
|
||||||
CONF_ICON: ICON_PATH,
|
ATTR_ICON: ICON_PATH,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
@ -116,8 +134,8 @@ async def test_connection_errors(hass, caplog, client, monkeypatch, side_effect,
|
|||||||
TV_NAME,
|
TV_NAME,
|
||||||
{
|
{
|
||||||
ATTR_MESSAGE: MESSAGE,
|
ATTR_MESSAGE: MESSAGE,
|
||||||
CONF_SERVICE_DATA: {
|
ATTR_DATA: {
|
||||||
CONF_ICON: ICON_PATH,
|
ATTR_ICON: ICON_PATH,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user