Fix Notifications for Android TV (#10798)

* Fixed icon path, added dynamic icon

* Addressing requested changes

* Using DEFAULT_ICON

* Using CONF_ICON from const

* Getting hass_frontend path via import

* Lint

* Using embedded 1px transparent icon

* woof -.-

* Lint
This commit is contained in:
Daniel Perna 2017-12-04 00:08:10 +01:00 committed by Paulus Schoutsen
parent 6776e942d7
commit 0d6c95ac44

View File

@ -4,8 +4,9 @@ Notifications for Android TV notification service.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/notify.nfandroidtv/ https://home-assistant.io/components/notify.nfandroidtv/
""" """
import os
import logging import logging
import io
import base64
import requests import requests
import voluptuous as vol import voluptuous as vol
@ -31,6 +32,9 @@ DEFAULT_TRANSPARENCY = 'default'
DEFAULT_COLOR = 'grey' DEFAULT_COLOR = 'grey'
DEFAULT_INTERRUPT = False DEFAULT_INTERRUPT = False
DEFAULT_TIMEOUT = 5 DEFAULT_TIMEOUT = 5
DEFAULT_ICON = (
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApo'
'cMXEAAAAASUVORK5CYII=')
ATTR_DURATION = 'duration' ATTR_DURATION = 'duration'
ATTR_POSITION = 'position' ATTR_POSITION = 'position'
@ -110,16 +114,13 @@ class NFAndroidTVNotificationService(BaseNotificationService):
self._default_color = color self._default_color = color
self._default_interrupt = interrupt self._default_interrupt = interrupt
self._timeout = timeout self._timeout = timeout
self._icon_file = os.path.join( self._icon_file = io.BytesIO(base64.b64decode(DEFAULT_ICON))
os.path.dirname(__file__), '..', 'frontend', 'www_static', 'icons',
'favicon-192x192.png')
def send_message(self, message="", **kwargs): def send_message(self, message="", **kwargs):
"""Send a message to a Android TV device.""" """Send a message to a Android TV device."""
_LOGGER.debug("Sending notification to: %s", self._target) _LOGGER.debug("Sending notification to: %s", self._target)
payload = dict(filename=('icon.png', payload = dict(filename=('icon.png', self._icon_file,
open(self._icon_file, 'rb'),
'application/octet-stream', 'application/octet-stream',
{'Expires': '0'}), type='0', {'Expires': '0'}), type='0',
title=kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT), title=kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
@ -129,7 +130,7 @@ class NFAndroidTVNotificationService(BaseNotificationService):
transparency='%i' % TRANSPARENCIES.get( transparency='%i' % TRANSPARENCIES.get(
self._default_transparency), self._default_transparency),
offset='0', app=ATTR_TITLE_DEFAULT, force='true', offset='0', app=ATTR_TITLE_DEFAULT, force='true',
interrupt='%i' % self._default_interrupt) interrupt='%i' % self._default_interrupt,)
data = kwargs.get(ATTR_DATA) data = kwargs.get(ATTR_DATA)
if data: if data: