You've already forked STARK
mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-11-23 21:34:45 +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/
|
downloads/
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
.mypy_cache
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ class HubManager:
|
|||||||
def wifi(self, ssid: str, password: str):
|
def wifi(self, ssid: str, password: str):
|
||||||
WiFi.save_and_connect(ssid, password)
|
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):
|
def set_tokens(tokens_pair: schemas.TokensPair):
|
||||||
with open(f'{path}/{resources}/access_token.txt', 'w') as f:
|
with open(f'{path}/{resources}/access_token.txt', 'w') as f:
|
||||||
f.write(tokens_pair.access_token)
|
f.write(tokens_pair.access_token)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from uuid import UUID
|
|||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
import SmartHome.API.exceptions
|
import SmartHome.API.exceptions
|
||||||
from .HubManager import HubManager
|
from .HubManager import HubManager
|
||||||
from .schemas import Hub, PatchHub, TokensPair
|
from .schemas import Hub, PatchHub, TokensPair, Hotspot
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter(
|
router = APIRouter(
|
||||||
@@ -22,10 +22,14 @@ async def hub_create(hub: Hub, manager: HubManager = Depends()):
|
|||||||
async def hub_patch(hub: PatchHub, manager: HubManager = Depends()):
|
async def hub_patch(hub: PatchHub, manager: HubManager = Depends()):
|
||||||
manager.patch(hub)
|
manager.patch(hub)
|
||||||
|
|
||||||
@router.post('/wifi')
|
@router.post('/connect')
|
||||||
async def hub_wifi(ssid: str, password: str, manager: HubManager = Depends()):
|
async def hub_connect(ssid: str, password: str, manager: HubManager = Depends()):
|
||||||
manager.wifi(ssid, password)
|
manager.wifi(ssid, password)
|
||||||
|
|
||||||
|
@router.get('/hotspots')
|
||||||
|
async def hub_hotspots(manager: HubManager = Depends()):
|
||||||
|
return manager.get_hotspots()
|
||||||
|
|
||||||
@router.post('/set_tokens')
|
@router.post('/set_tokens')
|
||||||
async def set_tokens(tokens: TokensPair):
|
async def set_tokens(tokens: TokensPair):
|
||||||
manager.save_tokens(tokens)
|
manager.save_tokens(tokens)
|
||||||
|
|||||||
@@ -16,3 +16,6 @@ class Hub(BaseModel):
|
|||||||
class TokensPair(BaseModel):
|
class TokensPair(BaseModel):
|
||||||
access_token: str
|
access_token: str
|
||||||
refresh_token: str
|
refresh_token: str
|
||||||
|
|
||||||
|
class Hotspot(BaseModel):
|
||||||
|
ssid: str
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class WSManager:
|
|||||||
if not parameter:
|
if not parameter:
|
||||||
return
|
return
|
||||||
|
|
||||||
# f = #device.parameters.index(parameter)
|
# TODO: f = #device.parameters.index(parameter)
|
||||||
x = data.value
|
x = data.value
|
||||||
self.merlin.send(MerlinMessage(device.urdi, f, x))
|
self.merlin.send(MerlinMessage(device.urdi, f, x))
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import config
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'save',
|
'save',
|
||||||
'connect',
|
'get_list',
|
||||||
|
'connect_first',
|
||||||
'save_and_connect',
|
'save_and_connect',
|
||||||
'start_hotspot',
|
'start_hotspot',
|
||||||
'stop_hotspot',
|
'stop_hotspot',
|
||||||
@@ -16,6 +17,9 @@ access_point = pyaccesspoint.AccessPoint()
|
|||||||
access_point.ssid = config.wifi_ssid
|
access_point.ssid = config.wifi_ssid
|
||||||
access_point.password = config.wifi_password
|
access_point.password = config.wifi_password
|
||||||
|
|
||||||
|
def get_list() -> list[Cell]:
|
||||||
|
return Cell.all('wlan0')
|
||||||
|
|
||||||
def save(ssid: str, password: str):
|
def save(ssid: str, password: str):
|
||||||
for cell in Cell.all('wlan0'):
|
for cell in Cell.all('wlan0'):
|
||||||
if cell.ssid == ssid:
|
if cell.ssid == ssid:
|
||||||
@@ -29,7 +33,7 @@ def save_and_connect(ssid: str, password: str):
|
|||||||
scheme.save()
|
scheme.save()
|
||||||
scheme.activate()
|
scheme.activate()
|
||||||
|
|
||||||
def connect() -> bool:
|
def connect_first() -> bool:
|
||||||
ssids = [cell.ssid for cell in Cell.all('wlan0')]
|
ssids = [cell.ssid for cell in Cell.all('wlan0')]
|
||||||
|
|
||||||
for scheme in Scheme.all():
|
for scheme in Scheme.all():
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ from CallbackTeleBot import CallbackTeleBot
|
|||||||
|
|
||||||
class TelegramBot(CommandsContextManagerDelegate):
|
class TelegramBot(CommandsContextManagerDelegate):
|
||||||
|
|
||||||
threads = []
|
|
||||||
online = True
|
online = True
|
||||||
voids = 0
|
voids = 0
|
||||||
memory = []
|
|
||||||
voice = Text2Speech.Engine()
|
voice = Text2Speech.Engine()
|
||||||
bot = CallbackTeleBot(config.telebot)
|
bot = CallbackTeleBot(config.telebot)
|
||||||
commandsContext: CommandsContextManager
|
commandsContext: CommandsContextManager
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from IO import Text2Speech
|
|||||||
class VoiceAssistant(SpeechRecognizerDelegate, CommandsContextManagerDelegate):
|
class VoiceAssistant(SpeechRecognizerDelegate, CommandsContextManagerDelegate):
|
||||||
|
|
||||||
speechRecognizer: SpeechRecognizer
|
speechRecognizer: SpeechRecognizer
|
||||||
CommandsContextManager: CommandsContextManager
|
commandsContext: CommandsContextManager
|
||||||
voice = Text2Speech.Engine()
|
voice = Text2Speech.Engine()
|
||||||
|
|
||||||
voids: int = 0
|
voids: int = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user