1
0
mirror of https://github.com/MarkParker5/STARK.git synced 2025-07-12 22:50:22 +02:00

add wifi list endpoint

minor fixes
This commit is contained in:
MarkParker5
2022-06-07 11:22:13 +02:00
parent 2d26a2a0bf
commit 9d971ef804
8 changed files with 23 additions and 9 deletions

2
.gitignore vendored
View File

@ -18,3 +18,5 @@ audio/
downloads/
.idea
.mypy_cache

View File

@ -39,6 +39,9 @@ class HubManager:
def wifi(self, ssid: str, password: str):
WiFi.save_and_connect(ssid, password)
def get_hotspots(self) -> list[schemas.Hotspot]:
return [schemas.Hotspot(**cell.__dict__) for cell in WiFi.get_list()]
def set_tokens(tokens_pair: schemas.TokensPair):
with open(f'{path}/{resources}/access_token.txt', 'w') as f:
f.write(tokens_pair.access_token)

View File

@ -2,7 +2,7 @@ from uuid import UUID
from fastapi import APIRouter, Depends
import SmartHome.API.exceptions
from .HubManager import HubManager
from .schemas import Hub, PatchHub, TokensPair
from .schemas import Hub, PatchHub, TokensPair, Hotspot
router = APIRouter(
@ -22,10 +22,14 @@ async def hub_create(hub: Hub, manager: HubManager = Depends()):
async def hub_patch(hub: PatchHub, manager: HubManager = Depends()):
manager.patch(hub)
@router.post('/wifi')
async def hub_wifi(ssid: str, password: str, manager: HubManager = Depends()):
@router.post('/connect')
async def hub_connect(ssid: str, password: str, manager: HubManager = Depends()):
manager.wifi(ssid, password)
@router.get('/hotspots')
async def hub_hotspots(manager: HubManager = Depends()):
return manager.get_hotspots()
@router.post('/set_tokens')
async def set_tokens(tokens: TokensPair):
manager.save_tokens(tokens)

View File

@ -16,3 +16,6 @@ class Hub(BaseModel):
class TokensPair(BaseModel):
access_token: str
refresh_token: str
class Hotspot(BaseModel):
ssid: str

View File

@ -22,7 +22,7 @@ class WSManager:
if not parameter:
return
# f = #device.parameters.index(parameter)
# TODO: f = #device.parameters.index(parameter)
x = data.value
self.merlin.send(MerlinMessage(device.urdi, f, x))

View File

@ -5,7 +5,8 @@ import config
__all__ = [
'save',
'connect',
'get_list',
'connect_first',
'save_and_connect',
'start_hotspot',
'stop_hotspot',
@ -16,6 +17,9 @@ access_point = pyaccesspoint.AccessPoint()
access_point.ssid = config.wifi_ssid
access_point.password = config.wifi_password
def get_list() -> list[Cell]:
return Cell.all('wlan0')
def save(ssid: str, password: str):
for cell in Cell.all('wlan0'):
if cell.ssid == ssid:
@ -29,7 +33,7 @@ def save_and_connect(ssid: str, password: str):
scheme.save()
scheme.activate()
def connect() -> bool:
def connect_first() -> bool:
ssids = [cell.ssid for cell in Cell.all('wlan0')]
for scheme in Scheme.all():

View File

@ -10,10 +10,8 @@ from CallbackTeleBot import CallbackTeleBot
class TelegramBot(CommandsContextManagerDelegate):
threads = []
online = True
voids = 0
memory = []
voice = Text2Speech.Engine()
bot = CallbackTeleBot(config.telebot)
commandsContext: CommandsContextManager

View File

@ -10,7 +10,7 @@ from IO import Text2Speech
class VoiceAssistant(SpeechRecognizerDelegate, CommandsContextManagerDelegate):
speechRecognizer: SpeechRecognizer
CommandsContextManager: CommandsContextManager
commandsContext: CommandsContextManager
voice = Text2Speech.Engine()
voids: int = 0