-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename only_specific_beds, basic automation api
- Loading branch information
1 parent
92f84df
commit 7415691
Showing
4 changed files
with
41 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from fastapi import Request | ||
from nicegui import app | ||
|
||
from field_friend.system import System | ||
|
||
|
||
class Automation: | ||
def __init__(self, system: System) -> None: | ||
self.system = system | ||
|
||
@app.post('/api/automation/start') | ||
async def start_automation(request: Request): | ||
# TODO add error handling | ||
self.system.current_navigation = self.system.field_navigation | ||
field_data = await request.json() | ||
self.system.field_navigation.field_id = field_data['field_id'] | ||
self.system.field_provider.only_specific_beds = field_data['only_specific_beds'] | ||
self.system.field_provider.selected_beds = field_data['selected_beds'] | ||
self.system.automator.start() | ||
return {'automation_started': True} | ||
|
||
@app.post('/api/automation/stop') | ||
def stop_automation(): | ||
assert self.system.automator.is_running | ||
self.system.automator.stop(because='API call') | ||
return {'automation_stopped': True} | ||
|
||
@app.post('/api/automation/pause') | ||
def pause_automation(): | ||
assert self.system.automator.is_running | ||
self.system.automator.pause(because='API call') | ||
return {'automation_paused': True} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters