Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 23 additions & 1 deletion homeassistant/components/hassio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
DOMAIN = 'hassio'
DEPENDENCIES = ['http']

CONF_FRONTEND_REPO = 'development_repo'

CONFIG_SCHEMA = vol.Schema({
vol.Optional(DOMAIN): vol.Schema({
vol.Optional(CONF_FRONTEND_REPO): cv.isdir,
}),
}, extra=vol.ALLOW_EXTRA)


DATA_HOMEASSISTANT_VERSION = 'hassio_hass_version'
HASSIO_UPDATE_INTERVAL = timedelta(minutes=55)

Expand Down Expand Up @@ -142,7 +151,13 @@ def async_setup(hass, config):
try:
host = os.environ['HASSIO']
except KeyError:
_LOGGER.error("No Hass.io supervisor detect")
_LOGGER.error("Missing HASSIO environment variable.")
return False

try:
os.environ['HASSIO_TOKEN']
except KeyError:
_LOGGER.error("Missing HASSIO_TOKEN environment variable.")
return False

websession = hass.helpers.aiohttp_client.async_get_clientsession()
Expand All @@ -152,6 +167,13 @@ def async_setup(hass, config):
_LOGGER.error("Not connected with Hass.io")
return False

# This overrides the normal API call that would be forwarded
development_repo = config.get(DOMAIN, {}).get(CONF_FRONTEND_REPO)
if development_repo is not None:
hass.http.register_static_path(
'/api/hassio/app-es5',
os.path.join(development_repo, 'hassio/build-es5'), False)

hass.http.register_view(HassIOView(host, websession))

if 'frontend' in hass.config.components:
Expand Down
20 changes: 13 additions & 7 deletions tests/components/hassio/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
from tests.common import mock_coro


MOCK_ENVIRON = {
'HASSIO': '127.0.0.1',
'HASSIO_TOKEN': 'abcdefgh',
}


@asyncio.coroutine
def test_setup_api_ping(hass, aioclient_mock):
"""Test setup with API ping."""
Expand All @@ -18,7 +24,7 @@ def test_setup_api_ping(hass, aioclient_mock):
"http://127.0.0.1/homeassistant/info", json={
'result': 'ok', 'data': {'last_version': '10.0'}})

with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}):
with patch.dict(os.environ, MOCK_ENVIRON):
result = yield from async_setup_component(hass, 'hassio', {})
assert result

Expand All @@ -38,7 +44,7 @@ def test_setup_api_push_api_data(hass, aioclient_mock):
aioclient_mock.post(
"http://127.0.0.1/homeassistant/options", json={'result': 'ok'})

with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}):
with patch.dict(os.environ, MOCK_ENVIRON):
result = yield from async_setup_component(hass, 'hassio', {
'http': {
'api_password': "123456",
Expand Down Expand Up @@ -66,7 +72,7 @@ def test_setup_api_push_api_data_server_host(hass, aioclient_mock):
aioclient_mock.post(
"http://127.0.0.1/homeassistant/options", json={'result': 'ok'})

with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}):
with patch.dict(os.environ, MOCK_ENVIRON):
result = yield from async_setup_component(hass, 'hassio', {
'http': {
'api_password': "123456",
Expand Down Expand Up @@ -95,7 +101,7 @@ def test_setup_api_push_api_data_default(hass, aioclient_mock):
aioclient_mock.post(
"http://127.0.0.1/homeassistant/options", json={'result': 'ok'})

with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}):
with patch.dict(os.environ, MOCK_ENVIRON):
result = yield from async_setup_component(hass, 'hassio', {
'http': {},
'hassio': {}
Expand All @@ -119,7 +125,7 @@ def test_setup_core_push_timezone(hass, aioclient_mock):
aioclient_mock.post(
"http://127.0.0.1/supervisor/options", json={'result': 'ok'})

with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}):
with patch.dict(os.environ, MOCK_ENVIRON):
result = yield from async_setup_component(hass, 'hassio', {
'hassio': {},
'homeassistant': {
Expand All @@ -143,7 +149,7 @@ def test_setup_hassio_no_additional_data(hass, aioclient_mock):
aioclient_mock.get(
"http://127.0.0.1/homeassistant/info", json={'result': 'ok'})

with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}), \
with patch.dict(os.environ, MOCK_ENVIRON), \
patch.dict(os.environ, {'HASSIO_TOKEN': "123456"}):
result = yield from async_setup_component(hass, 'hassio', {
'hassio': {},
Expand All @@ -165,7 +171,7 @@ def test_fail_setup_without_environ_var(hass):
@asyncio.coroutine
def test_fail_setup_cannot_connect(hass):
"""Fail setup if cannot connect."""
with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}), \
with patch.dict(os.environ, MOCK_ENVIRON), \
patch('homeassistant.components.hassio.HassIO.is_connected',
Mock(return_value=mock_coro(None))):
result = yield from async_setup_component(hass, 'hassio', {})
Expand Down