Implement setting lamp brightnesses

This commit is contained in:
2024-12-29 00:34:04 +01:00
parent 91ee137ff5
commit 4625f4a016
3 changed files with 13 additions and 8 deletions

4
app.go
View File

@@ -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)