v3.0.6 - small fixups.

This commit is contained in:
MickMake 2023-05-15 21:15:06 +10:00
parent 42d53539e2
commit 23f00cf280
6 changed files with 104 additions and 239 deletions

74
.idea/workspace.xml generated
View File

@ -6,11 +6,11 @@
<component name="ChangeListManager">
<list default="true" id="76adadc9-ae71-42a6-82a1-66dbc8ecb14c" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_ha.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_ha.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_show_psid.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_show_psid.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/datetime.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/datetime.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_mqtt.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_mqtt.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/point.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/point.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/highlevel_point.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/highlevel_point.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/highlevel_ps.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/highlevel_ps.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/mmHa/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/struct.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -84,7 +84,7 @@
<configuration name="GoSungrow" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="GoSungrow" />
<working_directory value="$PROJECT_DIR$/../SungrowData/test" />
<parameters value="show ps data . . " />
<parameters value="mqtt run" />
<envs>
<env name="GOCACHE" value="$PROJECT_DIR$/../../../../../../Media/GoCache" />
</envs>
@ -95,23 +95,6 @@
<output_directory value="$PROJECT_DIR$/bin" />
<method v="2" />
</configuration>
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="GoSungrow" />
<working_directory value="$PROJECT_DIR$" />
<kind value="FILE" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="GoSungrow" />
<working_directory value="$PROJECT_DIR$" />
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<method v="2" />
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TypeScriptGeneratedFilesManager">
@ -833,41 +816,46 @@
<line>333</line>
<option name="timeStamp" value="8906" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>380</line>
<option name="timeStamp" value="8909" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go</url>
<line>222</line>
<line>258</line>
<option name="timeStamp" value="8910" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go</url>
<line>330</line>
<line>366</line>
<option name="timeStamp" value="8914" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go</url>
<line>202</line>
<option name="timeStamp" value="8924" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>403</line>
<option name="timeStamp" value="8925" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>384</line>
<option name="timeStamp" value="8927" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/datetime.go</url>
<line>277</line>
<option name="timeStamp" value="8928" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>371</line>
<option name="timeStamp" value="8929" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go</url>
<line>220</line>
<option name="timeStamp" value="8931" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>161</line>
<option name="timeStamp" value="8935" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/mmHa/struct.go</url>
<line>531</line>
<option name="timeStamp" value="8936" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>317</line>
<option name="timeStamp" value="8937" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint type="DlvErrorBreakpoint" />

View File

@ -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"
// }
// }
// -------------------------------------------------------------------------------- //

View File

@ -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, ",") {

View File

@ -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
}

View File

@ -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
}

View File

@ -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