async def main(loop): logging.basicConfig(level=logging.DEBUG) fake_ws = FakeWebsocketHmip(loop=loop, base_url='ws.homematic.com') connector = await fake_ws.start() incoming = {} def parser(*args, **kwargs): incoming['test'] = None async with aiohttp.ClientSession(connector=connector, loop=loop) as session: connection = AsyncConnection(loop, session) connection.headers[ATTR_AUTH_TOKEN] = 'auth_token' connection.headers[ATTR_CLIENT_AUTH] = 'client_auth' connection._urlWebSocket = 'wss://ws.homematic.com/' try: ws_loop = await connection.ws_connect(parser) await ws_loop except Exception as err: pass print(incoming) await fake_ws.stop()
async def client_connection(event_loop): connection = AsyncConnection(event_loop) connection._urlWebSocket = "ws://localhost:8123/" connection.ping_timeout = 1 yield connection await connection._websession.close()
async def fake_server(event_loop): server = FakeConnectionHmip(loop=event_loop, base_url='test.homematic.com', port=None) connector = await server.start() async with aiohttp.ClientSession(connector=connector, loop=event_loop) as session: connection = AsyncConnection(event_loop, session=session) connection.headers[ATTR_AUTH_TOKEN] = '' connection.headers[ATTR_CLIENT_AUTH] = '' yield connection await server.stop()
async def fake_lookup_server(event_loop): server = FakeLookupHmip(loop=event_loop, base_url='lookup.homematic.com', port=48335) connector = await server.start() async with aiohttp.ClientSession(connector=connector, loop=event_loop) as session: connection = AsyncConnection(event_loop, session=session) yield connection await server.stop()
async def fake_async_home(fake_cloud, event_loop): home = AsyncHome(event_loop) with no_ssl_verification(): lookup_url = "{}/getHost".format(fake_cloud.url) # home.download_configuration = fake_home_download_configuration home._connection = AsyncConnection(event_loop) home._fake_cloud = fake_cloud home.set_auth_token( "8A45BAA53BE37E3FCA58E9976EFA4C497DAFE55DB997DB9FD685236E5E63ED7DE" ) await home._connection.init(accesspoint_id="3014F711A000000BAD0C0DED", lookup_url=lookup_url) await home.get_current_state() yield home
def __init__(self, loop, websession=None): super().__init__(connection=AsyncConnection(loop, websession))
async def start_async_client_connection(connector, loop, base_url, url): session = aiohttp.ClientSession(connector=connector, loop=loop) connection = AsyncConnection(loop, session) connection._urlWebSocket = 'ws://' + base_url + url return connection