diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 8864f41a7..0200ee29b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,11 +6,11 @@
-
-
-
+
+
+
@@ -84,7 +84,7 @@
-
+
@@ -95,23 +95,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -833,41 +816,46 @@
333
-
- file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go
- 380
-
-
file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go
- 222
+ 258
file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go
- 330
+ 366
-
- file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go
- 202
-
-
-
- file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go
- 403
-
-
-
- file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go
- 384
-
-
file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/datetime.go
277
+
+ file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go
+ 371
+
+
+
+ file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go
+ 220
+
+
+
+ file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go
+ 161
+
+
+
+ file://$PROJECT_DIR$/mmHa/struct.go
+ 531
+
+
+
+ file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go
+ 317
+
+
diff --git a/cmd/cmd_mqtt.go b/cmd/cmd_mqtt.go
index 43b625f84..6b22d6a6e 100644
--- a/cmd/cmd_mqtt.go
+++ b/cmd/cmd_mqtt.go
@@ -249,7 +249,7 @@ func (c *CmdMqtt) MqttArgs(_ *cobra.Command, _ []string) error {
break
}
- c.points, c.Error = cmds.Api.SunGrow.DevicePointAttrsMap(nil, "")
+ c.points, c.Error = cmds.Api.SunGrow.DevicePointAttrsMap("")
if c.Error != nil {
break
}
@@ -626,178 +626,6 @@ func (c *CmdMqtt) UpdatePoint(entry *api.DataEntry) error {
return c.Error
}
-// func FixConfig(config *mmHa.EntityConfig) {
-//
-// for range Only.Once {
-// // mdi:power-socket-au
-// // mdi:solar-power
-// // mdi:home-lightning-bolt-outline
-// // mdi:transmission-tower
-// // mdi:transmission-tower-export
-// // mdi:transmission-tower-import
-// // mdi:transmission-tower-off
-// // mdi:home-battery-outline
-// // mdi:lightning-bolt
-// // mdi:check-circle-outline | mdi:arrow-right-bold
-//
-// // Set ValueTemplate
-// switch config.Units {
-// case "MW":
-// fallthrough
-// case "kW":
-// fallthrough
-// case "W":
-// fallthrough
-// case "MWh":
-// fallthrough
-// case "kWh":
-// fallthrough
-// case "Wh":
-// fallthrough
-// case "kvar":
-// fallthrough
-// case "Hz":
-// fallthrough
-// case "V":
-// fallthrough
-// case "A":
-// fallthrough
-// case "°F":
-// fallthrough
-// case "F":
-// fallthrough
-// case "℉":
-// fallthrough
-// case "°C":
-// fallthrough
-// case "C":
-// fallthrough
-// case "℃":
-// fallthrough
-// case "%":
-// if !config.Value.Valid {
-// config.IgnoreUpdate = true
-// }
-// cnv := "| float"
-// if config.Value.String() == "" {
-// cnv = ""
-// }
-// if config.ValueName == "" {
-// config.ValueTemplate = SetDefault(config.ValueTemplate, fmt.Sprintf("{{ value_json.value %s }}", cnv))
-// } else {
-// config.ValueTemplate = SetDefault(config.ValueTemplate, fmt.Sprintf("{{ value_json.%s %s }}", config.ValueName, cnv))
-// }
-//
-// case "Bool":
-// fallthrough
-// case LabelBinarySensor:
-// config.ValueTemplate = SetDefault(config.ValueTemplate, "{{ value_json.value }}")
-//
-// default:
-// config.ValueTemplate = SetDefault(config.ValueTemplate, "{{ value_json.value }}")
-// }
-//
-// // Set DeviceClass & Icon
-// switch config.Units {
-// case "Bool":
-// fallthrough
-// case LabelBinarySensor:
-// config.DeviceClass = SetDefault(config.DeviceClass, "power")
-// config.Icon = SetDefault(config.Icon, "mdi:check-circle-outline")
-// // if !config.Value.Valid {
-// // config.Value = "false"
-// // }
-//
-// case "MW":
-// fallthrough
-// case "kW":
-// fallthrough
-// case "W":
-// config.DeviceClass = SetDefault(config.DeviceClass, "power")
-// config.Icon = SetDefault(config.Icon, "mdi:lightning-bolt")
-//
-// case "MWh":
-// fallthrough
-// case "kWh":
-// fallthrough
-// case "Wh":
-// config.DeviceClass = SetDefault(config.DeviceClass, "energy")
-// config.Icon = SetDefault(config.Icon, "mdi:lightning-bolt")
-//
-// case "kvar":
-// config.DeviceClass = SetDefault(config.DeviceClass, "reactive_power")
-// config.Icon = SetDefault(config.Icon, "mdi:lightning-bolt")
-//
-// case "Hz":
-// config.DeviceClass = SetDefault(config.DeviceClass, "frequency")
-// config.Icon = SetDefault(config.Icon, "mdi:sine-wave")
-//
-// case "V":
-// config.DeviceClass = SetDefault(config.DeviceClass, "voltage")
-// config.Icon = SetDefault(config.Icon, "mdi:current-dc")
-//
-// case "A":
-// config.DeviceClass = SetDefault(config.DeviceClass, "current")
-// config.Icon = SetDefault(config.Icon, "mdi:current-ac")
-//
-// case "°F":
-// fallthrough
-// case "F":
-// fallthrough
-// case "℉":
-// config.DeviceClass = SetDefault(config.DeviceClass, "temperature")
-// config.Units = "℉"
-// config.Icon = SetDefault(config.Icon, "mdi:thermometer")
-//
-// case "°C":
-// fallthrough
-// case "C":
-// fallthrough
-// case "℃":
-// config.DeviceClass = SetDefault(config.DeviceClass, "temperature")
-// config.Units = "°C"
-// config.Icon = SetDefault(config.Icon, "mdi:thermometer")
-//
-// case "%":
-// config.DeviceClass = SetDefault(config.DeviceClass, "battery")
-// config.Icon = SetDefault(config.Icon, "mdi:home-battery-outline")
-//
-// default:
-// config.DeviceClass = SetDefault(config.DeviceClass, "")
-// config.Icon = SetDefault(config.Icon, "")
-// }
-//
-// if config.LastReset != "" {
-// break
-// }
-//
-// // pt := api.GetDevicePoint(config.FullId)
-// // if !pt.Valid {
-// // break
-// // }
-//
-// if config.StateClass == "instant" {
-// config.StateClass = "measurement"
-// break
-// }
-//
-// if config.StateClass == "" {
-// config.StateClass = "measurement"
-// break
-// }
-//
-// // config.LastReset = pt.WhenReset()
-// config.LastResetValueTemplate = SetDefault(config.LastResetValueTemplate, "{{ value_json.last_reset | as_datetime() }}")
-// // config.LastResetValueTemplate = SetDefault(config.LastResetValueTemplate, "{{ value_json.last_reset | int | timestamp_local | as_datetime }}")
-//
-// if config.LastReset == "" {
-// config.StateClass = "measurement"
-// break
-// }
-// config.StateClass = "total"
-// }
-// }
-
// -------------------------------------------------------------------------------- //
diff --git a/iSolarCloud/api/GoStruct/valueTypes/point.go b/iSolarCloud/api/GoStruct/valueTypes/point.go
index 35df9eb07..d941ab528 100644
--- a/iSolarCloud/api/GoStruct/valueTypes/point.go
+++ b/iSolarCloud/api/GoStruct/valueTypes/point.go
@@ -581,6 +581,14 @@ func (t *PsKeys) Strings() []string {
return ret
}
+func (t *PsKeys) PsIds() []string {
+ var ret []string
+ for _, pskey := range t.PsKeys {
+ ret = append(ret, pskey.PsId)
+ }
+ return ret
+}
+
func (t *PsKeys) Set(values ...string) PsKeys {
for _, value := range values {
for _, v := range strings.Split(value, ",") {
diff --git a/iSolarCloud/highlevel_point.go b/iSolarCloud/highlevel_point.go
index 6fc65f206..764aff187 100644
--- a/iSolarCloud/highlevel_point.go
+++ b/iSolarCloud/highlevel_point.go
@@ -258,7 +258,7 @@ func (sg *SunGrow) GetAllPointsData(psIds ...string) error {
// DevicePointAttrs - Return all points associated with psIds and device_type filter.
-func (sg *SunGrow) DevicePointAttrs(psIds []string, deviceType string) (getDevicePointAttrs.Points, error) {
+func (sg *SunGrow) DevicePointAttrs(deviceType string, psIds ...string) (getDevicePointAttrs.Points, error) {
var points getDevicePointAttrs.Points
for range Only.Once {
@@ -304,12 +304,12 @@ func (sg *SunGrow) DevicePointAttrs(psIds []string, deviceType string) (getDevic
}
// DevicePointAttrsMap - Return all points associated with psIds and device_type filter.
-func (sg *SunGrow) DevicePointAttrsMap(psIds []string, deviceType string) (getDevicePointAttrs.PointsMap, error) {
+func (sg *SunGrow) DevicePointAttrsMap(deviceType string, psIds ...string) (getDevicePointAttrs.PointsMap, error) {
points := make(getDevicePointAttrs.PointsMap)
for range Only.Once {
var pa getDevicePointAttrs.Points
- pa, sg.Error = sg.DevicePointAttrs(psIds, deviceType)
+ pa, sg.Error = sg.DevicePointAttrs(deviceType, psIds...)
if sg.Error != nil {
break
}
diff --git a/iSolarCloud/highlevel_ps.go b/iSolarCloud/highlevel_ps.go
index 34f786a6b..2c5ddee85 100644
--- a/iSolarCloud/highlevel_ps.go
+++ b/iSolarCloud/highlevel_ps.go
@@ -87,7 +87,7 @@ func (sg *SunGrow) PsPoints(psIds []string, deviceType string) (string, error) {
for range Only.Once {
var points getDevicePointAttrs.Points
- points, sg.Error = sg.DevicePointAttrs(psIds, deviceType)
+ points, sg.Error = sg.DevicePointAttrs(deviceType, psIds...)
if sg.Error != nil {
break
}
@@ -174,34 +174,70 @@ func (sg *SunGrow) PsPoints(psIds []string, deviceType string) (string, error) {
return ret, sg.Error
}
+func IsInArray(find string, array ...string) bool {
+ var yes bool
+ for range Only.Once {
+ if len(array) == 0 {
+ yes = true
+ break
+ }
+
+ if find == "" {
+ break
+ }
+
+ for _, s := range array {
+ if s == find {
+ yes = true
+ break
+ }
+ }
+ }
+ return yes
+}
+
// PsPointsData - Return all points associated with psIds and device_type filter.
func (sg *SunGrow) PsPointsData(psIds []string, deviceType string, startDate string, endDate string, interval string) error {
for range Only.Once {
+ var tp []string
+ for _, i := range psIds {
+ if i != "" {
+ tp = append(tp, i)
+ }
+ }
+ psIds = tp
+
var pskeys valueTypes.PsKeys
pskeys, sg.Error = sg.GetPsKeys()
if sg.Error != nil {
break
}
+ if len(psIds) == 0 {
+ psIds = pskeys.PsIds()
+ }
+ _, _ = fmt.Fprintf(os.Stderr, "Using ps_ids: %s\n", psIds)
_, _ = fmt.Fprintf(os.Stderr, "Found ps_keys: %s\n", pskeys)
- var points getDevicePointAttrs.Points
- points, sg.Error = sg.DevicePointAttrs(psIds, deviceType)
- if sg.Error != nil {
- break
- }
-
- var ps []string
- for _, pid := range points {
- match := pskeys.MatchPsIdDeviceType(pid.PsId.String(), pid.DeviceType.String())
- if match.Valid {
- ps = append(ps, fmt.Sprintf("%s.%s", match, pid.Id))
+ for _, psId := range psIds {
+ var points getDevicePointAttrs.Points
+ points, sg.Error = sg.DevicePointAttrs(deviceType, psId)
+ if sg.Error != nil {
+ break
}
- }
- // _, _ = fmt.Fprintf(os.Stderr, "Found points: %s\n", strings.Join(ps, " "))
- sg.Error = sg.PointData(startDate, endDate, interval, ps...)
- if sg.Error != nil {
- break
+ var ps []string
+ for _, pid := range points {
+ match := pskeys.MatchPsIdDeviceType(pid.PsId.String(), pid.DeviceType.String())
+ if match.Valid {
+ ps = append(ps, fmt.Sprintf("%s.%s", match, pid.Id))
+ }
+ _, _ = fmt.Fprintf(os.Stderr, "Found points: %s\n", strings.Join(ps, " "))
+
+ sg.Error = sg.PointData(startDate, endDate, interval, ps...)
+ if sg.Error != nil {
+ break
+ }
+ }
}
}
@@ -219,7 +255,7 @@ func (sg *SunGrow) PsPointsDataSave(psIds []string, deviceType string, startDate
_, _ = fmt.Fprintf(os.Stderr, "Found ps_keys: %s\n", pskeys)
var points getDevicePointAttrs.Points
- points, sg.Error = sg.DevicePointAttrs(psIds, deviceType)
+ points, sg.Error = sg.DevicePointAttrs(deviceType, psIds...)
if sg.Error != nil {
break
}
diff --git a/mmHa/struct.go b/mmHa/struct.go
index 693e3dad0..8fc506240 100644
--- a/mmHa/struct.go
+++ b/mmHa/struct.go
@@ -518,13 +518,18 @@ func (config *EntityConfig) FixConfig() {
}
case config.Value.IsInt():
- fallthrough
- default:
vj := "value"
if config.ValueName != "" {
vj = config.ValueName
}
config.ValueTemplate = SetDefault(config.ValueTemplate, fmt.Sprintf("{{ value_json.%s | int }}", vj))
+
+ default:
+ vj := "value"
+ if config.ValueName != "" {
+ vj = config.ValueName
+ }
+ config.ValueTemplate = SetDefault(config.ValueTemplate, fmt.Sprintf("{{ value_json.%s }}", vj))
}
// Set DeviceClass & Icon