commit
5e9c1098c0
|
@ -1,4 +1,5 @@
|
||||||
"""Component to embed Google Cast."""
|
"""Component to embed Google Cast."""
|
||||||
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.helpers import config_entry_flow
|
from homeassistant.helpers import config_entry_flow
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +9,14 @@ REQUIREMENTS = ['pychromecast==2.1.0']
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the Cast component."""
|
"""Set up the Cast component."""
|
||||||
hass.data[DOMAIN] = config.get(DOMAIN, {})
|
conf = config.get(DOMAIN)
|
||||||
|
|
||||||
|
hass.data[DOMAIN] = conf or {}
|
||||||
|
|
||||||
|
if conf is not None:
|
||||||
|
hass.async_create_task(hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, source=data_entry_flow.SOURCE_IMPORT))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ from homeassistant.util.yaml import load_yaml
|
||||||
REQUIREMENTS = ['home-assistant-frontend==20180720.0']
|
REQUIREMENTS = ['home-assistant-frontend==20180720.0']
|
||||||
|
|
||||||
DOMAIN = 'frontend'
|
DOMAIN = 'frontend'
|
||||||
DEPENDENCIES = ['api', 'websocket_api', 'http', 'system_log', 'onboarding']
|
DEPENDENCIES = ['api', 'websocket_api', 'http', 'system_log',
|
||||||
|
'auth', 'onboarding']
|
||||||
|
|
||||||
CONF_THEMES = 'themes'
|
CONF_THEMES = 'themes'
|
||||||
CONF_EXTRA_HTML_URL = 'extra_html_url'
|
CONF_EXTRA_HTML_URL = 'extra_html_url'
|
||||||
|
|
|
@ -21,9 +21,10 @@ from homeassistant.helpers.entityfilter import FILTER_SCHEMA
|
||||||
from homeassistant.util import get_local_ip
|
from homeassistant.util import get_local_ip
|
||||||
from homeassistant.util.decorator import Registry
|
from homeassistant.util.decorator import Registry
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_AUTO_START, CONF_ENTITY_CONFIG, CONF_FEATURE_LIST, CONF_FILTER,
|
BRIDGE_NAME, CONF_AUTO_START, CONF_ENTITY_CONFIG, CONF_FEATURE_LIST,
|
||||||
DEFAULT_AUTO_START, DEFAULT_PORT, DEVICE_CLASS_CO2, DEVICE_CLASS_PM25,
|
CONF_FILTER, DEFAULT_AUTO_START, DEFAULT_PORT, DEVICE_CLASS_CO2,
|
||||||
DOMAIN, HOMEKIT_FILE, SERVICE_HOMEKIT_START, TYPE_OUTLET, TYPE_SWITCH)
|
DEVICE_CLASS_PM25, DOMAIN, HOMEKIT_FILE, SERVICE_HOMEKIT_START,
|
||||||
|
TYPE_OUTLET, TYPE_SWITCH)
|
||||||
from .util import (
|
from .util import (
|
||||||
show_setup_message, validate_entity_config, validate_media_player_features)
|
show_setup_message, validate_entity_config, validate_media_player_features)
|
||||||
|
|
||||||
|
@ -43,6 +44,8 @@ SWITCH_TYPES = {TYPE_OUTLET: 'Outlet',
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.All({
|
DOMAIN: vol.All({
|
||||||
|
vol.Optional(CONF_NAME, default=BRIDGE_NAME):
|
||||||
|
vol.All(cv.string, vol.Length(min=3, max=25)),
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
vol.Optional(CONF_IP_ADDRESS):
|
vol.Optional(CONF_IP_ADDRESS):
|
||||||
vol.All(ipaddress.ip_address, cv.string),
|
vol.All(ipaddress.ip_address, cv.string),
|
||||||
|
@ -58,13 +61,15 @@ async def async_setup(hass, config):
|
||||||
_LOGGER.debug('Begin setup HomeKit')
|
_LOGGER.debug('Begin setup HomeKit')
|
||||||
|
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
|
name = conf[CONF_NAME]
|
||||||
port = conf[CONF_PORT]
|
port = conf[CONF_PORT]
|
||||||
ip_address = conf.get(CONF_IP_ADDRESS)
|
ip_address = conf.get(CONF_IP_ADDRESS)
|
||||||
auto_start = conf[CONF_AUTO_START]
|
auto_start = conf[CONF_AUTO_START]
|
||||||
entity_filter = conf[CONF_FILTER]
|
entity_filter = conf[CONF_FILTER]
|
||||||
entity_config = conf[CONF_ENTITY_CONFIG]
|
entity_config = conf[CONF_ENTITY_CONFIG]
|
||||||
|
|
||||||
homekit = HomeKit(hass, port, ip_address, entity_filter, entity_config)
|
homekit = HomeKit(hass, name, port, ip_address, entity_filter,
|
||||||
|
entity_config)
|
||||||
await hass.async_add_job(homekit.setup)
|
await hass.async_add_job(homekit.setup)
|
||||||
|
|
||||||
if auto_start:
|
if auto_start:
|
||||||
|
@ -176,9 +181,11 @@ def generate_aid(entity_id):
|
||||||
class HomeKit():
|
class HomeKit():
|
||||||
"""Class to handle all actions between HomeKit and Home Assistant."""
|
"""Class to handle all actions between HomeKit and Home Assistant."""
|
||||||
|
|
||||||
def __init__(self, hass, port, ip_address, entity_filter, entity_config):
|
def __init__(self, hass, name, port, ip_address, entity_filter,
|
||||||
|
entity_config):
|
||||||
"""Initialize a HomeKit object."""
|
"""Initialize a HomeKit object."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
|
self._name = name
|
||||||
self._port = port
|
self._port = port
|
||||||
self._ip_address = ip_address
|
self._ip_address = ip_address
|
||||||
self._filter = entity_filter
|
self._filter = entity_filter
|
||||||
|
@ -199,7 +206,7 @@ class HomeKit():
|
||||||
path = self.hass.config.path(HOMEKIT_FILE)
|
path = self.hass.config.path(HOMEKIT_FILE)
|
||||||
self.driver = HomeDriver(self.hass, address=ip_addr,
|
self.driver = HomeDriver(self.hass, address=ip_addr,
|
||||||
port=self._port, persist_file=path)
|
port=self._port, persist_file=path)
|
||||||
self.bridge = HomeBridge(self.hass, self.driver)
|
self.bridge = HomeBridge(self.hass, self.driver, self._name)
|
||||||
|
|
||||||
def add_bridge_accessory(self, state):
|
def add_bridge_accessory(self, state):
|
||||||
"""Try adding accessory to bridge if configured beforehand."""
|
"""Try adding accessory to bridge if configured beforehand."""
|
||||||
|
|
|
@ -17,7 +17,7 @@ from homeassistant.helpers.event import (
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
BRIDGE_MODEL, BRIDGE_NAME, BRIDGE_SERIAL_NUMBER, CHAR_BATTERY_LEVEL,
|
BRIDGE_MODEL, BRIDGE_SERIAL_NUMBER, CHAR_BATTERY_LEVEL,
|
||||||
CHAR_CHARGING_STATE, CHAR_STATUS_LOW_BATTERY, DEBOUNCE_TIMEOUT,
|
CHAR_CHARGING_STATE, CHAR_STATUS_LOW_BATTERY, DEBOUNCE_TIMEOUT,
|
||||||
MANUFACTURER, SERV_BATTERY_SERVICE)
|
MANUFACTURER, SERV_BATTERY_SERVICE)
|
||||||
from .util import (
|
from .util import (
|
||||||
|
@ -141,7 +141,7 @@ class HomeAccessory(Accessory):
|
||||||
class HomeBridge(Bridge):
|
class HomeBridge(Bridge):
|
||||||
"""Adapter class for Bridge."""
|
"""Adapter class for Bridge."""
|
||||||
|
|
||||||
def __init__(self, hass, driver, name=BRIDGE_NAME):
|
def __init__(self, hass, driver, name):
|
||||||
"""Initialize a Bridge object."""
|
"""Initialize a Bridge object."""
|
||||||
super().__init__(driver, name)
|
super().__init__(driver, name)
|
||||||
self.set_info_service(
|
self.set_info_service(
|
||||||
|
|
|
@ -865,9 +865,10 @@ class SonosDevice(MediaPlayerDevice):
|
||||||
"""List of available input sources."""
|
"""List of available input sources."""
|
||||||
sources = [fav.title for fav in self._favorites]
|
sources = [fav.title for fav in self._favorites]
|
||||||
|
|
||||||
if 'PLAY:5' in self._model or 'CONNECT' in self._model:
|
model = self._model.upper()
|
||||||
|
if 'PLAY:5' in model or 'CONNECT' in model:
|
||||||
sources += [SOURCE_LINEIN]
|
sources += [SOURCE_LINEIN]
|
||||||
elif 'PLAYBAR' in self._model:
|
elif 'PLAYBAR' in model:
|
||||||
sources += [SOURCE_LINEIN, SOURCE_TV]
|
sources += [SOURCE_LINEIN, SOURCE_TV]
|
||||||
|
|
||||||
return sources
|
return sources
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Component to embed Sonos."""
|
"""Component to embed Sonos."""
|
||||||
|
from homeassistant import data_entry_flow
|
||||||
from homeassistant.helpers import config_entry_flow
|
from homeassistant.helpers import config_entry_flow
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +9,14 @@ REQUIREMENTS = ['SoCo==0.14']
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the Sonos component."""
|
"""Set up the Sonos component."""
|
||||||
hass.data[DOMAIN] = config.get(DOMAIN, {})
|
conf = config.get(DOMAIN)
|
||||||
|
|
||||||
|
hass.data[DOMAIN] = conf or {}
|
||||||
|
|
||||||
|
if conf is not None:
|
||||||
|
hass.async_create_task(hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, source=data_entry_flow.SOURCE_IMPORT))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"""Constants used by Home Assistant components."""
|
"""Constants used by Home Assistant components."""
|
||||||
MAJOR_VERSION = 0
|
MAJOR_VERSION = 0
|
||||||
MINOR_VERSION = 74
|
MINOR_VERSION = 74
|
||||||
PATCH_VERSION = '0'
|
PATCH_VERSION = '1'
|
||||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||||
REQUIRED_PYTHON_VER = (3, 5, 3)
|
REQUIRED_PYTHON_VER = (3, 5, 3)
|
||||||
|
|
|
@ -72,6 +72,18 @@ class DiscoveryFlowHandler(data_entry_flow.FlowHandler):
|
||||||
|
|
||||||
return await self.async_step_confirm()
|
return await self.async_step_confirm()
|
||||||
|
|
||||||
|
async def async_step_import(self, _):
|
||||||
|
"""Handle a flow initialized by import."""
|
||||||
|
if self._async_in_progress() or self._async_current_entries():
|
||||||
|
return self.async_abort(
|
||||||
|
reason='single_instance_allowed'
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.async_create_entry(
|
||||||
|
title=self._title,
|
||||||
|
data={},
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_current_entries(self):
|
def _async_current_entries(self):
|
||||||
"""Return current entries."""
|
"""Return current entries."""
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.components import cast
|
from homeassistant.components import cast
|
||||||
|
|
||||||
from tests.common import MockDependency, mock_coro
|
from tests.common import MockDependency, mock_coro
|
||||||
|
@ -20,3 +21,33 @@ async def test_creating_entry_sets_up_media_player(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_configuring_cast_creates_entry(hass):
|
||||||
|
"""Test that specifying config will create an entry."""
|
||||||
|
with patch('homeassistant.components.cast.async_setup_entry',
|
||||||
|
return_value=mock_coro(True)) as mock_setup, \
|
||||||
|
MockDependency('pychromecast', 'discovery'), \
|
||||||
|
patch('pychromecast.discovery.discover_chromecasts',
|
||||||
|
return_value=True):
|
||||||
|
await async_setup_component(hass, cast.DOMAIN, {
|
||||||
|
'cast': {
|
||||||
|
'some_config': 'to_trigger_import'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_not_configuring_cast_not_creates_entry(hass):
|
||||||
|
"""Test that no config will not create an entry."""
|
||||||
|
with patch('homeassistant.components.cast.async_setup_entry',
|
||||||
|
return_value=mock_coro(True)) as mock_setup, \
|
||||||
|
MockDependency('pychromecast', 'discovery'), \
|
||||||
|
patch('pychromecast.discovery.discover_chromecasts',
|
||||||
|
return_value=True):
|
||||||
|
await async_setup_component(hass, cast.DOMAIN, {})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(mock_setup.mock_calls) == 0
|
||||||
|
|
|
@ -336,3 +336,15 @@ async def test_lovelace_ui_load_err(hass, hass_ws_client):
|
||||||
assert msg['type'] == wapi.TYPE_RESULT
|
assert msg['type'] == wapi.TYPE_RESULT
|
||||||
assert msg['success'] is False
|
assert msg['success'] is False
|
||||||
assert msg['error']['code'] == 'load_error'
|
assert msg['error']['code'] == 'load_error'
|
||||||
|
|
||||||
|
|
||||||
|
async def test_auth_load(mock_http_client):
|
||||||
|
"""Test auth component loaded by default."""
|
||||||
|
resp = await mock_http_client.get('/auth/providers')
|
||||||
|
assert resp.status == 200
|
||||||
|
|
||||||
|
|
||||||
|
async def test_onboarding_load(mock_http_client):
|
||||||
|
"""Test onboarding component loaded by default."""
|
||||||
|
resp = await mock_http_client.get('/api/onboarding')
|
||||||
|
assert resp.status == 200
|
||||||
|
|
|
@ -146,7 +146,7 @@ async def test_battery_service(hass, hk_driver):
|
||||||
|
|
||||||
def test_home_bridge(hk_driver):
|
def test_home_bridge(hk_driver):
|
||||||
"""Test HomeBridge class."""
|
"""Test HomeBridge class."""
|
||||||
bridge = HomeBridge('hass', hk_driver)
|
bridge = HomeBridge('hass', hk_driver, BRIDGE_NAME)
|
||||||
assert bridge.hass == 'hass'
|
assert bridge.hass == 'hass'
|
||||||
assert bridge.display_name == BRIDGE_NAME
|
assert bridge.display_name == BRIDGE_NAME
|
||||||
assert bridge.category == 2 # Category.BRIDGE
|
assert bridge.category == 2 # Category.BRIDGE
|
||||||
|
|
|
@ -9,9 +9,10 @@ from homeassistant.components.homekit import (
|
||||||
STATUS_STOPPED, STATUS_WAIT)
|
STATUS_STOPPED, STATUS_WAIT)
|
||||||
from homeassistant.components.homekit.accessories import HomeBridge
|
from homeassistant.components.homekit.accessories import HomeBridge
|
||||||
from homeassistant.components.homekit.const import (
|
from homeassistant.components.homekit.const import (
|
||||||
CONF_AUTO_START, DEFAULT_PORT, DOMAIN, HOMEKIT_FILE, SERVICE_HOMEKIT_START)
|
CONF_AUTO_START, BRIDGE_NAME, DEFAULT_PORT, DOMAIN, HOMEKIT_FILE,
|
||||||
|
SERVICE_HOMEKIT_START)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_IP_ADDRESS, CONF_PORT,
|
CONF_NAME, CONF_IP_ADDRESS, CONF_PORT,
|
||||||
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
from homeassistant.helpers.entityfilter import generate_filter
|
from homeassistant.helpers.entityfilter import generate_filter
|
||||||
|
@ -47,7 +48,8 @@ async def test_setup_min(hass):
|
||||||
assert await setup.async_setup_component(
|
assert await setup.async_setup_component(
|
||||||
hass, DOMAIN, {DOMAIN: {}})
|
hass, DOMAIN, {DOMAIN: {}})
|
||||||
|
|
||||||
mock_homekit.assert_any_call(hass, DEFAULT_PORT, None, ANY, {})
|
mock_homekit.assert_any_call(hass, BRIDGE_NAME, DEFAULT_PORT, None, ANY,
|
||||||
|
{})
|
||||||
assert mock_homekit().setup.called is True
|
assert mock_homekit().setup.called is True
|
||||||
|
|
||||||
# Test auto start enabled
|
# Test auto start enabled
|
||||||
|
@ -60,15 +62,16 @@ async def test_setup_min(hass):
|
||||||
|
|
||||||
async def test_setup_auto_start_disabled(hass):
|
async def test_setup_auto_start_disabled(hass):
|
||||||
"""Test async_setup with auto start disabled and test service calls."""
|
"""Test async_setup with auto start disabled and test service calls."""
|
||||||
config = {DOMAIN: {CONF_AUTO_START: False, CONF_PORT: 11111,
|
config = {DOMAIN: {CONF_AUTO_START: False, CONF_NAME: 'Test Name',
|
||||||
CONF_IP_ADDRESS: '172.0.0.0'}}
|
CONF_PORT: 11111, CONF_IP_ADDRESS: '172.0.0.0'}}
|
||||||
|
|
||||||
with patch(PATH_HOMEKIT + '.HomeKit') as mock_homekit:
|
with patch(PATH_HOMEKIT + '.HomeKit') as mock_homekit:
|
||||||
mock_homekit.return_value = homekit = Mock()
|
mock_homekit.return_value = homekit = Mock()
|
||||||
assert await setup.async_setup_component(
|
assert await setup.async_setup_component(
|
||||||
hass, DOMAIN, config)
|
hass, DOMAIN, config)
|
||||||
|
|
||||||
mock_homekit.assert_any_call(hass, 11111, '172.0.0.0', ANY, {})
|
mock_homekit.assert_any_call(hass, 'Test Name', 11111, '172.0.0.0', ANY,
|
||||||
|
{})
|
||||||
assert mock_homekit().setup.called is True
|
assert mock_homekit().setup.called is True
|
||||||
|
|
||||||
# Test auto_start disabled
|
# Test auto_start disabled
|
||||||
|
@ -96,7 +99,7 @@ async def test_setup_auto_start_disabled(hass):
|
||||||
|
|
||||||
async def test_homekit_setup(hass, hk_driver):
|
async def test_homekit_setup(hass, hk_driver):
|
||||||
"""Test setup of bridge and driver."""
|
"""Test setup of bridge and driver."""
|
||||||
homekit = HomeKit(hass, DEFAULT_PORT, None, {}, {})
|
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, None, {}, {})
|
||||||
|
|
||||||
with patch(PATH_HOMEKIT + '.accessories.HomeDriver',
|
with patch(PATH_HOMEKIT + '.accessories.HomeDriver',
|
||||||
return_value=hk_driver) as mock_driver, \
|
return_value=hk_driver) as mock_driver, \
|
||||||
|
@ -115,7 +118,7 @@ async def test_homekit_setup(hass, hk_driver):
|
||||||
|
|
||||||
async def test_homekit_setup_ip_address(hass, hk_driver):
|
async def test_homekit_setup_ip_address(hass, hk_driver):
|
||||||
"""Test setup with given IP address."""
|
"""Test setup with given IP address."""
|
||||||
homekit = HomeKit(hass, DEFAULT_PORT, '172.0.0.0', {}, {})
|
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, '172.0.0.0', {}, {})
|
||||||
|
|
||||||
with patch(PATH_HOMEKIT + '.accessories.HomeDriver',
|
with patch(PATH_HOMEKIT + '.accessories.HomeDriver',
|
||||||
return_value=hk_driver) as mock_driver:
|
return_value=hk_driver) as mock_driver:
|
||||||
|
@ -126,7 +129,7 @@ async def test_homekit_setup_ip_address(hass, hk_driver):
|
||||||
|
|
||||||
async def test_homekit_add_accessory():
|
async def test_homekit_add_accessory():
|
||||||
"""Add accessory if config exists and get_acc returns an accessory."""
|
"""Add accessory if config exists and get_acc returns an accessory."""
|
||||||
homekit = HomeKit('hass', None, None, lambda entity_id: True, {})
|
homekit = HomeKit('hass', None, None, None, lambda entity_id: True, {})
|
||||||
homekit.driver = 'driver'
|
homekit.driver = 'driver'
|
||||||
homekit.bridge = mock_bridge = Mock()
|
homekit.bridge = mock_bridge = Mock()
|
||||||
|
|
||||||
|
@ -149,7 +152,7 @@ async def test_homekit_add_accessory():
|
||||||
async def test_homekit_entity_filter(hass):
|
async def test_homekit_entity_filter(hass):
|
||||||
"""Test the entity filter."""
|
"""Test the entity filter."""
|
||||||
entity_filter = generate_filter(['cover'], ['demo.test'], [], [])
|
entity_filter = generate_filter(['cover'], ['demo.test'], [], [])
|
||||||
homekit = HomeKit(hass, None, None, entity_filter, {})
|
homekit = HomeKit(hass, None, None, None, entity_filter, {})
|
||||||
|
|
||||||
with patch(PATH_HOMEKIT + '.get_accessory') as mock_get_acc:
|
with patch(PATH_HOMEKIT + '.get_accessory') as mock_get_acc:
|
||||||
mock_get_acc.return_value = None
|
mock_get_acc.return_value = None
|
||||||
|
@ -169,7 +172,7 @@ async def test_homekit_entity_filter(hass):
|
||||||
async def test_homekit_start(hass, hk_driver, debounce_patcher):
|
async def test_homekit_start(hass, hk_driver, debounce_patcher):
|
||||||
"""Test HomeKit start method."""
|
"""Test HomeKit start method."""
|
||||||
pin = b'123-45-678'
|
pin = b'123-45-678'
|
||||||
homekit = HomeKit(hass, None, None, {}, {'cover.demo': {}})
|
homekit = HomeKit(hass, None, None, None, {}, {'cover.demo': {}})
|
||||||
homekit.bridge = 'bridge'
|
homekit.bridge = 'bridge'
|
||||||
homekit.driver = hk_driver
|
homekit.driver = hk_driver
|
||||||
|
|
||||||
|
@ -199,7 +202,7 @@ async def test_homekit_start(hass, hk_driver, debounce_patcher):
|
||||||
|
|
||||||
async def test_homekit_stop(hass):
|
async def test_homekit_stop(hass):
|
||||||
"""Test HomeKit stop method."""
|
"""Test HomeKit stop method."""
|
||||||
homekit = HomeKit(hass, None, None, None, None)
|
homekit = HomeKit(hass, None, None, None, None, None)
|
||||||
homekit.driver = Mock()
|
homekit.driver = Mock()
|
||||||
|
|
||||||
assert homekit.status == STATUS_READY
|
assert homekit.status == STATUS_READY
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import data_entry_flow
|
from homeassistant import data_entry_flow
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.components import sonos
|
from homeassistant.components import sonos
|
||||||
|
|
||||||
from tests.common import mock_coro
|
from tests.common import mock_coro
|
||||||
|
@ -18,3 +19,29 @@ async def test_creating_entry_sets_up_media_player(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_configuring_sonos_creates_entry(hass):
|
||||||
|
"""Test that specifying config will create an entry."""
|
||||||
|
with patch('homeassistant.components.sonos.async_setup_entry',
|
||||||
|
return_value=mock_coro(True)) as mock_setup, \
|
||||||
|
patch('soco.discover', return_value=True):
|
||||||
|
await async_setup_component(hass, sonos.DOMAIN, {
|
||||||
|
'sonos': {
|
||||||
|
'some_config': 'to_trigger_import'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_not_configuring_sonos_not_creates_entry(hass):
|
||||||
|
"""Test that no config will not create an entry."""
|
||||||
|
with patch('homeassistant.components.sonos.async_setup_entry',
|
||||||
|
return_value=mock_coro(True)) as mock_setup, \
|
||||||
|
patch('soco.discover', return_value=True):
|
||||||
|
await async_setup_component(hass, sonos.DOMAIN, {})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(mock_setup.mock_calls) == 0
|
||||||
|
|
|
@ -114,3 +114,24 @@ async def test_user_init_trumps_discovery(hass, flow_conf):
|
||||||
|
|
||||||
# Discovery flow has been aborted
|
# Discovery flow has been aborted
|
||||||
assert len(hass.config_entries.flow.async_progress()) == 0
|
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_import_no_confirmation(hass, flow_conf):
|
||||||
|
"""Test import requires no confirmation to setup."""
|
||||||
|
flow = config_entries.HANDLERS['test']()
|
||||||
|
flow.hass = hass
|
||||||
|
flow_conf['discovered'] = True
|
||||||
|
|
||||||
|
result = await flow.async_step_import(None)
|
||||||
|
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
|
||||||
|
|
||||||
|
async def test_import_single_instance(hass, flow_conf):
|
||||||
|
"""Test import doesn't create second instance."""
|
||||||
|
flow = config_entries.HANDLERS['test']()
|
||||||
|
flow.hass = hass
|
||||||
|
flow_conf['discovered'] = True
|
||||||
|
MockConfigEntry(domain='test').add_to_hass(hass)
|
||||||
|
|
||||||
|
result = await flow.async_step_import(None)
|
||||||
|
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
|
|
Loading…
Reference in New Issue