Support specifying no Apple TVs (#9394)
This commit is contained in:
parent
c8da95c1e8
commit
f5ffef3f72
1 changed files with 26 additions and 10 deletions
|
@ -10,6 +10,7 @@ import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from typing import Union, TypeVar, Sequence
|
||||||
from homeassistant.const import (CONF_HOST, CONF_NAME, ATTR_ENTITY_ID)
|
from homeassistant.const import (CONF_HOST, CONF_NAME, ATTR_ENTITY_ID)
|
||||||
from homeassistant.config import load_yaml_config_file
|
from homeassistant.config import load_yaml_config_file
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
@ -45,8 +46,19 @@ NOTIFICATION_AUTH_TITLE = 'Apple TV Authentication'
|
||||||
NOTIFICATION_SCAN_ID = 'apple_tv_scan_notification'
|
NOTIFICATION_SCAN_ID = 'apple_tv_scan_notification'
|
||||||
NOTIFICATION_SCAN_TITLE = 'Apple TV Scan'
|
NOTIFICATION_SCAN_TITLE = 'Apple TV Scan'
|
||||||
|
|
||||||
|
T = TypeVar('T')
|
||||||
|
|
||||||
|
|
||||||
|
# This version of ensure_list interprets an empty dict as no value
|
||||||
|
def ensure_list(value: Union[T, Sequence[T]]) -> Sequence[T]:
|
||||||
|
"""Wrap value in list if it is not one."""
|
||||||
|
if value is None or (isinstance(value, dict) and not value):
|
||||||
|
return []
|
||||||
|
return value if isinstance(value, list) else [value]
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.All(cv.ensure_list, [vol.Schema({
|
DOMAIN: vol.All(ensure_list, [vol.Schema({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
vol.Required(CONF_LOGIN_ID): cv.string,
|
vol.Required(CONF_LOGIN_ID): cv.string,
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
@ -133,6 +145,10 @@ def async_setup(hass, config):
|
||||||
"""Handler for service calls."""
|
"""Handler for service calls."""
|
||||||
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
entity_ids = service.data.get(ATTR_ENTITY_ID)
|
||||||
|
|
||||||
|
if service.service == SERVICE_SCAN:
|
||||||
|
hass.async_add_job(scan_for_apple_tvs, hass)
|
||||||
|
return
|
||||||
|
|
||||||
if entity_ids:
|
if entity_ids:
|
||||||
devices = [device for device in hass.data[DATA_ENTITIES]
|
devices = [device for device in hass.data[DATA_ENTITIES]
|
||||||
if device.entity_id in entity_ids]
|
if device.entity_id in entity_ids]
|
||||||
|
@ -140,16 +156,16 @@ def async_setup(hass, config):
|
||||||
devices = hass.data[DATA_ENTITIES]
|
devices = hass.data[DATA_ENTITIES]
|
||||||
|
|
||||||
for device in devices:
|
for device in devices:
|
||||||
|
if service.service != SERVICE_AUTHENTICATE:
|
||||||
|
continue
|
||||||
|
|
||||||
atv = device.atv
|
atv = device.atv
|
||||||
if service.service == SERVICE_AUTHENTICATE:
|
credentials = yield from atv.airplay.generate_credentials()
|
||||||
credentials = yield from atv.airplay.generate_credentials()
|
yield from atv.airplay.load_credentials(credentials)
|
||||||
yield from atv.airplay.load_credentials(credentials)
|
_LOGGER.debug('Generated new credentials: %s', credentials)
|
||||||
_LOGGER.debug('Generated new credentials: %s', credentials)
|
yield from atv.airplay.start_authentication()
|
||||||
yield from atv.airplay.start_authentication()
|
hass.async_add_job(request_configuration,
|
||||||
hass.async_add_job(request_configuration,
|
hass, config, atv, credentials)
|
||||||
hass, config, atv, credentials)
|
|
||||||
elif service.service == SERVICE_SCAN:
|
|
||||||
hass.async_add_job(scan_for_apple_tvs, hass)
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def atv_discovered(service, info):
|
def atv_discovered(service, info):
|
||||||
|
|
Loading…
Add table
Reference in a new issue