From 250523c1d820b3de6b82afc5cf2d3b1285ad0c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20St=C3=A5hl?= Date: Wed, 8 Feb 2017 12:17:23 +0100 Subject: [PATCH] Add discovery suppport to Apple TV (#5801) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an optional extended description… --- homeassistant/components/discovery.py | 1 + .../components/media_player/apple_tv.py | 20 +++++++++++-------- requirements_all.txt | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/discovery.py b/homeassistant/components/discovery.py index 79b5b768801..45a3944e6fe 100644 --- a/homeassistant/components/discovery.py +++ b/homeassistant/components/discovery.py @@ -40,6 +40,7 @@ SERVICE_HANDLERS = { 'samsung_tv': ('media_player', 'samsungtv'), 'yeelight': ('light', 'yeelight'), 'flux_led': ('light', 'flux_led'), + 'apple_tv': ('media_player', 'apple_tv'), } CONFIG_SCHEMA = vol.Schema({ diff --git a/homeassistant/components/media_player/apple_tv.py b/homeassistant/components/media_player/apple_tv.py index acfdac088aa..19700e2f8d7 100644 --- a/homeassistant/components/media_player/apple_tv.py +++ b/homeassistant/components/media_player/apple_tv.py @@ -21,7 +21,7 @@ import homeassistant.helpers.config_validation as cv import homeassistant.util.dt as dt_util -REQUIREMENTS = ['pyatv==0.0.1'] +REQUIREMENTS = ['pyatv==0.1.1'] _LOGGER = logging.getLogger(__name__) @@ -44,17 +44,21 @@ def async_setup_platform(hass, config, async_add_entities, """Setup the Apple TV platform.""" import pyatv + if discovery_info is not None: + name = discovery_info['name'] + host = discovery_info['host'] + login_id = discovery_info['hsgid'] + else: + name = config.get(CONF_NAME) + host = config.get(CONF_HOST) + login_id = config.get(CONF_LOGIN_ID) + if DATA_APPLE_TV not in hass.data: hass.data[DATA_APPLE_TV] = [] - name = config.get(CONF_NAME) - host = config.get(CONF_HOST) - login_id = config.get(CONF_LOGIN_ID) - - key = '{}:{}'.format(host, name) - if key in hass.data[DATA_APPLE_TV]: + if host in hass.data[DATA_APPLE_TV]: return False - hass.data[DATA_APPLE_TV].append(key) + hass.data[DATA_APPLE_TV].append(host) details = pyatv.AppleTVDevice(name, host, login_id) atv = pyatv.connect_to_apple_tv(details, hass.loop) diff --git a/requirements_all.txt b/requirements_all.txt index 5118d9351cb..e93a4565ae3 100755 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -418,7 +418,7 @@ pyasn1-modules==0.0.8 pyasn1==0.2.2 # homeassistant.components.media_player.apple_tv -pyatv==0.0.1 +pyatv==0.1.1 # homeassistant.components.device_tracker.bbox # homeassistant.components.sensor.bbox