chore: simplify
This commit is contained in:
parent
29b7b2f44c
commit
415a014f54
1 changed files with 7 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue