generated from dave/wails-template
Implement setting lamp brightnesses
This commit is contained in:
4
app.go
4
app.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -61,15 +62,18 @@ func (a *App) GetLamps() (lamps []string) {
|
||||
}
|
||||
|
||||
func (a *App) SetLampBrightness(lampId int, brightness int) string {
|
||||
log.Printf("Setting lamp %d to %d", lampId, brightness)
|
||||
resp, err := http.Get("http://" + IP + "/lamp/" + strconv.Itoa(lampId) + "?n=" + strconv.Itoa(brightness))
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
log.Printf("Error: %s", err.Error())
|
||||
return ""
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
log.Printf("Error: %s", err.Error())
|
||||
return ""
|
||||
}
|
||||
return string(body)
|
||||
|
Reference in New Issue
Block a user