generate random address and big ids on init
This commit is contained in:
@@ -2,19 +2,21 @@
|
||||
FastAPI implementation of the Multilang Translator API.
|
||||
This API mimics the mock_api from auracaster-webui to allow integration.
|
||||
"""
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
import asyncio
|
||||
import time
|
||||
import logging as log
|
||||
import asyncio
|
||||
import random
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
# Import models
|
||||
from multilang_translator.translator_models.translator_models import AnnouncementStates, Endpoint, EndpointGroup
|
||||
from multilang_translator.translator import llm_translator
|
||||
from multilang_translator.translator_server import endpoints_db
|
||||
from voice_provider import text_to_speech
|
||||
|
||||
# Import the endpoints database and multicast client
|
||||
from multilang_translator.translator_server import endpoints_db
|
||||
from auracast import multicast_client, auracast_config
|
||||
|
||||
# Create FastAPI app
|
||||
@@ -42,22 +44,27 @@ def init_endpoint(endpoint: Endpoint, languages: list[str]):
|
||||
for lang in languages]
|
||||
)
|
||||
|
||||
# overwrite some default configs
|
||||
# Configure the transport
|
||||
config.transport = 'auto'
|
||||
config.auracast_device_address = ':'.join(f"{random.randint(0, 255):02X}" for _ in range(6))
|
||||
|
||||
# Configure the bigs
|
||||
for big in config.bigs: # TODO: this is now part of the endpoint group config
|
||||
for big in config.bigs:
|
||||
big.loop = False
|
||||
big.name = endpoint.name
|
||||
#big.program_info =
|
||||
big.program_info = big.program_info + ' ' + endpoint.name
|
||||
big.id = random.randint(0, 2**16) #TODO: how many bits is this ?
|
||||
big.random_address = ':'.join(f"{random.randint(0, 255):02X}" for _ in range(6))
|
||||
|
||||
# TODO: init happens all the time
|
||||
# Initialize the endpoint if config changed or if it's not already initialized
|
||||
if not multicast_client.get_status(base_url=endpoint.url)['is_initialized'] or config != CURRENT_ENDPOINT_CONFIG.get(endpoint.id):
|
||||
ret = multicast_client.init(config, base_url=endpoint.url)
|
||||
# if ret != 200: # TODO: this is not working, should probably be handled async
|
||||
# log.error('Init of endpoint %s was unsucessfull', endpoint.name)
|
||||
# raise Exception(f"Init was of endpoint {endpoint.name} was unsucessfull")
|
||||
CURRENT_ENDPOINT_CONFIG[endpoint.id] = config
|
||||
CURRENT_ENDPOINT_CONFIG[endpoint.id] = config.model_copy()
|
||||
else:
|
||||
log.info('Endpoint %s was already initialized', endpoint.name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user