mirror of
https://github.com/home-assistant/core
synced 2024-08-02 23:40:32 +02:00
Fix extra data for AWS sns service (#64771)
* Fix extra data for ANS sns service * Add test * apply review comments
This commit is contained in:
parent
c202b24cae
commit
d9e6ce00e0
@ -12,6 +12,7 @@ from homeassistant.components.notify import (
|
|||||||
ATTR_TITLE_DEFAULT,
|
ATTR_TITLE_DEFAULT,
|
||||||
BaseNotificationService,
|
BaseNotificationService,
|
||||||
)
|
)
|
||||||
|
from homeassistant.components.notify.const import ATTR_DATA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PLATFORM,
|
CONF_PLATFORM,
|
||||||
@ -166,11 +167,13 @@ class AWSSNS(AWSNotify):
|
|||||||
_LOGGER.error("At least one target is required")
|
_LOGGER.error("At least one target is required")
|
||||||
return
|
return
|
||||||
|
|
||||||
message_attributes = {
|
message_attributes = {}
|
||||||
k: {"StringValue": json.dumps(v), "DataType": "String"}
|
if data := kwargs.get(ATTR_DATA):
|
||||||
for k, v in kwargs.items()
|
message_attributes = {
|
||||||
if v is not None
|
k: {"StringValue": v, "DataType": "String"}
|
||||||
}
|
for k, v in data.items()
|
||||||
|
if v is not None
|
||||||
|
}
|
||||||
subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
|
|
||||||
async with self.session.create_client(
|
async with self.session.create_client(
|
||||||
|
@ -266,3 +266,51 @@ async def test_credential_skip_validate(hass):
|
|||||||
session = sessions.get("key")
|
session = sessions.get("key")
|
||||||
assert isinstance(session, MockAioSession)
|
assert isinstance(session, MockAioSession)
|
||||||
session.get_user.assert_not_awaited()
|
session.get_user.assert_not_awaited()
|
||||||
|
|
||||||
|
|
||||||
|
async def test_service_call_extra_data(hass):
|
||||||
|
"""Test service call extra data are parsed properly."""
|
||||||
|
with async_patch("homeassistant.components.aws.AioSession", new=MockAioSession):
|
||||||
|
await async_setup_component(
|
||||||
|
hass,
|
||||||
|
"aws",
|
||||||
|
{
|
||||||
|
"aws": {
|
||||||
|
"notify": [
|
||||||
|
{
|
||||||
|
"service": "sns",
|
||||||
|
"name": "SNS Test",
|
||||||
|
"region_name": "us-east-1",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
sessions = hass.data[aws.DATA_SESSIONS]
|
||||||
|
assert sessions is not None
|
||||||
|
assert len(sessions) == 1
|
||||||
|
session = sessions.get("default")
|
||||||
|
assert isinstance(session, MockAioSession)
|
||||||
|
|
||||||
|
assert hass.services.has_service("notify", "sns_test") is True
|
||||||
|
await hass.services.async_call(
|
||||||
|
"notify",
|
||||||
|
"sns_test",
|
||||||
|
{
|
||||||
|
"message": "test",
|
||||||
|
"target": "ARN",
|
||||||
|
"data": {"AWS.SNS.SMS.SenderID": "HA-notify"},
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
session.publish.assert_called_once_with(
|
||||||
|
TargetArn="ARN",
|
||||||
|
Message="test",
|
||||||
|
Subject="Home Assistant",
|
||||||
|
MessageAttributes={
|
||||||
|
"AWS.SNS.SMS.SenderID": {"StringValue": "HA-notify", "DataType": "String"}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user