Fix PsTree bug

This commit is contained in:
MickMake
2023-05-11 07:39:17 +10:00
parent 3f78088664
commit 42d53539e2
6 changed files with 123 additions and 93 deletions

87
.idea/workspace.xml generated
View File

@@ -6,8 +6,11 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="76adadc9-ae71-42a6-82a1-66dbc8ecb14c" name="Changes" comment=""> <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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CHANGELOG.md" beforeDir="false" afterPath="$PROJECT_DIR$/CHANGELOG.md" 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_point.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_show_point.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$/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" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -81,7 +84,7 @@
<configuration name="GoSungrow" type="GoApplicationRunConfiguration" factoryName="Go Application"> <configuration name="GoSungrow" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="GoSungrow" /> <module name="GoSungrow" />
<working_directory value="$PROJECT_DIR$/../SungrowData/test" /> <working_directory value="$PROJECT_DIR$/../SungrowData/test" />
<parameters value="show ps save . . 20230504" /> <parameters value="show ps data . . " />
<envs> <envs>
<env name="GOCACHE" value="$PROJECT_DIR$/../../../../../../Media/GoCache" /> <env name="GOCACHE" value="$PROJECT_DIR$/../../../../../../Media/GoCache" />
</envs> </envs>
@@ -432,12 +435,12 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>649</line> <line>654</line>
<option name="timeStamp" value="7893" /> <option name="timeStamp" value="7893" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>627</line> <line>632</line>
<option name="timeStamp" value="7902" /> <option name="timeStamp" value="7902" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
@@ -537,7 +540,7 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>517</line> <line>522</line>
<option name="timeStamp" value="8082" /> <option name="timeStamp" value="8082" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
@@ -642,22 +645,22 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_ha.go</url> <url>file://$PROJECT_DIR$/cmd/cmd_ha.go</url>
<line>144</line> <line>134</line>
<option name="timeStamp" value="8618" /> <option name="timeStamp" value="8618" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_ha.go</url> <url>file://$PROJECT_DIR$/cmd/cmd_ha.go</url>
<line>154</line> <line>144</line>
<option name="timeStamp" value="8619" /> <option name="timeStamp" value="8619" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_ha.go</url> <url>file://$PROJECT_DIR$/cmd/cmd_ha.go</url>
<line>164</line> <line>154</line>
<option name="timeStamp" value="8620" /> <option name="timeStamp" value="8620" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_ha.go</url> <url>file://$PROJECT_DIR$/cmd/cmd_ha.go</url>
<line>176</line> <line>166</line>
<option name="timeStamp" value="8626" /> <option name="timeStamp" value="8626" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
@@ -682,29 +685,9 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>625</line> <line>630</line>
<option name="timeStamp" value="8646" /> <option name="timeStamp" value="8646" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go</url>
<line>180</line>
<option name="timeStamp" value="8654" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go</url>
<line>187</line>
<option name="timeStamp" value="8659" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go</url>
<line>188</line>
<option name="timeStamp" value="8660" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_ps.go</url>
<line>181</line>
<option name="timeStamp" value="8664" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>61</line> <line>61</line>
@@ -735,11 +718,6 @@
<line>604</line> <line>604</line>
<option name="timeStamp" value="8839" /> <option name="timeStamp" value="8839" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>412</line>
<option name="timeStamp" value="8849" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_template.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/highlevel_template.go</url>
<line>270</line> <line>270</line>
@@ -822,7 +800,7 @@
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url> <url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>462</line> <line>467</line>
<option name="timeStamp" value="8898" /> <option name="timeStamp" value="8898" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
@@ -855,6 +833,41 @@
<line>333</line> <line>333</line>
<option name="timeStamp" value="8906" /> <option name="timeStamp" value="8906" />
</line-breakpoint> </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>
<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>
<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>
</breakpoints> </breakpoints>
<default-breakpoints> <default-breakpoints>
<breakpoint type="DlvErrorBreakpoint" /> <breakpoint type="DlvErrorBreakpoint" />

View File

@@ -76,18 +76,6 @@ func (c *CmdHa) AttachCommand(cmd *cobra.Command) *cobra.Command {
func (c *CmdHa) CmdLovelace(cmd *cobra.Command, args []string) error { func (c *CmdHa) CmdLovelace(cmd *cobra.Command, args []string) error {
for range Only.Once { for range Only.Once {
// if len(args) == 0 {
// fmt.Println("One of: basic graphs stats")
// _ = cmd.Help()
// break
// }
//
// var pids valueTypes.PsIds
// pids, c.Error = cmds.Api.SunGrow.GetPsIds()
// if c.Error != nil {
// break
// }
pids := cmds.Api.SunGrow.SetPsIds(args...) pids := cmds.Api.SunGrow.SetPsIds(args...)
if cmds.Api.SunGrow.Error != nil { if cmds.Api.SunGrow.Error != nil {
c.Error = cmds.Api.SunGrow.Error c.Error = cmds.Api.SunGrow.Error
@@ -95,8 +83,8 @@ func (c *CmdHa) CmdLovelace(cmd *cobra.Command, args []string) error {
} }
for _, pid := range pids { for _, pid := range pids {
var tree iSolarCloud.PsTree var trees iSolarCloud.PsTrees
tree, c.Error = cmds.Api.SunGrow.PsTreeMenu(pid.String()) trees, c.Error = cmds.Api.SunGrow.PsTreeMenu(pid.String())
if c.Error != nil { if c.Error != nil {
break break
} }
@@ -105,18 +93,20 @@ func (c *CmdHa) CmdLovelace(cmd *cobra.Command, args []string) error {
var DeviceType22 string var DeviceType22 string
var DeviceType43 string var DeviceType43 string
for _, device := range tree.Devices { for pid2 := range trees {
if device.DeviceType.Match(14) { for _, device := range trees[pid2].Devices {
DeviceType14 = device.PsKey.String() if device.DeviceType.Match(14) {
continue DeviceType14 = device.PsKey.String()
} continue
if device.DeviceType.Match(22) { }
DeviceType22 = device.PsKey.String() if device.DeviceType.Match(22) {
continue DeviceType22 = device.PsKey.String()
} continue
if device.DeviceType.Match(43) { }
DeviceType43 = device.PsKey.String() if device.DeviceType.Match(43) {
continue DeviceType43 = device.PsKey.String()
continue
}
} }
} }
@@ -177,6 +167,7 @@ func (c *CmdHa) CmdLovelace(cmd *cobra.Command, args []string) error {
return c.Error return c.Error
} }
const lovelaceBasic = `views: const lovelaceBasic = `views:
- theme: Backend-selected - theme: Backend-selected
title: Status title: Status

View File

@@ -124,7 +124,7 @@ func (c *CmdShow) AttachPsTree(cmd *cobra.Command) *cobra.Command {
} }
func (c *CmdShow) funcPsTree(_ *cobra.Command, args []string) error { func (c *CmdShow) funcPsTree(_ *cobra.Command, args []string) error {
for range Only.Once { for range Only.Once {
var pids iSolarCloud.PsTree var pids iSolarCloud.PsTrees
pids, c.Error = cmds.Api.SunGrow.PsTreeMenu(args...) pids, c.Error = cmds.Api.SunGrow.PsTreeMenu(args...)
if c.Error != nil { if c.Error != nil {
break break

View File

@@ -267,27 +267,29 @@ func SetDateTimeValue(value time.Time) DateTime {
func (dt *DateTime) GetDayStartTimestamp() string { func (dt *DateTime) GetDayStartTimestamp() string {
var ret string var ret string
f1 := dt.Time.Round(time.Hour * 24) f1 := time.Date(dt.Time.Year(), dt.Time.Month(), dt.Time.Day(), 0, 0, 0, 0, dt.Time.Location())
ret = f1.Format(DateTimeLayoutSecond) ret = f1.Format(DateTimeLayoutSecond)
return ret return ret
// return fmt.Sprintf("%s000000", dt.Time.Format(DtLayoutDay)) // return fmt.Sprintf("%s000000", dt.Time.Format(DtLayoutDay))
} }
func (dt *DateTime) SetDayStart() { func (dt *DateTime) SetDayStart() {
dt.Time = dt.Time.Round(time.Hour * 24) // dt.Time = dt.Time.Truncate(time.Hour * 24)
dt.Time = time.Date(dt.Time.Year(), dt.Time.Month(), dt.Time.Day(), 0, 0, 0, 0, dt.Time.Location())
dt.string = dt.Time.Format(dt.format) dt.string = dt.Time.Format(dt.format)
} }
func (dt *DateTime) GetDayEndTimestamp() string { func (dt *DateTime) GetDayEndTimestamp() string {
var ret string var ret string
f1 := dt.Time.Round(time.Hour * 24).Add(time.Hour * 24).Add(-time.Second) f1 := time.Date(dt.Time.Year(), dt.Time.Month(), dt.Time.Day(), 23, 59, 59, 0, dt.Time.Location())
ret = f1.Format(DateTimeLayoutSecond) ret = f1.Format(DateTimeLayoutSecond)
return ret return ret
// return fmt.Sprintf("%s235900", dt.Time.Format(DtLayoutDay)) // return fmt.Sprintf("%s235900", dt.Time.Format(DtLayoutDay))
} }
func (dt *DateTime) SetDayEnd() { func (dt *DateTime) SetDayEnd() {
dt.Time = dt.Time.Truncate(time.Hour * 24).Add(time.Hour * 24).Add(-time.Second) // dt.Time = dt.Time.Truncate(time.Hour * 24).Add(time.Hour * 24).Add(-time.Second)
dt.Time = time.Date(dt.Time.Year(), dt.Time.Month(), dt.Time.Day(), 23, 59, 59, 0, dt.Time.Location())
dt.string = dt.Time.Format(dt.format) dt.string = dt.Time.Format(dt.format)
} }

View File

@@ -327,28 +327,30 @@ func (sg *SunGrow) GetDevicePointAttrs(psId valueTypes.PsId) (getDevicePointAttr
var ret getDevicePointAttrs.Points var ret getDevicePointAttrs.Points
for range Only.Once { for range Only.Once {
var tree PsTree var trees PsTrees
tree, sg.Error = sg.PsTreeMenu(psId.String()) trees, sg.Error = sg.PsTreeMenu(psId.String())
if sg.Error != nil { if sg.Error != nil {
break break
} }
for _, pid := range tree.Devices { for pid := range trees {
ep := sg.GetByStruct(getDevicePointAttrs.EndPointName, for _, tree := range trees[pid].Devices {
getDevicePointAttrs.RequestData { ep := sg.GetByStruct(getDevicePointAttrs.EndPointName,
Uuid: pid.UUID, getDevicePointAttrs.RequestData{
PsId2: pid.PsId, Uuid: tree.UUID,
DeviceType2: pid.DeviceType, PsId2: tree.PsId,
}, DeviceType2: tree.DeviceType,
time.Hour * 24, },
) time.Hour*24,
if sg.IsError() { )
break if sg.IsError() {
} break
}
data := getDevicePointAttrs.Assert(ep) data := getDevicePointAttrs.Assert(ep)
ret = append(ret, data.Points()...) ret = append(ret, data.Points()...)
// more := sg.GetDevicePointNames(pid.DeviceType) // more := sg.GetDevicePointNames(pid.DeviceType)
}
} }
} }
@@ -377,6 +379,9 @@ func (sg *SunGrow) getPointData(startDate string, endDate string, interval strin
// Also set the startDate based on the ps_id deployment endDate if not set. // Also set the startDate based on the ps_id deployment endDate if not set.
sd := valueTypes.NewDateTime(startDate) sd := valueTypes.NewDateTime(startDate)
if startDate == "" {
sd.SetDayStart()
}
var ed valueTypes.DateTime var ed valueTypes.DateTime
if endDate == "" { if endDate == "" {
ed = sd ed = sd

View File

@@ -274,14 +274,16 @@ func (sg *SunGrow) GetPsKeys() (valueTypes.PsKeys, error) {
// -------------------------------------------------------------------------------- // // -------------------------------------------------------------------------------- //
// Method 2: PsTreeMenu // Method 2: PsTreeMenu
var tree PsTree var trees PsTrees
tree, sg.Error = sg.PsTreeMenu() trees, sg.Error = sg.PsTreeMenu()
if sg.Error != nil { if sg.Error != nil {
break break
} }
for _, pid := range tree.Devices { for pid := range trees {
// pskey := fmt.Sprintf("%s_%s_%s_%s", pid.PsId, pid.DeviceType, pid.PsKey.DeviceCode, pid.PsKey.ChannelId) for _, tree := range trees[pid].Devices {
pskeys = append(pskeys, pid.PsKey.String()) // pskey := fmt.Sprintf("%s_%s_%s_%s", pid.PsId, pid.DeviceType, pid.PsKey.DeviceCode, pid.PsKey.ChannelId)
pskeys = append(pskeys, tree.PsKey.String())
}
} }
if len(pskeys) > 0 { if len(pskeys) > 0 {
ret.Set(pskeys...) ret.Set(pskeys...)
@@ -449,8 +451,8 @@ func (sg *SunGrow) GetPsIds() (valueTypes.PsIds, error) {
// PsTreeMenu - WebIscmAppService.getPsTreeMenu // PsTreeMenu - WebIscmAppService.getPsTreeMenu
func (sg *SunGrow) PsTreeMenu(psIds ...string) (PsTree, error) { func (sg *SunGrow) PsTreeMenu(psIds ...string) (PsTrees, error) {
var ret PsTree ret := make(PsTrees)
for range Only.Once { for range Only.Once {
pids := sg.SetPsIds(psIds...) pids := sg.SetPsIds(psIds...)
@@ -469,7 +471,9 @@ func (sg *SunGrow) PsTreeMenu(psIds ...string) (PsTree, error) {
data := getPsTreeMenu.Assert(ep) data := getPsTreeMenu.Assert(ep)
ret.Scan(data.Response.ResultData.List, false) var p PsTree
p.Scan(data.Response.ResultData.List, false)
ret[psId.String()] = p
} }
} }
@@ -515,6 +519,10 @@ func (p *PsTree) Scan(devices []getPsTreeMenu.Ps, print bool) {
p.Map = make(map[string]*Ps) p.Map = make(map[string]*Ps)
for _, ps := range p.Devices { for _, ps := range p.Devices {
name := ps.UpUUID.String() name := ps.UpUUID.String()
// if name == "0" {
// // name = ps.PsId.String()
// }
// fmt.Printf("[%s]\tParent:%s\tSelf: - %s\t%s\t%s\t%s\n", name, ps.UpUUID, ps.UUID, ps.PsId, ps.PsKey, ps.DeviceName) // fmt.Printf("[%s]\tParent:%s\tSelf: - %s\t%s\t%s\t%s\n", name, ps.UpUUID, ps.UUID, ps.PsId, ps.PsKey, ps.DeviceName)
if _, ok := p.Map[name]; !ok { if _, ok := p.Map[name]; !ok {
p.Map[name] = &Ps { p.Map[name] = &Ps {
@@ -553,6 +561,17 @@ func (p *PsTree) loop(current string, count int, depth int) {
} }
type PsTrees map[string]PsTree
func (p PsTrees) String() string {
var ret string
for i := range p {
ret += p[i].String()
}
return ret
}
// QueryDeviceListForBackSys - WebIscmAppService.queryDeviceListForBackSys // QueryDeviceListForBackSys - WebIscmAppService.queryDeviceListForBackSys
func (sg *SunGrow) QueryDeviceListForBackSys(psId string) ([]queryDeviceListForBackSys.Device, error) { func (sg *SunGrow) QueryDeviceListForBackSys(psId string) ([]queryDeviceListForBackSys.Device, error) {
var ret []queryDeviceListForBackSys.Device var ret []queryDeviceListForBackSys.Device