Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #201

Merged
merged 2 commits into from
Jan 7, 2024
Merged

Dev #201

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
2 changes: 1 addition & 1 deletion backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ verify_ssl = true
name = "pypi"

[packages]
bleak = "*"
websockets = "*"
requests = "*"
pinecil = "*"

[dev-packages]
pytest = "*"
Expand Down
76 changes: 0 additions & 76 deletions backend/ble.py

This file was deleted.

111 changes: 0 additions & 111 deletions backend/crx_uuid_name_map.py

This file was deleted.

22 changes: 16 additions & 6 deletions backend/main_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import websockets.exceptions
import json
import requests
from ble import DeviceNotFoundException
from ble import DeviceDisconnectedException
from pinecil_ble import Pinecil
from pinecil_ble import InvalidSettingException
from pinecil_ble import ValueOutOfRangeException
from pinecil import DeviceNotFoundException
from pinecil import DeviceDisconnectedException
from pinecil import Pinecil, find_pinecils
from pinecil import InvalidSettingException
from pinecil import ValueOutOfRangeException

LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO').upper()
timestamp_format = '%H:%M:%S'
logging.basicConfig(level=LOG_LEVEL, format='%(asctime)s.%(msecs)03d::%(levelname)s::%(message)s', datefmt=timestamp_format)

pinecil = Pinecil()
pinecils = []

def read_app_version():
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -45,6 +45,9 @@ async def process_command(command: str, payload: dict) -> dict:
'is_new_available': is_semver_greater(get_latest_app_version(), app_version),
}
return {'status': 'OK', 'payload': info}
while not pinecils:
await asyncio.sleep(0.5)
pinecil = pinecils[0]
while not pinecil.is_connected:
await asyncio.sleep(0.5)
if command == 'GET_SETTINGS':
Expand Down Expand Up @@ -105,9 +108,16 @@ def broadcast(message):
asyncio.create_task(send(client, message))

async def pinecil_monitor(stop_event: asyncio.Event):
global pinecils
logging.info('Starting pinecil monitor')
should_announce_not_found = True
while not stop_event.is_set():
if not pinecils:
pinecils = await find_pinecils()
logging.info('looking for pinecil...')
await asyncio.sleep(1)
continue
pinecil = pinecils[0]
if not pinecil.is_connected:
logging.info('waiting for pinecil...')
try:
Expand Down
Loading
Loading