|
| 1 | +package globalconfig |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net" |
| 6 | + "strconv" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/evcc-io/evcc/charger/eebus" |
| 10 | + "github.com/evcc-io/evcc/provider/mqtt" |
| 11 | + "github.com/evcc-io/evcc/push" |
| 12 | + "github.com/evcc-io/evcc/util/config" |
| 13 | + "github.com/evcc-io/evcc/util/modbus" |
| 14 | +) |
| 15 | + |
| 16 | +type All struct { |
| 17 | + Network Network |
| 18 | + Log string |
| 19 | + SponsorToken string |
| 20 | + Plant string // telemetry plant id |
| 21 | + Telemetry bool |
| 22 | + Metrics bool |
| 23 | + Profile bool |
| 24 | + Levels map[string]string |
| 25 | + Interval time.Duration |
| 26 | + Database DB |
| 27 | + Mqtt Mqtt |
| 28 | + ModbusProxy []ModbusProxy |
| 29 | + Javascript []Javascript |
| 30 | + Go []Go |
| 31 | + Influx Influx |
| 32 | + EEBus eebus.Config |
| 33 | + HEMS config.Typed |
| 34 | + Messaging Messaging |
| 35 | + Meters []config.Named |
| 36 | + Chargers []config.Named |
| 37 | + Vehicles []config.Named |
| 38 | + Tariffs Tariffs |
| 39 | + Site map[string]interface{} |
| 40 | + Loadpoints []map[string]interface{} |
| 41 | + Circuits []config.Named |
| 42 | +} |
| 43 | + |
| 44 | +type Javascript struct { |
| 45 | + VM string |
| 46 | + Script string |
| 47 | +} |
| 48 | + |
| 49 | +type Go struct { |
| 50 | + VM string |
| 51 | + Script string |
| 52 | +} |
| 53 | + |
| 54 | +type ModbusProxy struct { |
| 55 | + Port int |
| 56 | + ReadOnly string |
| 57 | + modbus.Settings `mapstructure:",squash"` |
| 58 | +} |
| 59 | + |
| 60 | +type Mqtt struct { |
| 61 | + mqtt.Config `mapstructure:",squash"` |
| 62 | + Topic string `json:"topic"` |
| 63 | +} |
| 64 | + |
| 65 | +// Redacted implements the redactor interface used by the tee publisher |
| 66 | +func (m Mqtt) Redacted() any { |
| 67 | + // TODO add masked password |
| 68 | + return struct { |
| 69 | + Broker string `json:"broker"` |
| 70 | + Topic string `json:"topic"` |
| 71 | + User string `json:"user"` |
| 72 | + ClientID string `json:"clientID"` |
| 73 | + Insecure bool `json:"insecure"` |
| 74 | + }{ |
| 75 | + Broker: m.Broker, |
| 76 | + Topic: m.Topic, |
| 77 | + User: m.User, |
| 78 | + ClientID: m.ClientID, |
| 79 | + Insecure: m.Insecure, |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +// Influx is the influx db configuration |
| 84 | +type Influx struct { |
| 85 | + URL string `json:"url"` |
| 86 | + Database string `json:"database"` |
| 87 | + Token string `json:"token"` |
| 88 | + Org string `json:"org"` |
| 89 | + User string `json:"user"` |
| 90 | + Password string `json:"password"` |
| 91 | +} |
| 92 | + |
| 93 | +// Redacted implements the redactor interface used by the tee publisher |
| 94 | +func (c Influx) Redacted() any { |
| 95 | + // TODO add masked password |
| 96 | + return struct { |
| 97 | + URL string `json:"url"` |
| 98 | + Database string `json:"database"` |
| 99 | + Org string `json:"org"` |
| 100 | + User string `json:"user"` |
| 101 | + }{ |
| 102 | + URL: c.URL, |
| 103 | + Database: c.Database, |
| 104 | + Org: c.Org, |
| 105 | + User: c.User, |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +type DB struct { |
| 110 | + Type string |
| 111 | + Dsn string |
| 112 | +} |
| 113 | + |
| 114 | +type Messaging struct { |
| 115 | + Events map[string]push.EventTemplateConfig |
| 116 | + Services []config.Typed |
| 117 | +} |
| 118 | + |
| 119 | +type Tariffs struct { |
| 120 | + Currency string |
| 121 | + Grid config.Typed |
| 122 | + FeedIn config.Typed |
| 123 | + Co2 config.Typed |
| 124 | + Planner config.Typed |
| 125 | +} |
| 126 | + |
| 127 | +type Network struct { |
| 128 | + Schema string `json:"schema"` |
| 129 | + Host string `json:"host"` |
| 130 | + Port int `json:"port"` |
| 131 | +} |
| 132 | + |
| 133 | +func (c Network) HostPort() string { |
| 134 | + if c.Schema == "http" && c.Port == 80 || c.Schema == "https" && c.Port == 443 { |
| 135 | + return c.Host |
| 136 | + } |
| 137 | + return net.JoinHostPort(c.Host, strconv.Itoa(c.Port)) |
| 138 | +} |
| 139 | + |
| 140 | +func (c Network) URI() string { |
| 141 | + return fmt.Sprintf("%s://%s", c.Schema, c.HostPort()) |
| 142 | +} |
0 commit comments