Config UI: add missing config sections / partial yaml inputs (BC) (#13319)
This commit is contained in:
parent
62a1e223b6
commit
554ce1db60
133 changed files with 4405 additions and 1572 deletions
|
|
@ -3,11 +3,14 @@ package util
|
|||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/evcc-io/evcc/util/encode"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
// Cache is a data store
|
||||
type Cache struct {
|
||||
sync.Mutex
|
||||
mu sync.RWMutex
|
||||
val map[string]Param
|
||||
}
|
||||
|
||||
|
|
@ -48,30 +51,31 @@ func (c *Cache) Run(in <-chan Param) {
|
|||
}
|
||||
}
|
||||
|
||||
// State provides a structured copy of the cached values
|
||||
// Loadpoints are aggregated as loadpoints array
|
||||
func (c *Cache) State() map[string]interface{} {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
// State provides a structured copy of the cached values.
|
||||
// Loadpoints are aggregated as loadpoints array.
|
||||
// Result values are formatted using encoder.
|
||||
func (c *Cache) State(enc encode.Encoder) map[string]any {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
res := map[string]interface{}{}
|
||||
lps := make(map[int]map[string]interface{})
|
||||
res := make(map[string]any)
|
||||
lps := make(map[int]map[string]any)
|
||||
|
||||
for _, param := range c.val {
|
||||
if param.Loadpoint == nil {
|
||||
res[param.Key] = param.Val
|
||||
res[param.Key] = enc.Encode(param.Val)
|
||||
} else {
|
||||
lp, ok := lps[*param.Loadpoint]
|
||||
if !ok {
|
||||
lp = make(map[string]interface{})
|
||||
lp = make(map[string]any)
|
||||
lps[*param.Loadpoint] = lp
|
||||
}
|
||||
lp[param.Key] = param.Val
|
||||
lp[param.Key] = enc.Encode(param.Val)
|
||||
}
|
||||
}
|
||||
|
||||
// convert map to array
|
||||
loadpoints := make([]map[string]interface{}, len(lps))
|
||||
loadpoints := make([]map[string]any, len(lps))
|
||||
for id, lp := range lps {
|
||||
loadpoints[id] = lp
|
||||
}
|
||||
|
|
@ -82,29 +86,24 @@ func (c *Cache) State() map[string]interface{} {
|
|||
|
||||
// All provides a copy of the cached values
|
||||
func (c *Cache) All() []Param {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
copy := make([]Param, 0, len(c.val))
|
||||
for _, val := range c.val {
|
||||
copy = append(copy, val)
|
||||
}
|
||||
|
||||
return copy
|
||||
return maps.Values(c.val)
|
||||
}
|
||||
|
||||
// Add entry to cache
|
||||
func (c *Cache) Add(key string, param Param) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
c.val[key] = param
|
||||
}
|
||||
|
||||
// Get entry from cache
|
||||
func (c *Cache) Get(key string) Param {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
if val, ok := c.val[key]; ok {
|
||||
return val
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue