mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add Notifications for Android TV icon support (#60159)
* Add icon support * Sort imports * Sort imports correctly * Satisfy pylint Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
6b9c2d8295
commit
3399c90936
@ -17,12 +17,20 @@ ATTR_TRANSPARENCY = "transparency"
|
|||||||
ATTR_COLOR = "color"
|
ATTR_COLOR = "color"
|
||||||
ATTR_BKGCOLOR = "bkgcolor"
|
ATTR_BKGCOLOR = "bkgcolor"
|
||||||
ATTR_INTERRUPT = "interrupt"
|
ATTR_INTERRUPT = "interrupt"
|
||||||
ATTR_FILE = "file"
|
ATTR_IMAGE = "image"
|
||||||
# Attributes contained in file
|
# Attributes contained in image
|
||||||
ATTR_FILE_URL = "url"
|
ATTR_IMAGE_URL = "url"
|
||||||
ATTR_FILE_PATH = "path"
|
ATTR_IMAGE_PATH = "path"
|
||||||
ATTR_FILE_USERNAME = "username"
|
ATTR_IMAGE_USERNAME = "username"
|
||||||
ATTR_FILE_PASSWORD = "password"
|
ATTR_IMAGE_PASSWORD = "password"
|
||||||
ATTR_FILE_AUTH = "auth"
|
ATTR_IMAGE_AUTH = "auth"
|
||||||
|
ATTR_ICON = "icon"
|
||||||
|
# Attributes contained in icon
|
||||||
|
ATTR_ICON_URL = "url"
|
||||||
|
ATTR_ICON_PATH = "path"
|
||||||
|
ATTR_ICON_USERNAME = "username"
|
||||||
|
ATTR_ICON_PASSWORD = "password"
|
||||||
|
ATTR_ICON_AUTH = "auth"
|
||||||
# Any other value or absence of 'auth' lead to basic authentication being used
|
# Any other value or absence of 'auth' lead to basic authentication being used
|
||||||
ATTR_FILE_AUTH_DIGEST = "digest"
|
ATTR_IMAGE_AUTH_DIGEST = "digest"
|
||||||
|
ATTR_ICON_AUTH_DIGEST = "digest"
|
||||||
|
@ -16,7 +16,7 @@ from homeassistant.components.notify import (
|
|||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
BaseNotificationService,
|
BaseNotificationService,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ICON, CONF_HOST, CONF_TIMEOUT
|
from homeassistant.const import CONF_HOST, CONF_TIMEOUT
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
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
|
||||||
@ -24,14 +24,21 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|||||||
from .const import (
|
from .const import (
|
||||||
ATTR_COLOR,
|
ATTR_COLOR,
|
||||||
ATTR_DURATION,
|
ATTR_DURATION,
|
||||||
ATTR_FILE,
|
|
||||||
ATTR_FILE_AUTH,
|
|
||||||
ATTR_FILE_AUTH_DIGEST,
|
|
||||||
ATTR_FILE_PASSWORD,
|
|
||||||
ATTR_FILE_PATH,
|
|
||||||
ATTR_FILE_URL,
|
|
||||||
ATTR_FILE_USERNAME,
|
|
||||||
ATTR_FONTSIZE,
|
ATTR_FONTSIZE,
|
||||||
|
ATTR_ICON,
|
||||||
|
ATTR_ICON_AUTH,
|
||||||
|
ATTR_ICON_AUTH_DIGEST,
|
||||||
|
ATTR_ICON_PASSWORD,
|
||||||
|
ATTR_ICON_PATH,
|
||||||
|
ATTR_ICON_URL,
|
||||||
|
ATTR_ICON_USERNAME,
|
||||||
|
ATTR_IMAGE,
|
||||||
|
ATTR_IMAGE_AUTH,
|
||||||
|
ATTR_IMAGE_AUTH_DIGEST,
|
||||||
|
ATTR_IMAGE_PASSWORD,
|
||||||
|
ATTR_IMAGE_PATH,
|
||||||
|
ATTR_IMAGE_URL,
|
||||||
|
ATTR_IMAGE_USERNAME,
|
||||||
ATTR_INTERRUPT,
|
ATTR_INTERRUPT,
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
ATTR_TRANSPARENCY,
|
ATTR_TRANSPARENCY,
|
||||||
@ -158,22 +165,23 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Invalid interrupt-value: %s", str(data.get(ATTR_INTERRUPT))
|
"Invalid interrupt-value: %s", str(data.get(ATTR_INTERRUPT))
|
||||||
)
|
)
|
||||||
filedata = data.get(ATTR_FILE) if data else None
|
imagedata = data.get(ATTR_IMAGE) if data else None
|
||||||
if filedata is not None:
|
if imagedata is not None:
|
||||||
if ATTR_ICON in filedata:
|
|
||||||
icon = self.load_file(
|
|
||||||
url=filedata[ATTR_ICON],
|
|
||||||
local_path=filedata.get(ATTR_FILE_PATH),
|
|
||||||
username=filedata.get(ATTR_FILE_USERNAME),
|
|
||||||
password=filedata.get(ATTR_FILE_PASSWORD),
|
|
||||||
auth=filedata.get(ATTR_FILE_AUTH),
|
|
||||||
)
|
|
||||||
image_file = self.load_file(
|
image_file = self.load_file(
|
||||||
url=filedata.get(ATTR_FILE_URL),
|
url=imagedata.get(ATTR_IMAGE_URL),
|
||||||
local_path=filedata.get(ATTR_FILE_PATH),
|
local_path=imagedata.get(ATTR_IMAGE_PATH),
|
||||||
username=filedata.get(ATTR_FILE_USERNAME),
|
username=imagedata.get(ATTR_IMAGE_USERNAME),
|
||||||
password=filedata.get(ATTR_FILE_PASSWORD),
|
password=imagedata.get(ATTR_IMAGE_PASSWORD),
|
||||||
auth=filedata.get(ATTR_FILE_AUTH),
|
auth=imagedata.get(ATTR_IMAGE_AUTH),
|
||||||
|
)
|
||||||
|
icondata = data.get(ATTR_ICON) if data else None
|
||||||
|
if icondata is not None:
|
||||||
|
icon = self.load_file(
|
||||||
|
url=icondata.get(ATTR_ICON_URL),
|
||||||
|
local_path=icondata.get(ATTR_ICON_PATH),
|
||||||
|
username=icondata.get(ATTR_ICON_USERNAME),
|
||||||
|
password=icondata.get(ATTR_ICON_PASSWORD),
|
||||||
|
auth=icondata.get(ATTR_ICON_AUTH),
|
||||||
)
|
)
|
||||||
self.notify.send(
|
self.notify.send(
|
||||||
message,
|
message,
|
||||||
@ -203,7 +211,7 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
if username is not None and password is not None:
|
if username is not None and password is not None:
|
||||||
# Use digest or basic authentication
|
# Use digest or basic authentication
|
||||||
auth_: HTTPDigestAuth | HTTPBasicAuth
|
auth_: HTTPDigestAuth | HTTPBasicAuth
|
||||||
if ATTR_FILE_AUTH_DIGEST == auth:
|
if auth in (ATTR_IMAGE_AUTH_DIGEST, ATTR_ICON_AUTH_DIGEST):
|
||||||
auth_ = HTTPDigestAuth(username, password)
|
auth_ = HTTPDigestAuth(username, password)
|
||||||
else:
|
else:
|
||||||
auth_ = HTTPBasicAuth(username, password)
|
auth_ = HTTPBasicAuth(username, password)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user