Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Notifications for Android TV #10798

Merged
merged 9 commits into from
Dec 3, 2017
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions homeassistant/components/notify/nfandroidtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
"""
import os
import logging
import io
import base64

import requests
import voluptuous as vol

from homeassistant.components.notify import (
ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, BaseNotificationService,
PLATFORM_SCHEMA)
from homeassistant.const import CONF_TIMEOUT
from homeassistant.const import CONF_TIMEOUT, CONF_ICON

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'homeassistant.const.CONF_ICON' imported but unused

import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)
Expand All @@ -31,6 +33,9 @@
DEFAULT_COLOR = 'grey'
DEFAULT_INTERRUPT = False
DEFAULT_TIMEOUT = 5
DEFAULT_ICON = (
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApo'
'cMXEAAAAASUVORK5CYII=')

ATTR_DURATION = 'duration'
ATTR_POSITION = 'position'
Expand Down Expand Up @@ -110,16 +115,13 @@ def __init__(self, remoteip, duration, position, transparency, color,
self._default_color = color
self._default_interrupt = interrupt
self._timeout = timeout
self._icon_file = os.path.join(
os.path.dirname(__file__), '..', 'frontend', 'www_static', 'icons',
'favicon-192x192.png')
self._icon_file = io.BytesIO(base64.b64decode(DEFAULT_ICON))

def send_message(self, message="", **kwargs):
"""Send a message to a Android TV device."""
_LOGGER.debug("Sending notification to: %s", self._target)

payload = dict(filename=('icon.png',
open(self._icon_file, 'rb'),
payload = dict(filename=('icon.png', self._icon_file,
'application/octet-stream',
{'Expires': '0'}), type='0',
title=kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
Expand All @@ -129,7 +131,7 @@ def send_message(self, message="", **kwargs):
transparency='%i' % TRANSPARENCIES.get(
self._default_transparency),
offset='0', app=ATTR_TITLE_DEFAULT, force='true',
interrupt='%i' % self._default_interrupt)
interrupt='%i' % self._default_interrupt,)

data = kwargs.get(ATTR_DATA)
if data:
Expand Down