Skip to content

Commit

Permalink
Fix attribute error for media_player/roku if roku device is unreachab…
Browse files Browse the repository at this point in the history
…le and shows a persistent notification (#5785) (#5786)
  • Loading branch information
tchellomello authored and balloob committed Feb 7, 2017
1 parent 34c7bac commit 305d261
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions homeassistant/components/media_player/roku.py
Expand Up @@ -15,6 +15,7 @@
from homeassistant.const import (
CONF_HOST, STATE_IDLE, STATE_PLAYING, STATE_UNKNOWN, STATE_HOME)
import homeassistant.helpers.config_validation as cv
import homeassistant.loader as loader

REQUIREMENTS = [
'https://github.com/bah2830/python-roku/archive/3.1.3.zip'
Expand All @@ -23,6 +24,9 @@
KNOWN_HOSTS = []
DEFAULT_PORT = 8060

NOTIFICATION_ID = 'roku_notification'
NOTIFICATION_TITLE = 'Roku Media Player Setup'

_LOGGER = logging.getLogger(__name__)

SUPPORT_ROKU = SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK |\
Expand All @@ -48,15 +52,28 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
elif CONF_HOST in config:
hosts.append(config.get(CONF_HOST))

persistent_notification = loader.get_component('persistent_notification')
rokus = []
for host in hosts:
new_roku = RokuDevice(host)

if new_roku.name is None:
try:
if new_roku.name is not None:
rokus.append(RokuDevice(host))
KNOWN_HOSTS.append(host)
else:
_LOGGER.error("Unable to initialize roku at %s", host)

except AttributeError:
_LOGGER.error("Unable to initialize roku at %s", host)
else:
rokus.append(RokuDevice(host))
KNOWN_HOSTS.append(host)
persistent_notification.create(
hass, 'Error: Unable to initialize roku at {}<br />'
'Check its network connection or consider '
'using auto discovery.<br />'
'You will need to restart hass after fixing.'
''.format(config.get(CONF_HOST)),
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)

add_devices(rokus)

Expand Down

0 comments on commit 305d261

Please sign in to comment.