Skip to content

Commit

Permalink
Add a stub test
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed May 19, 2018
1 parent 88f7ad9 commit 0ca296e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 83 deletions.
13 changes: 10 additions & 3 deletions homeassistant/components/remote_homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import voluptuous as vol

from homeassistant.core import callback
import homeassistant.components.websocket_api as api
from homeassistant.core import EventOrigin, split_entity_id
from homeassistant.helpers.typing import HomeAssistantType, ConfigType
Expand Down Expand Up @@ -48,7 +49,8 @@

CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_INSTANCES): [INSTANCES_SCHEMA],
vol.Required(CONF_INSTANCES): vol.All(cv.ensure_list,
[INSTANCES_SCHEMA]),
}),
}, extra=vol.ALLOW_EXTRA)

Expand Down Expand Up @@ -83,10 +85,15 @@ def __init__(self, hass, conf):

self.__id = 1

@callback
def _get_url(self):
"""Get url to connect to."""
return '%s://%s:%s/api/websocket' % (
'wss' if self._secure else 'ws', self._host, self._port)

async def async_connect(self):
"""Connect to remote home-assistant websocket..."""
url = '%s://%s:%s/api/websocket' % (
'wss' if self._secure else 'ws', self._host, self._port)
url = self._get_url()

session = async_get_clientsession(self._hass)

Expand Down
113 changes: 33 additions & 80 deletions tests/components/test_remote_homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,36 @@
import asyncio
from unittest.mock import patch

from aiohttp import WSMsgType
from async_timeout import timeout
import pytest

from homeassistant.components import remote_homeassistant
from homeassistant.core import callback
from homeassistant.components import websocket_api as wapi, frontend
from homeassistant.setup import async_setup_component, setup_component
from homeassistant.components import http

from tests.common import (
get_test_home_assistant,
mock_mqtt_component,
fire_mqtt_message,
mock_state_change_event,
fire_time_changed
)

instance01_port = 8124
instance02_port = 8125

class TestRemoteHomeassistant(object):
"""Test the Remote Homeassistant module."""

def setup_method(self):
"""Setup things to be run when tests are started."""
self.hass_instance01 = get_test_home_assistant()
#self.hass_instance02 = get_test_home_assistant()

self.hass_main = get_test_home_assistant()

#self.hass_main.block_till_done()

#setup_component(
# self.hass_instance01, http.DOMAIN, {
# http.DOMAIN: {
# http.CONF_SERVER_PORT: instance01_port,
# }
# }
#)

#setup_component(self.hass_instance01, 'websocket_api')

def teardown_method(self):
"""Stop everything that was started."""
self.hass_main.stop()
self.hass_instance01.stop()
#self.hass_instance02.stop()

pass

def test_connect(self):
#setup_component(
# self.hass_instance01, http.DOMAIN, {
# http.DOMAIN: {
# http.CONF_SERVER_PORT: instance01_port,
# }
# }
#)

#setup_component(self.hass_instance01, 'websocket_api')

#self.hass_instance01.block_till_done()


#config = {
# remote_homeassistant.CONF_INSTANCES:
# [
# {
# remote_homeassistant.CONF_HOST: 'localhost',
# #remote_homeassistant.CONF_PORT: instance01_port
# }
# ]
#}
#setup_component(self.hass_main, remote_homeassistant.DOMAIN, {
# remote_homeassistant.DOMAIN: config})

#self.hass_main.block_till_done()
pass

from homeassistant.setup import async_setup_component
from homeassistant.components import remote_homeassistant as rass

from tests.common import async_test_home_assistant


async def test_something(hass, aiohttp_client):
"""Test bla."""
assert await async_setup_component(hass, 'websocket_api', {})
client = await aiohttp_client(hass.http.app)

hass_client = await async_test_home_assistant(hass.loop)

with patch('homeassistant.components.remote_homeassistant'
'.async_get_clientsession', return_value=client), \
patch('homeassistant.components.remote_homeassistant'
'.RemoteConnection._get_url', return_value='/api/websocket'):
assert await async_setup_component(hass_client, rass.DOMAIN, {
rass.DOMAIN: {
'instances': {
'host': 'mock',
}
}
})

hass.states.async_set('light.kitchen', 'on')
# await hass.async_block_till_done()
# await hass_client.async_block_till_done()
await asyncio.sleep(.1)

state = hass_client.states.get('light.kitchen')
assert state is not None
assert state.state == 'on'

0 comments on commit 0ca296e

Please sign in to comment.