chore: simplify

This commit is contained in:
andig 2025-03-07 12:41:03 +01:00
parent 29b7b2f44c
commit 415a014f54

View file

@ -130,6 +130,11 @@ type testResult = struct {
Error string `json:"error"`
}
func hasFeature(instance any, f api.Feature) bool {
fd, ok := instance.(api.FeatureDescriber)
return ok && slices.Contains(fd.Features(), f)
}
// testInstance tests the given instance similar to dump
// TODO refactor together with dump
func testInstance(instance any) map[string]testResult {
@ -159,7 +164,7 @@ func testInstance(instance any) map[string]testResult {
if dev, ok := instance.(api.Battery); ok {
val, err := dev.Soc()
key := "soc"
if fd, ok := instance.(api.FeatureDescriber); ok && slices.Contains(fd.Features(), api.Heating) {
if hasFeature(instance, api.Heating) {
key = "temp"
}
makeResult(key, val, err)
@ -225,7 +230,7 @@ func testInstance(instance any) map[string]testResult {
if dev, ok := instance.(api.SocLimiter); ok {
val, err := dev.GetLimitSoc()
key := "vehicleLimitSoc"
if fd, ok := instance.(api.FeatureDescriber); ok && slices.Contains(fd.Features(), api.Heating) {
if hasFeature(instance, api.Heating) {
key = "heaterTempLimit"
}
makeResult(key, val, err)