Idk what this is
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
import os, logging
|
||||
DEBUG = os.environ.get('DEBUG')
|
||||
logging.basicConfig(
|
||||
format='[%(asctime)s] %(levelname)s %(module)s/%(funcName)s - %(message)s',
|
||||
level=logging.DEBUG if DEBUG else logging.INFO)
|
||||
logging.getLogger('aiohttp').setLevel(logging.DEBUG if DEBUG else logging.WARNING)
|
||||
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import zlib
|
||||
@@ -15,12 +22,24 @@ async def connect():
|
||||
rememberMe=True,
|
||||
)
|
||||
|
||||
logging.info('Connecting to Unifi Protect...')
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(settings.UFP_ADDRESS + '/api/auth/login', json=data, ssl=False) as resp:
|
||||
async with session.post(settings.UFP_ADDRESS + '/api/auth/login', json=data, ssl=False, timeout=5) as resp:
|
||||
cookie = resp.cookies['TOKEN']
|
||||
|
||||
logging.info('Got cookie.')
|
||||
|
||||
headers = {'cookie': cookie.key + '=' + cookie.value}
|
||||
async with session.ws_connect(settings.UFP_ADDRESS + '/proxy/protect/ws/updates', headers=headers, ssl=False) as ws:
|
||||
async with session.ws_connect(
|
||||
settings.UFP_ADDRESS + '/proxy/protect/ws/updates',
|
||||
headers=headers,
|
||||
ssl=False,
|
||||
receive_timeout=10.0,
|
||||
heartbeat=10.0,
|
||||
) as ws:
|
||||
yield 'CONNECTED'
|
||||
|
||||
async for msg in ws:
|
||||
packet_type, payload_format, deflated, unknown, payload_size = struct.unpack('!bbbbi', msg.data[0:HEADER_LENGTH])
|
||||
action_start = HEADER_LENGTH
|
||||
@@ -30,6 +49,8 @@ async def connect():
|
||||
|
||||
yield json.loads(data_packet.decode())
|
||||
|
||||
logging.info('Lost connection to web socket.')
|
||||
|
||||
|
||||
async def test():
|
||||
async for msg in connect():
|
||||
|
||||
Reference in New Issue
Block a user