🐛 Fixes server requests
This commit is contained in:
parent
cf35326bf2
commit
53722bdf18
@ -27,7 +27,7 @@ type ChangeLockReq struct {
|
||||
}
|
||||
|
||||
type ChangeAlertReq struct {
|
||||
Alert bool `json:"alert"`
|
||||
Alert bool `json:"alerts"`
|
||||
For int `json:"for"`
|
||||
}
|
||||
|
||||
@ -137,11 +137,13 @@ func main() {
|
||||
{
|
||||
Name: "yes",
|
||||
Usage: "lock the door",
|
||||
Aliases: []string{"y", "on", "1", "do"},
|
||||
Action: createManageLock(true),
|
||||
},
|
||||
{
|
||||
Name: "no",
|
||||
Usage: "unlock the door",
|
||||
Aliases: []string{"n", "off", "0", "undo"},
|
||||
Action: createManageLock(false),
|
||||
},
|
||||
},
|
||||
@ -154,11 +156,13 @@ func main() {
|
||||
{
|
||||
Name: "yes",
|
||||
Usage: "resume alerts",
|
||||
Aliases: []string{"y", "on", "1", "do"},
|
||||
Action: createManageAlert(true),
|
||||
},
|
||||
{
|
||||
Name: "no",
|
||||
Usage: "pause alerts",
|
||||
Aliases: []string{"n", "off", "0", "undo"},
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "for",
|
||||
@ -322,7 +326,7 @@ func createManageAlert(alert bool) func(context.Context, *cli.Command) error {
|
||||
action = "paused"
|
||||
}
|
||||
|
||||
fmt.Printf("alerts were %sd%s\n", action, rest)
|
||||
fmt.Printf("alerts were %s%s\n", action, rest)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ class App:
|
||||
try:
|
||||
r = urequests.post(
|
||||
f"{self.server}/opened",
|
||||
headers={"Authorization": self.token, "Content-Type": "application/json"},
|
||||
headers={"Authorization": f"Bearer {self.token}", "Content-Type": "application/json"},
|
||||
data=raw
|
||||
)
|
||||
print(f"State updated [{r.status_code}] {r.content.decode()}")
|
||||
|
@ -23,14 +23,14 @@ const TimeFormat = "2006-01-02 15:04:05"
|
||||
var token string
|
||||
|
||||
// the condition is: distance >= threshold (is door open)
|
||||
var opened bool
|
||||
var opened = false
|
||||
var openedChange = make(chan any)
|
||||
|
||||
// is door locked
|
||||
var locked bool = false
|
||||
var locked = false
|
||||
|
||||
// alerts the user when door locked and but open?
|
||||
var alerts bool = false
|
||||
var alerts = false
|
||||
var gotifyToken string
|
||||
var gotifyURL string
|
||||
|
||||
|
@ -79,7 +79,9 @@ func setOpened(c echo.Context) error {
|
||||
go sendAlert(action)
|
||||
}
|
||||
|
||||
go func() {
|
||||
openedChange <- 0
|
||||
}()
|
||||
mut.Unlock()
|
||||
return c.NoContent(http.StatusOK)
|
||||
}
|
||||
@ -126,6 +128,7 @@ func setAlerts(c echo.Context) error {
|
||||
}
|
||||
|
||||
if data.For > 0 {
|
||||
log.Infof("pausing alerts for %d seconds", data.For)
|
||||
go func() {
|
||||
time.Sleep(time.Duration(data.For) * time.Second)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user