You've already forked STARK
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:
2
.gitignore
vendored
2
.gitignore
vendored
@ -18,3 +18,5 @@ audio/
|
||||
downloads/
|
||||
|
||||
.idea
|
||||
|
||||
.mypy_cache
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -16,3 +16,6 @@ class Hub(BaseModel):
|
||||
class TokensPair(BaseModel):
|
||||
access_token: str
|
||||
refresh_token: str
|
||||
|
||||
class Hotspot(BaseModel):
|
||||
ssid: str
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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():
|
||||
|
@ -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
|
||||
|
@ -10,7 +10,7 @@ from IO import Text2Speech
|
||||
class VoiceAssistant(SpeechRecognizerDelegate, CommandsContextManagerDelegate):
|
||||
|
||||
speechRecognizer: SpeechRecognizer
|
||||
CommandsContextManager: CommandsContextManager
|
||||
commandsContext: CommandsContextManager
|
||||
voice = Text2Speech.Engine()
|
||||
|
||||
voids: int = 0
|
||||
|
Reference in New Issue
Block a user