mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Add nfandroidtv type checking and allow for strings to be passed to the image and icon data (#108652)
* nfandroidtv - add type checking and allow for strings to be passed to the image and icon data
* nfandroidtv - wrong argument name
* nfandroidtv - put the icon in the wrong varible 🙃
* nfandroidtv - raise ServiceValidationError instead of logging
---------
Co-authored-by: nyangogo <7449028+ioangogo@users.noreply.github.com>
This commit is contained in:
parent
d0f5e40b19
commit
c9ff618ef0
@ -19,6 +19,7 @@ from homeassistant.components.notify import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ from .const import (
|
|||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TRANSPARENCY,
|
ATTR_TRANSPARENCY,
|
||||||
DEFAULT_TIMEOUT,
|
DEFAULT_TIMEOUT,
|
||||||
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -133,6 +135,13 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
"Invalid interrupt-value: %s", data.get(ATTR_INTERRUPT)
|
"Invalid interrupt-value: %s", data.get(ATTR_INTERRUPT)
|
||||||
)
|
)
|
||||||
if imagedata := data.get(ATTR_IMAGE):
|
if imagedata := data.get(ATTR_IMAGE):
|
||||||
|
if isinstance(imagedata, str):
|
||||||
|
image_file = (
|
||||||
|
self.load_file(url=imagedata)
|
||||||
|
if imagedata.startswith("http")
|
||||||
|
else self.load_file(local_path=imagedata)
|
||||||
|
)
|
||||||
|
elif isinstance(imagedata, dict):
|
||||||
image_file = self.load_file(
|
image_file = self.load_file(
|
||||||
url=imagedata.get(ATTR_IMAGE_URL),
|
url=imagedata.get(ATTR_IMAGE_URL),
|
||||||
local_path=imagedata.get(ATTR_IMAGE_PATH),
|
local_path=imagedata.get(ATTR_IMAGE_PATH),
|
||||||
@ -140,7 +149,21 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
password=imagedata.get(ATTR_IMAGE_PASSWORD),
|
password=imagedata.get(ATTR_IMAGE_PASSWORD),
|
||||||
auth=imagedata.get(ATTR_IMAGE_AUTH),
|
auth=imagedata.get(ATTR_IMAGE_AUTH),
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
raise ServiceValidationError(
|
||||||
|
"Invalid image provided",
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="invalid_notification_image",
|
||||||
|
translation_placeholders={"type": type(imagedata).__name__},
|
||||||
|
)
|
||||||
if icondata := data.get(ATTR_ICON):
|
if icondata := data.get(ATTR_ICON):
|
||||||
|
if isinstance(icondata, str):
|
||||||
|
icondata = (
|
||||||
|
self.load_file(url=icondata)
|
||||||
|
if icondata.startswith("http")
|
||||||
|
else self.load_file(local_path=icondata)
|
||||||
|
)
|
||||||
|
elif isinstance(icondata, dict):
|
||||||
icon = self.load_file(
|
icon = self.load_file(
|
||||||
url=icondata.get(ATTR_ICON_URL),
|
url=icondata.get(ATTR_ICON_URL),
|
||||||
local_path=icondata.get(ATTR_ICON_PATH),
|
local_path=icondata.get(ATTR_ICON_PATH),
|
||||||
@ -148,6 +171,13 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
password=icondata.get(ATTR_ICON_PASSWORD),
|
password=icondata.get(ATTR_ICON_PASSWORD),
|
||||||
auth=icondata.get(ATTR_ICON_AUTH),
|
auth=icondata.get(ATTR_ICON_AUTH),
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
raise ServiceValidationError(
|
||||||
|
"Invalid Icon provided",
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="invalid_notification_icon",
|
||||||
|
translation_placeholders={"type": type(icondata).__name__},
|
||||||
|
)
|
||||||
self.notify.send(
|
self.notify.send(
|
||||||
message,
|
message,
|
||||||
title=title,
|
title=title,
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
{
|
{
|
||||||
|
"exceptions": {
|
||||||
|
"invalid_notification_icon": {
|
||||||
|
"message": "Invalid icon data provided. Got {type}"
|
||||||
|
},
|
||||||
|
"invalid_notification_image": {
|
||||||
|
"message": "Invalid image data provided. Got {type}"
|
||||||
|
}
|
||||||
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user