mirror of
https://github.com/Luzifer/tasmota-config.git
synced 2024-12-22 10:41:19 +00:00
Add more settings reader
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
f01c6ebac0
commit
4e039d96bc
1 changed files with 30 additions and 10 deletions
40
settings.go
40
settings.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -12,16 +13,20 @@ import (
|
||||||
type settingExtractor func([]byte) (interface{}, error)
|
type settingExtractor func([]byte) (interface{}, error)
|
||||||
|
|
||||||
var extractors = map[string]settingExtractor{
|
var extractors = map[string]settingExtractor{
|
||||||
"currentcal": func(p []byte) (interface{}, error) { return extractFloatToInt("CurrentCal", p) },
|
"currentcal": func(p []byte) (interface{}, error) { return extractFloatToInt("CurrentCal", p) },
|
||||||
"devicename": func(p []byte) (interface{}, error) { return extractGenericJSONValue("DeviceName", p) },
|
"devicename": func(p []byte) (interface{}, error) { return extractGenericJSONValue("DeviceName", p) },
|
||||||
"ledstate": func(p []byte) (interface{}, error) { return extractFloatToInt("LedState", p) },
|
"ledstate": func(p []byte) (interface{}, error) { return extractFloatToInt("LedState", p) },
|
||||||
"module": extractModule,
|
"module": extractModule,
|
||||||
"otaurl": func(p []byte) (interface{}, error) { return extractGenericJSONValue("OtaUrl", p) },
|
"otaurl": func(p []byte) (interface{}, error) { return extractGenericJSONValue("OtaUrl", p) },
|
||||||
"powercal": func(p []byte) (interface{}, error) { return extractFloatToInt("PowerCal", p) },
|
"powercal": func(p []byte) (interface{}, error) { return extractFloatToInt("PowerCal", p) },
|
||||||
"teleperiod": func(p []byte) (interface{}, error) { return extractFloatToInt("TelePeriod", p) },
|
"poweronstate": func(p []byte) (interface{}, error) { return extractFloatToInt("PowerOnState", p) },
|
||||||
"timezone": func(p []byte) (interface{}, error) { return extractGenericJSONValue("Timezone", p) },
|
"pulsetime1": func(p []byte) (interface{}, error) { return extractPulseTime(1, p) },
|
||||||
"topic": func(p []byte) (interface{}, error) { return extractGenericJSONValue("Topic", p) },
|
"switchmode1": func(p []byte) (interface{}, error) { return extractFloatToInt("SwitchMode1", p) },
|
||||||
"voltagecal": func(p []byte) (interface{}, error) { return extractFloatToInt("VoltageCal", p) },
|
"switchmode2": func(p []byte) (interface{}, error) { return extractFloatToInt("SwitchMode2", p) },
|
||||||
|
"teleperiod": func(p []byte) (interface{}, error) { return extractFloatToInt("TelePeriod", p) },
|
||||||
|
"timezone": func(p []byte) (interface{}, error) { return extractGenericJSONValue("Timezone", p) },
|
||||||
|
"topic": func(p []byte) (interface{}, error) { return extractGenericJSONValue("Topic", p) },
|
||||||
|
"voltagecal": func(p []byte) (interface{}, error) { return extractFloatToInt("VoltageCal", p) },
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractSettingValue(setting string, payloadChan chan []byte) (interface{}, error) {
|
func extractSettingValue(setting string, payloadChan chan []byte) (interface{}, error) {
|
||||||
|
@ -90,3 +95,18 @@ func extractModule(payload []byte) (interface{}, error) {
|
||||||
|
|
||||||
return strconv.Atoi(values[0])
|
return strconv.Atoi(values[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func extractPulseTime(slot int, payload []byte) (interface{}, error) {
|
||||||
|
// {"PulseTime1":{"Set":15,"Remaining":0}}
|
||||||
|
var data = map[string]struct{ Remaining, Set int }{}
|
||||||
|
if err := json.Unmarshal(payload, &data); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "Unable to unmarshal response")
|
||||||
|
}
|
||||||
|
|
||||||
|
pt, ok := data[fmt.Sprintf("PulseTime%d", slot)]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.Errorf("Found no response to PulseTime%d", slot)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pt.Set, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue