Add 'save' sub-cmd

This commit is contained in:
MickMake 2023-05-10 06:49:35 +10:00
parent d25c98b89d
commit b0f7ad2831
25 changed files with 920 additions and 171 deletions

252
.idea/workspace.xml generated
View File

@ -5,7 +5,34 @@
</component>
<component name="ChangeListManager">
<list default="true" id="76adadc9-ae71-42a6-82a1-66dbc8ecb14c" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/cmd/cmd_const.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_api.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$/cmd/cmd_show_device.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_show_device.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$/cmd/cmd_show_template.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_show_template.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/defaults/const.go" beforeDir="false" afterPath="$PROJECT_DIR$/defaults/const.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/example.go" beforeDir="false" afterPath="$PROJECT_DIR$/example/example.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/file.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/file.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_graph.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_graph.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.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/api/GoStruct/valueTypes/uv.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/struct_data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/struct_data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/struct_point.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/struct_point.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/data_request.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/data_request.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/highlevel_device.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/highlevel_device.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$/iSolarCloud/highlevel_template.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/highlevel_template.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/mmHa/binary_sensor.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/binary_sensor.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" />
@ -78,10 +105,10 @@
<component name="RunManager">
<configuration name="GoSungrow" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="GoSungrow" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="mqtt run" />
<working_directory value="$PROJECT_DIR$/../SungrowData/test" />
<parameters value="show ps save . . 20230504" />
<envs>
<env name="GOCACHE" value="/Volumes/Media/GoCache" />
<env name="GOCACHE" value="$PROJECT_DIR$/../../../../../../Media/GoCache" />
</envs>
<kind value="PACKAGE" />
<package value="GoSungrow" />
@ -90,6 +117,23 @@
<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">
@ -203,12 +247,12 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>960</line>
<line>964</line>
<option name="timeStamp" value="5785" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>971</line>
<line>975</line>
<option name="timeStamp" value="5786" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -238,37 +282,37 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>931</line>
<line>937</line>
<option name="timeStamp" value="6789" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>908</line>
<line>914</line>
<option name="timeStamp" value="6790" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>841</line>
<line>847</line>
<option name="timeStamp" value="6792" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>796</line>
<line>802</line>
<option name="timeStamp" value="6794" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>756</line>
<line>762</line>
<option name="timeStamp" value="6796" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>670</line>
<line>676</line>
<option name="timeStamp" value="6800" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>1185</line>
<line>1191</line>
<option name="timeStamp" value="6822" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -293,7 +337,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>592</line>
<line>595</line>
<option name="timeStamp" value="7135" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -363,7 +407,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data_request.go</url>
<line>509</line>
<line>511</line>
<option name="timeStamp" value="7380" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -383,27 +427,27 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data_request.go</url>
<line>818</line>
<line>841</line>
<option name="timeStamp" value="7600" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_graph.go</url>
<line>168</line>
<line>169</line>
<option name="timeStamp" value="7684" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_graph.go</url>
<line>161</line>
<line>162</line>
<option name="timeStamp" value="7685" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_graph.go</url>
<line>229</line>
<line>230</line>
<option name="timeStamp" value="7689" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_graph.go</url>
<line>757</line>
<line>758</line>
<option name="timeStamp" value="7735" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -413,12 +457,12 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>566</line>
<line>649</line>
<option name="timeStamp" value="7893" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>544</line>
<line>627</line>
<option name="timeStamp" value="7902" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -513,17 +557,17 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>440</line>
<line>443</line>
<option name="timeStamp" value="8080" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>434</line>
<line>517</line>
<option name="timeStamp" value="8082" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>482</line>
<line>519</line>
<option name="timeStamp" value="8097" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -533,12 +577,12 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>546</line>
<line>549</line>
<option name="timeStamp" value="8129" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>464</line>
<line>467</line>
<option name="timeStamp" value="8144" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -573,7 +617,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>996</line>
<line>1002</line>
<option name="timeStamp" value="8365" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -643,14 +687,9 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_show_psid.go</url>
<line>253</line>
<line>283</line>
<option name="timeStamp" value="8627" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>342</line>
<option name="timeStamp" value="8629" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_meta.go</url>
<line>46</line>
@ -666,14 +705,9 @@
<line>22</line>
<option name="timeStamp" value="8641" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>367</line>
<option name="timeStamp" value="8645" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>542</line>
<line>625</line>
<option name="timeStamp" value="8646" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -701,11 +735,6 @@
<line>61</line>
<option name="timeStamp" value="8699" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/mmHa/struct.go</url>
<line>533</line>
<option name="timeStamp" value="8759" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>253</line>
@ -716,6 +745,141 @@
<line>82</line>
<option name="timeStamp" value="8828" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>599</line>
<option name="timeStamp" value="8837" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>602</line>
<option name="timeStamp" value="8838" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>605</line>
<option name="timeStamp" value="8839" />
</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">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_template.go</url>
<line>270</line>
<option name="timeStamp" value="8865" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_show_template.go</url>
<line>191</line>
<option name="timeStamp" value="8867" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>368</line>
<option name="timeStamp" value="8872" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>522</line>
<option name="timeStamp" value="8874" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>499</line>
<option name="timeStamp" value="8875" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>496</line>
<option name="timeStamp" value="8876" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>487</line>
<option name="timeStamp" value="8877" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>484</line>
<option name="timeStamp" value="8878" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>481</line>
<option name="timeStamp" value="8879" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>502</line>
<option name="timeStamp" value="8880" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>511</line>
<option name="timeStamp" value="8881" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>347</line>
<option name="timeStamp" value="8892" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>354</line>
<option name="timeStamp" value="8893" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>473</line>
<option name="timeStamp" value="8894" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_show_psid.go</url>
<line>250</line>
<option name="timeStamp" value="8895" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>600</line>
<option name="timeStamp" value="8897" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>462</line>
<option name="timeStamp" value="8898" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>486</line>
<option name="timeStamp" value="8900" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_table.go</url>
<line>563</line>
<option name="timeStamp" value="8901" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>342</line>
<option name="timeStamp" value="8902" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>428</line>
<option name="timeStamp" value="8903" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_meta.go</url>
<line>110</line>
<option name="timeStamp" value="8905" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>347</line>
<option name="timeStamp" value="8906" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint type="DlvErrorBreakpoint" />

View File

@ -24,6 +24,7 @@ const (
flagApiLastLogin = "token-expiry"
flagApiOutputType = "out"
flagApiSaveFile = "save"
flagApiDirectory = "dir"
)
//goland:noinspection GoNameStartsWithPackageName
@ -31,18 +32,19 @@ type CmdApi struct {
CmdDefault
// iSolarCloud api
ApiTimeout time.Duration
Url string
Username string
Password string
AppKey string
LastLogin string
ApiToken string
ApiTimeout time.Duration
Url string
Username string
Password string
AppKey string
LastLogin string
ApiToken string
ApiTokenFile string
OutputType string
SaveFile bool
OutputType string
SaveFile bool
Directory string
SunGrow *iSolarCloud.SunGrow
SunGrow *iSolarCloud.SunGrow
}
@ -255,6 +257,8 @@ func (c *CmdApi) AttachFlags(cmd *cobra.Command, viper *viper.Viper) {
_ = cmd.PersistentFlags().MarkHidden(flagApiOutputType)
cmd.PersistentFlags().BoolVarP(&c.SaveFile, flagApiSaveFile, "s", false, "Save output as a file.")
viper.SetDefault(flagApiSaveFile, false)
cmd.PersistentFlags().StringVarP(&c.Directory, flagApiDirectory, "", "", "Save output base directory.")
viper.SetDefault(flagApiDirectory, "")
}
}

5
cmd/cmd_const.go Normal file
View File

@ -0,0 +1,5 @@
package cmd
const (
ArgsDateInterval = "[YYYYmmdd[HHMMSS] | .] [YYYYmmdd[HHMMSS] | .] [interval | .]"
)

View File

@ -106,7 +106,7 @@ func (c *CmdShow) funcDevicePoints(_ *cobra.Command, args []string) error {
func (c *CmdShow) AttachDeviceData(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "data <device_type> [start date] [end date] [interval]",
Use: "data <device_type> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Device"},
Short: fmt.Sprintf("Generate points table for a given device_type."),
@ -139,7 +139,7 @@ func (c *CmdShow) funcDeviceData(_ *cobra.Command, args []string) error {
func (c *CmdShow) AttachDeviceGraph(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "graph <device_type> [start date] [end date] [interval]",
Use: "graph <device_type> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Device"},
Short: fmt.Sprintf("Generate graphs of points for a given device_type."),
@ -170,6 +170,39 @@ func (c *CmdShow) funcDeviceGraph(_ *cobra.Command, args []string) error {
return c.Error
}
func (c *CmdShow) AttachDeviceSave(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "save <device_type> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Device"},
Short: fmt.Sprintf("Generate points table for a given device_type."),
Long: fmt.Sprintf("Generate points table for a given device_type."),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcDeviceSave,
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(self)
self.Example = cmdHelp.PrintExamples(self,
"11 20221201 20221202 30",
"11 20221201 20221202 5",
"11 20221201 20221202",
"11 20221201",
"11",
)
return cmd
}
func (c *CmdShow) funcDeviceSave(_ *cobra.Command, args []string) error {
for range Only.Once {
cmds.Api.SunGrow.OutputType.SetTable()
args = MinimumArraySize(4, args)
c.Error = cmds.Api.SunGrow.DeviceTypeSave(args[0], args[1], args[2], args[3])
}
return c.Error
}
func (c *CmdShow) AttachDeviceModels(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "models",

View File

@ -30,17 +30,21 @@ func (c *CmdShow) AttachPoint(cmd *cobra.Command) *cobra.Command {
c.AttachPointPs(self)
c.AttachPointPsTable(self)
c.AttachPointPsGraph(self)
c.AttachPointPsSave(self)
c.AttachPointDevice(self)
c.AttachPointDeviceTable(self)
c.AttachPointDeviceGraph(self)
c.AttachPointDeviceSave(self)
c.AttachPointTemplate(self)
c.AttachPointTemplateTable(self)
c.AttachPointTemplateGraph(self)
c.AttachPointTemplateSave(self)
c.AttachPointData(self)
c.AttachPointGraph(self)
c.AttachPointSave(self)
c.AttachPointScan(self)
}
@ -69,7 +73,7 @@ func (c *CmdShow) AttachPointPs(cmd *cobra.Command) *cobra.Command {
func (c *CmdShow) AttachPointPsTable(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "ps-data <ps_ids | .> <device_type | .> (start)<YYYYmmdd[HHMMSS]> (end)<YYYYmmdd[HHMMSS]> <interval_minutes | .>",
Use: "ps-data <ps_ids | .> <device_type | .> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate points table for a given ps_id."),
@ -93,7 +97,7 @@ func (c *CmdShow) AttachPointPsTable(cmd *cobra.Command) *cobra.Command {
func (c *CmdShow) AttachPointPsGraph(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "ps-graph <ps_ids | .> <device_type | .> (start)<YYYYmmdd[HHMMSS]> (end)<YYYYmmdd[HHMMSS]> <interval_minutes | .>",
Use: "ps-graph <ps_ids | .> <device_type | .> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate graphs of points for a given ps_id."),
@ -115,6 +119,30 @@ func (c *CmdShow) AttachPointPsGraph(cmd *cobra.Command) *cobra.Command {
return cmd
}
func (c *CmdShow) AttachPointPsSave(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "ps-graph <ps_ids | .> <device_type | .> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate and save data points for a given ps_id."),
Long: fmt.Sprintf("Generate and save data points for a given ps_id."),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcPsSave,
Args: cobra.MinimumNArgs(0),
}
cmd.AddCommand(self)
self.Example = cmdHelp.PrintExamples(self,
"1171348 43 20221201 20221202 10",
"1171348 43 20221201 20221202",
"1171348 43 20221201",
". . 20221201 20221202 60",
)
return cmd
}
func (c *CmdShow) AttachPointDevice(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
@ -140,7 +168,7 @@ func (c *CmdShow) AttachPointDevice(cmd *cobra.Command) *cobra.Command {
func (c *CmdShow) AttachPointDeviceTable(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "device-data <device_id> [start date] [end date] [interval]",
Use: "device-data <device_id> " + ArgsDateInterval,
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate points table for a given device."),
Long: fmt.Sprintf("Generate points table for a given device."),
@ -164,7 +192,7 @@ func (c *CmdShow) AttachPointDeviceTable(cmd *cobra.Command) *cobra.Command {
func (c *CmdShow) AttachPointDeviceGraph(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "device-graph <template_id> [start date] [end date] [interval]",
Use: "device-graph <template_id> " + ArgsDateInterval,
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate graphs of points for a given device."),
Long: fmt.Sprintf("Generate graphs of points for a given device."),
@ -186,6 +214,30 @@ func (c *CmdShow) AttachPointDeviceGraph(cmd *cobra.Command) *cobra.Command {
return cmd
}
func (c *CmdShow) AttachPointDeviceSave(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "device-graph <template_id> " + ArgsDateInterval,
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate and save data points for a given device."),
Long: fmt.Sprintf("Generate and save data points for a given device."),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcDeviceSave,
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(self)
self.Example = cmdHelp.PrintExamples(self,
"8092 20221201 20221202 30",
"8092 20221201 20221202 5",
"8092 20221201 20221202",
"8092 20221201",
"8092",
)
return cmd
}
func (c *CmdShow) AttachPointTemplate(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
@ -211,7 +263,7 @@ func (c *CmdShow) AttachPointTemplate(cmd *cobra.Command) *cobra.Command {
func (c *CmdShow) AttachPointTemplateTable(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "template-data <template_id> [start date] [end date] [interval]",
Use: "template-data <template_id> " + ArgsDateInterval,
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate points table for a given report template."),
Long: fmt.Sprintf("Generate points table for a given report template."),
@ -235,7 +287,7 @@ func (c *CmdShow) AttachPointTemplateTable(cmd *cobra.Command) *cobra.Command {
func (c *CmdShow) AttachPointTemplateGraph(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "template-graph <template_id> [start date] [end date] [interval]",
Use: "template-graph <template_id> " + ArgsDateInterval,
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate graphs of points for a given report template."),
Long: fmt.Sprintf("Generate graphs of points for a given report template."),
@ -257,10 +309,34 @@ func (c *CmdShow) AttachPointTemplateGraph(cmd *cobra.Command) *cobra.Command {
return cmd
}
func (c *CmdShow) AttachPointTemplateSave(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "template-graph <template_id> " + ArgsDateInterval,
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Generate and save data points for a given report template."),
Long: fmt.Sprintf("Generate and save data points for a given report template."),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcTemplateSave,
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(self)
self.Example = cmdHelp.PrintExamples(self,
"8092 20221201 20221202 30",
"8092 20221201 20221202 5",
"8092 20221201 20221202",
"8092 20221201",
"8092",
)
return cmd
}
func (c *CmdShow) AttachPointData(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "data (start)<YYYYmmdd[HHMMSS]> (end)<YYYYmmdd[HHMMSS]> <interval_minutes | .> <points ...>",
Use: "data " + ArgsDateInterval + " <points ...>",
Aliases: []string{},
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Get data points."),
@ -281,8 +357,9 @@ func (c *CmdShow) AttachPointData(cmd *cobra.Command) *cobra.Command {
}
func (c *CmdShow) funcPointData(_ *cobra.Command, args []string) error {
for range Only.Once {
cmds.Api.SunGrow.OutputType.SetTable()
args = MinimumArraySize(4, args)
cmds.Api.SunGrow.OutputType.SetTable()
c.Error = cmds.Api.SunGrow.PointData(args[0], args[1], args[2], args[3:]...)
if c.Error != nil {
break
@ -293,7 +370,7 @@ func (c *CmdShow) funcPointData(_ *cobra.Command, args []string) error {
func (c *CmdShow) AttachPointGraph(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "graph (start)<YYYYmmdd[HHMMSS]> (end)<YYYYmmdd[HHMMSS]> <interval_minutes | .> <points ...>",
Use: "graph " + ArgsDateInterval + " <points ...>",
Aliases: []string{},
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Graph data points."),
@ -314,8 +391,9 @@ func (c *CmdShow) AttachPointGraph(cmd *cobra.Command) *cobra.Command {
}
func (c *CmdShow) funcPointGraph(_ *cobra.Command, args []string) error {
for range Only.Once {
cmds.Api.SunGrow.OutputType.SetGraph()
args = MinimumArraySize(4, args)
cmds.Api.SunGrow.OutputType.SetGraph()
c.Error = cmds.Api.SunGrow.PointData(args[0], args[1], args[2], args[3:]...)
if c.Error != nil {
break
@ -324,6 +402,38 @@ func (c *CmdShow) funcPointGraph(_ *cobra.Command, args []string) error {
return c.Error
}
func (c *CmdShow) AttachPointSave(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "save " + ArgsDateInterval + " <points ...>",
Aliases: []string{},
Annotations: map[string]string{"group": "Point"},
Short: fmt.Sprintf("Get data points."),
Long: fmt.Sprintf("Get data points."),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcPointSave,
Args: cobra.MinimumNArgs(4),
}
cmd.AddCommand(self)
self.Example = cmdHelp.PrintExamples(self,
"20221101 20221104 5 1171348_11_0_0.p83033,1171348_11_0_0.p83072,1171348_11_0_0.p83128",
"20221101 20221104 . 1171348_11_0_0.p83033 1171348_11_0_0.p83072 1171348_11_0_0.p83128",
)
return cmd
}
func (c *CmdShow) funcPointSave(_ *cobra.Command, args []string) error {
for range Only.Once {
args = MinimumArraySize(4, args)
c.Error = cmds.Api.SunGrow.PointDataSave(args[0], args[1], args[2], args[3:]...)
if c.Error != nil {
break
}
}
return c.Error
}
func (c *CmdShow) AttachPointScan(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{

View File

@ -37,6 +37,7 @@ func (c *CmdShow) AttachPs(cmd *cobra.Command) *cobra.Command {
c.AttachPsPoints(self)
c.AttachPsData(self)
c.AttachPsGraph(self)
c.AttachPsSave(self)
}
return c.SelfCmd
}
@ -168,7 +169,7 @@ func (c *CmdShow) funcPsPoints(_ *cobra.Command, args []string) error {
func (c *CmdShow) AttachPsData(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "data <ps_ids | .> [device_type | .] [start date] [end date] [interval]",
Use: "data <ps_ids | .> [device_type | .] " + ArgsDateInterval,
Aliases: []string{"point"},
Annotations: map[string]string{"group": "PsId"},
Short: fmt.Sprintf("Generate points table for a given ps_id."),
@ -198,7 +199,7 @@ func (c *CmdShow) funcPsData(_ *cobra.Command, args []string) error {
func (c *CmdShow) AttachPsGraph(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "graph <ps_ids | .> [device_type]",
Use: "graph <ps_ids | .> [device_type | .] " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "PsId"},
Short: fmt.Sprintf("Generate graphs of points for a given ps_id."),
@ -226,6 +227,35 @@ func (c *CmdShow) funcPsGraph(_ *cobra.Command, args []string) error {
return c.Error
}
func (c *CmdShow) AttachPsSave(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "save <ps_ids | .> [device_type | .] " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "PsId"},
Short: fmt.Sprintf("Generate and save data points for a given ps_id."),
Long: fmt.Sprintf("Generate and save data points for a given ps_id."),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcPsSave,
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(self)
self.Example = cmdHelp.PrintExamples(self, "")
return cmd
}
func (c *CmdShow) funcPsSave(_ *cobra.Command, args []string) error {
for range Only.Once {
args = MinimumArraySize(5, args)
c.Error = cmds.Api.SunGrow.PsPointsDataSave(strings.Split(args[0], ","), args[1], args[2], args[3], args[4])
if c.Error != nil {
break
}
}
return c.Error
}
func (c *CmdShow) AttachPsDetail(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "detail [ps_id ...]",

View File

@ -31,6 +31,7 @@ func (c *CmdShow) AttachTemplate(cmd *cobra.Command) *cobra.Command {
c.AttachTemplatePoints(self)
c.AttachTemplateData(self)
c.AttachTemplateGraph(self)
c.AttachTemplateSave(self)
}
return c.SelfCmd
}
@ -90,7 +91,7 @@ func (c *CmdShow) funcTemplatePoints(_ *cobra.Command, args []string) error {
func (c *CmdShow) AttachTemplateData(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "data <template_id> [start date] [end date] [interval]",
Use: "data <template_id> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Template"},
Short: fmt.Sprintf("Generate points table for a given template_id."),
@ -114,16 +115,19 @@ func (c *CmdShow) AttachTemplateData(cmd *cobra.Command) *cobra.Command {
}
func (c *CmdShow) funcTemplateData(_ *cobra.Command, args []string) error {
for range Only.Once {
cmds.Api.SunGrow.OutputType.SetTable()
args = MinimumArraySize(4, args)
cmds.Api.SunGrow.OutputType.SetTable()
c.Error = cmds.Api.SunGrow.TemplateData(args[0], args[1], args[2], args[3])
if c.Error != nil {
break
}
}
return c.Error
}
func (c *CmdShow) AttachTemplateGraph(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "graph <template_id> [start date] [end date] [interval]",
Use: "graph <template_id> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Template"},
Short: fmt.Sprintf("Generate graphs of points for a given template_id."),
@ -147,9 +151,47 @@ func (c *CmdShow) AttachTemplateGraph(cmd *cobra.Command) *cobra.Command {
}
func (c *CmdShow) funcTemplateGraph(_ *cobra.Command, args []string) error {
for range Only.Once {
cmds.Api.SunGrow.OutputType.SetGraph()
args = MinimumArraySize(4, args)
cmds.Api.SunGrow.OutputType.SetGraph()
c.Error = cmds.Api.SunGrow.TemplateData(args[0], args[1], args[2], args[3])
if c.Error != nil {
break
}
}
return c.Error
}
func (c *CmdShow) AttachTemplateSave(cmd *cobra.Command) *cobra.Command {
var self = &cobra.Command{
Use: "save <template_id> " + ArgsDateInterval,
Aliases: []string{},
Annotations: map[string]string{"group": "Template"},
Short: fmt.Sprintf("Generate and save data points for a given template_id."),
Long: fmt.Sprintf("Generate and save data points for a given template_id."),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcTemplateSave,
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(self)
self.Example = cmdHelp.PrintExamples(self,
"8092 20221201 20221202 30",
"8092 20221201 20221202 5",
"8092 20221201 20221202",
"8092 20221201",
"8092",
)
return cmd
}
func (c *CmdShow) funcTemplateSave(_ *cobra.Command, args []string) error {
for range Only.Once {
args = MinimumArraySize(4, args)
c.Error = cmds.Api.SunGrow.TemplateDataSave(args[0], args[1], args[2], args[3])
if c.Error != nil {
break
}
}
return c.Error
}

View File

@ -19,7 +19,7 @@ var Examples string
const (
Description = "GoSungrow - GoLang implementation to access the iSolarCloud API updated by SunGrow inverters"
BinaryName = "GoSungrow"
BinaryVersion = "3.0.4"
BinaryVersion = "3.0.6"
SourceRepo = "github.com/MickMake/" + BinaryName
BinaryRepo = "github.com/MickMake/" + BinaryName

View File

@ -183,7 +183,7 @@ func Example2(startDate string, endDate string, interval string, points []string
break
}
table := response.Data.CreateResultTable(false)
table := response.Data.CreateResultTable(false, "")
table.OutputType = output.TypeTable
table.SetSaveFile(false)
sg.Error = table.Output()
@ -197,7 +197,7 @@ func Example2(startDate string, endDate string, interval string, points []string
GraphRequest: output.GraphRequest{},
}
sg.Error = response.OutputDataTables()
sg.Error = response.OutputDataTables("")
if sg.IsError() {
break
}

View File

@ -244,7 +244,7 @@ func (e *EndPoint) GetData() api.DataMap {
foo := entries.CopyPointFromName(name, epp, name, point.PointName.String())
foo.Value.Reset()
foo.Value.AddFloat("", point.Unit.String(), "", point.Value.Value())
// foo.Value.SetUnit(point.Unit.String())
// foo.SetUnit(point.Unit.String())
foo.Value.SetDeviceId(deviceId)
foo.DataStructure.PointGroupName = point.PointGroupName.String()
foo.DataStructure.PointDevice = deviceId
@ -347,9 +347,9 @@ func (e *EndPoint) SetBatteryPoints(epp GoStruct.EndPointPath, entries api.DataM
dailyPvEnergy := entries.GetReflect(epp.AddString("p13112"))
batteryChargeEnergyPercent := entries.CopyPoint(dailyPvEnergy, epp, "battery_charge_energy_percent", "Battery Charge Percent (Calc)")
batteryChargeEnergyPercent.SetValue(entries.GetPercent(batteryChargeEnergy, dailyPvEnergy, 1))
batteryChargeEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
batteryChargeEnergyPercent.Value.SetUnit("%")
batteryChargeEnergyPercent.SetValue(entries.GetPercent(batteryChargeEnergy, dailyPvEnergy, 1))
batteryChargeEnergyPercent.SetUnit("%")
// batteryChargeEnergyPercent.DataStructure.PointIcon = "mdi:battery"
@ -410,7 +410,7 @@ func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
pvToGridEnergyPercent := entries.CopyPoint(pvDailyEnergy, epp, "pv_to_grid_energy_percent", "Pv To Grid Energy Percent (Calc)")
pvToGridEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
pvToGridEnergyPercent.SetValue(entries.GetPercent(pvToGridEnergy, pvDailyEnergy, 1))
pvToGridEnergyPercent.Value.SetUnit("%")
pvToGridEnergyPercent.SetUnit("%")
pvToBatteryEnergy := entries.CopyPointFromName(epp.AddString("p13174"), epp, "pv_to_battery_energy", "Pv To Battery Energy (p13174)")
pvToBatteryEnergy.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
@ -431,7 +431,7 @@ func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
selfConsumptionOfPvPercent := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_consumption_energy_percent", "Pv Consumption Energy Percent (Calc)")
selfConsumptionOfPvPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
selfConsumptionOfPvPercent.SetValue(entries.GetPercent(selfConsumptionOfPv, pvDailyEnergy, 1))
selfConsumptionOfPvPercent.Value.SetUnit("%")
selfConsumptionOfPvPercent.SetUnit("%")
// WRONG!!! - pvToLoadPercent := entries.CopyPointFromName(epp.AddString("p13144"), epp, "pv_to_load_energy_percent", "Pv To Load Energy Percent (p13144)")
// WRONG!!! - pvToLoadEnergy := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_to_load_energy", "Pv To Load Energy (p13116)")
@ -445,14 +445,14 @@ func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
pvToLoadEnergyPercent := entries.CopyPoint(pvDailyEnergy, epp, "pv_to_load_energy_percent", "Pv To Load Energy Percent (Calc)")
pvToLoadEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
pvToLoadEnergyPercent.SetValue(entries.GetPercent(pvToLoadEnergy, totalDailyEnergy, 1))
pvToLoadEnergyPercent.Value.SetUnit("%")
pvToLoadEnergyPercent.SetUnit("%")
gridToLoadDailyEnergy := entries.GetReflect(epp.AddString("p13147"))
pvDailyEnergyPercent := entries.CopyPoint(totalDailyEnergy, epp, "pv_daily_energy_percent", "Pv Daily Energy Percent (Calc)")
pvDailyEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
dpe := totalDailyEnergy.GetValueFloat() - gridToLoadDailyEnergy.GetValueFloat()
pvDailyEnergyPercent.SetValue(api.GetPercent(dpe, totalDailyEnergy.GetValueFloat(), 1))
pvDailyEnergyPercent.Value.SetUnit("%")
pvDailyEnergyPercent.SetUnit("%")
pvEnergy := entries.CopyPointFromName(pvToLoadEnergy.PointId(), epp, "pv_energy", "Pv Energy (Calc)")
// pvDailyYield := entries.GetReflect(pvSelfConsumption.PointId())
@ -482,7 +482,7 @@ func (e *EndPoint) SetGridPoints(epp GoStruct.EndPointPath, entries api.DataMap)
gridToLoadEnergyPercent := entries.CopyPoint(totalLoadEnergy, epp, "grid_to_load_energy_percent", "")
gridToLoadEnergyPercent.DataStructure.PointUpdateFreq = GoStruct.UpdateFreqDay
gridToLoadEnergyPercent.SetValue(entries.GetPercent(gridToLoadEnergy, totalLoadEnergy, 1))
gridToLoadEnergyPercent.Value.SetUnit("%")
gridToLoadEnergyPercent.SetUnit("%")
pvToGridPower := entries.CopyPointFromName(epp.AddString("p13121"), epp, "pv_to_grid_power", "Pv To Grid Power (p13121)")
gridPower := entries.CopyPoint(gridToLoadPower, epp, "grid_power", "Grid Power (Calc)")

View File

@ -171,3 +171,65 @@ func FileExists(fn string) bool {
return yes
}
// DirExists - Checks if a directory exists.
func DirExists(fn string) bool {
var yes bool
for range Only.Once {
var err error
if fn == "" {
// err = errors.New("empty file")
break
}
var f os.FileInfo
f, err = os.Stat(fn)
if os.IsNotExist(err) {
break
}
if err != nil {
break
}
if !f.IsDir() {
// err = errors.New("file is a directory")
break
}
yes = true
}
return yes
}
// Mkdir - Create dir.
func Mkdir(fn string) bool {
var yes bool
for range Only.Once {
var err error
if fn == "" {
// err = errors.New("empty file")
break
}
var f os.FileInfo
f, err = os.Stat(fn)
if os.IsNotExist(err) {
err = os.MkdirAll(fn, 755)
if err != nil {
yes = true
}
break
}
if err != nil {
break
}
if !f.IsDir() {
// err = errors.New("file is a directory")
break
}
yes = true
}
return yes
}

View File

@ -9,6 +9,7 @@ import (
"github.com/wcharczuk/go-chart/v2"
"github.com/wcharczuk/go-chart/v2/drawing"
"os"
"path"
"strings"
"time"
)
@ -518,7 +519,7 @@ func (c *Chart) ProcessGraphData(table *Table) error {
// }
}
c.Error = c.SetFilename(table.filePrefix)
c.Error = c.SetFilename(path.Join(table.directory, table.filePrefix))
if c.Error != nil {
break
}

View File

@ -7,6 +7,7 @@ import (
"fmt"
"github.com/MickMake/GoUnify/Only"
"os"
"path"
"reflect"
"sort"
"strings"
@ -37,6 +38,7 @@ func (t *Tables) Sort() []string {
type Table struct {
name string
directory string
filePrefix string
title string
graph *Chart
@ -58,6 +60,7 @@ type Table struct {
func NewTable(headers ...string) Table {
// buf := new(bytes.Buffer)
t := Table {
directory: "",
filePrefix: "",
title: "",
tablib: tablib.NewDataset(headers),
@ -342,10 +345,16 @@ func (t *Table) AddRow(row ...interface{}) error {
func (t *Table) writeFile(data string, perm os.FileMode) error {
for range Only.Once {
fmt.Printf("Writing file '%s'\n", t.filePrefix)
t.Error = os.WriteFile(t.filePrefix, []byte(data), perm)
Mkdir(t.directory)
// if !DirExists(t.directory) {
// Mkdir(t.directory)
// }
fn := path.Join(t.directory, t.filePrefix)
fmt.Printf("Writing file '%s'\n", fn)
t.Error = os.WriteFile(fn, []byte(data), perm)
if t.Error != nil {
t.Error = errors.New(fmt.Sprintf("Unable to write to file %s - %v", t.filePrefix, t.Error))
t.Error = errors.New(fmt.Sprintf("Unable to write to file %s - %v", fn, t.Error))
break
}
}
@ -366,7 +375,7 @@ func (t *Table) GetTitle() string {
}
func (t *Table) GetFilePrefix() string {
return t.filePrefix
return path.Join(t.directory, t.filePrefix)
}
func (t *Table) SetRaw(data []byte) {
@ -406,16 +415,44 @@ func (t *Table) SetFilePrefix(prefix string, args ...interface{}) {
}
}
func (t *Table) AppendFilePrefix(prefix string, args ...interface{}) {
func (t *Table) SetDirectory(prefix string, args ...interface{}) {
for range Only.Once {
if prefix == "" {
break
}
if len(args) == 0 {
t.filePrefix += "-" + prefix
t.directory = prefix
t.directory = strings.ReplaceAll(t.directory, "[", "")
t.directory = strings.ReplaceAll(t.directory, "]", "")
break
}
t.filePrefix += "-" + fmt.Sprintf(prefix, args...)
t.directory = fmt.Sprintf(prefix, args...)
t.directory = strings.ReplaceAll(t.directory, "[", "")
t.directory = strings.ReplaceAll(t.directory, "]", "")
}
}
func (t *Table) AppendFilePrefix(prefix string, args ...interface{}) {
for range Only.Once {
if prefix == "" {
break
}
if len(args) > 0 {
prefix = fmt.Sprintf(prefix, args...)
}
t.filePrefix += "-" + prefix
}
}
func (t *Table) PrependFilePrefix(prefix string, args ...interface{}) {
for range Only.Once {
if prefix == "" {
break
}
if len(args) > 0 {
prefix = fmt.Sprintf(prefix, args...)
}
t.filePrefix = prefix + "-" + t.filePrefix
}
}

View File

@ -658,7 +658,7 @@ func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPat
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
r.SetUnit()
r.UpdateUnit()
r.Value.SetDeviceId(r.DataStructure.PointDevice)
case reflect.Slice:
@ -680,7 +680,7 @@ func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPat
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
r.SetUnit()
r.UpdateUnit()
r.Value.SetDeviceId(r.DataStructure.PointDevice)
case reflect.Map:
@ -702,7 +702,7 @@ func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPat
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
r.SetUnit()
r.UpdateUnit()
r.Value.SetDeviceId(r.DataStructure.PointDevice)
}
@ -810,7 +810,7 @@ func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, index
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
r.SetUnit()
r.UpdateUnit()
r.Value.SetDeviceId(r.DataStructure.PointDevice)
case reflect.Slice:
@ -864,7 +864,7 @@ func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, index
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
r.SetUnit()
r.UpdateUnit()
r.Value.SetDeviceId(r.DataStructure.PointDevice)
case reflect.Map:
@ -911,7 +911,7 @@ func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, index
// map[string]interface{}{ indexName.String(): r.InterfaceValue }, r.DataStructure.PointUnit,
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
r.SetUnit()
r.UpdateUnit()
r.Value.SetDeviceId(r.DataStructure.PointDevice)
@ -934,13 +934,17 @@ func (r *Reflect) SetValue(value interface{}) {
}
}
func (r *Reflect) SetUnit(unit string) {
r.Value.SetUnit(unit)
}
func (r *Reflect) SetValuePrecision(precision int) {
for range Only.Once {
r.Value.SetPrecision(precision)
}
}
func (r *Reflect) SetUnit() {
func (r *Reflect) UpdateUnit() {
for range Only.Once {
switch {
case r.Value.GetUnit() == "":
@ -981,6 +985,10 @@ func (r *Reflect) SetUnitValues(value valueTypes.UnitValues) {
func (r *Reflect) GetValueFloat() float64 {
var ret float64
for range Only.Once {
if r == nil {
break
}
v := r.Value.First()
if v == nil {
break

View File

@ -66,6 +66,8 @@ const (
DateLayout = "2006-01-02"
DateHumanLayout = "2006/01/02"
DateHumanMonth = "2006/01"
DateHumanYear = "2006"
DateLayoutDay = "20060102"
DateLayoutMonth = "200601"
DateLayoutYear = "2006"
@ -278,14 +280,14 @@ func (dt *DateTime) SetDayStart() {
func (dt *DateTime) GetDayEndTimestamp() string {
var ret string
f1 := dt.Time.Round(time.Hour * 24).Add(time.Hour * 24)
f1 := dt.Time.Round(time.Hour * 24).Add(time.Hour * 24).Add(-time.Second)
ret = f1.Format(DateTimeLayoutSecond)
return ret
// return fmt.Sprintf("%s235900", dt.Time.Format(DtLayoutDay))
}
func (dt *DateTime) SetDayEnd() {
dt.Time = dt.Time.Truncate(time.Hour * 24).Add(time.Hour * 24)
dt.Time = dt.Time.Truncate(time.Hour * 24).Add(time.Hour * 24).Add(-time.Second)
dt.string = dt.Time.Format(dt.format)
}

View File

@ -332,7 +332,10 @@ func (t *UnitValue) IsNumber() bool {
}
func (t *UnitValue) IsBool() bool {
if t.float64 != nil {
if t.bool != nil {
return true
}
if t.TypeValue == "Bool" {
return true
}
return false
@ -399,6 +402,9 @@ func (t *UnitValue) IsTypeDateTime() bool {
if t.TypeValue == "DateTime" {
return true
}
if t.UnitValue == "DateTime" {
return true
}
return false
}

View File

@ -340,6 +340,8 @@ func (dm *DataMap) CreateDataTables() Tables {
break
}
ret.Table.SetFilePrefix("%s.%s", dm.EndPoint.GetArea(), dm.StructMap.Name.String())
_, dm.Error = ret.CreateTable()
if dm.Error != nil {
break
@ -419,6 +421,7 @@ func (dm *DataMap) CreateResultTable(full bool) output.Table {
}
}
}
table.SetTitle("EndPoint Data %s.%s", dm.EndPoint.GetArea(), dm.StructMap.Name.String()) // endpoint.GetArea(), endpoint.GetName()
if dm.StructMap.Start.DataStructure.DataTableName != "" {
table.AppendTitle(" - %s", dm.StructMap.Start.DataStructure.DataTableName)

View File

@ -165,6 +165,13 @@ func (p Point) IsTotal() bool {
return false
}
func (p Point) IsBool() bool {
if p.ValueType == "Bool" {
return true
}
return false
}
func (p *Point) SetName(name string) {
if name == "" {
name = valueTypes.PointToName(p.Id)

View File

@ -55,12 +55,11 @@ type SunGrowData struct {
Args []string
endPoints []string
Request SunGrowDataRequest
Results SunGrowDataResults
Results SunGrowDataResults
sunGrow *SunGrow
outputType output.OutputType
saveAsFile bool
sunGrow *SunGrow
// outputType output.OutputType
// saveAsFile bool
cacheTimeout time.Duration
Debug bool
@ -84,15 +83,15 @@ func (sgd *SunGrowData) SetCacheTimeout(t time.Duration) {
}
func (sgd *SunGrowData) SetOutput(t string) {
sgd.outputType.Set(t)
sgd.sunGrow.OutputType.Set(t)
}
func (sgd *SunGrowData) SetOutputType(t output.OutputType) {
sgd.outputType = t
sgd.sunGrow.OutputType = t
}
func (sgd *SunGrowData) SetSaveAsFile(yes bool) {
sgd.saveAsFile = yes
sgd.sunGrow.SaveAsFile = yes
}
func (sgd *SunGrowData) SetEndpoints(endpoints ...string) {
@ -160,6 +159,7 @@ func (sgd *SunGrowData) CallEndpoint(endpoint api.EndPoint, request SunGrowDataR
response.Data = endpoint.GetEndPointData()
args := request.GetArgs(response.Data.EndPoint)
hash := request.GetArgsHash(response.Data.EndPoint)
name := endpoint.GetArea().String() + "." + endpoint.GetName().String()
var title string
var file string // + " - " + request.RequestAsFilePrefix(),
@ -173,6 +173,8 @@ func (sgd *SunGrowData) CallEndpoint(endpoint api.EndPoint, request SunGrowDataR
Name: name,
OutputType: sgd.sunGrow.OutputType,
PrimaryKey: key,
Directory: sgd.sunGrow.Directory,
FilePrefix: hash,
FileSuffix: file,
SaveAsFile: sgd.sunGrow.SaveAsFile,
TitleSuffix: args,
@ -305,6 +307,9 @@ func (sgd *SunGrowData) Process() error {
}
for _, result := range sgd.Results {
result.Response.Options.OutputType = sgd.sunGrow.OutputType
result.Response.Options.SaveAsFile = sgd.sunGrow.SaveAsFile
result.Response.Options.Directory = sgd.sunGrow.Directory
result.Response.Data.ProcessMap()
if sgd.Error != nil {
break
@ -323,6 +328,9 @@ func (sgd *SunGrowData) Output() error {
}
for _, result := range sgd.Results {
result.Response.Options.OutputType = sgd.sunGrow.OutputType
result.Response.Options.SaveAsFile = sgd.sunGrow.SaveAsFile
result.Response.Options.Directory = sgd.sunGrow.Directory
sgd.Error = result.Response.Output()
if sgd.Error != nil {
break
@ -341,6 +349,9 @@ func (sgd *SunGrowData) OutputDataTables() error {
}
for _, result := range sgd.Results {
result.Response.Options.OutputType = sgd.sunGrow.OutputType
result.Response.Options.SaveAsFile = sgd.sunGrow.SaveAsFile
result.Response.Options.Directory = sgd.sunGrow.Directory
sgd.Error = result.Response.OutputDataTables()
if sgd.Error != nil {
break
@ -369,24 +380,6 @@ func (sgd *SunGrowDataResult) Process() error {
return sgd.Error
}
// func (sgd *SunGrowDataResult) ProcessMapForMqtt() error {
// sgd.Response.Data.ProcessMapForMqtt()
// sgd.Error = sgd.Response.Data.Error
// return sgd.Error
// }
// func (sgd *SunGrowDataResult) CreateResultTable(full bool) output.Table {
// ret := sgd.Response.CreateResultTable(full)
// sgd.Error = sgd.Response.Data.Error
// return ret
// }
// func (sgd *SunGrowDataResult) CreateDataTables() api.Tables {
// tables := sgd.Response.CreateDataTables()
// sgd.Error = sgd.Response.Data.Error
// return tables
// }
func (sgd *SunGrowDataResult) Sort() []string {
return sgd.Response.Data.Sort()
}
@ -399,23 +392,15 @@ func (sgd *SunGrowDataResult) Print() {
type OutputOptions struct {
Name string
TitleSuffix string
OutputType output.OutputType
PrimaryKey string
FileSuffix string
SaveAsFile bool
GraphRequest output.GraphRequest
// table.InitGraph(output.GraphRequest {
// Title: "",
// TimeColumn: output.SetString("Date/Time"),
// SearchColumn: output.SetString("Point Id"),
// NameColumn: output.SetString("Point Name"),
// ValueColumn: output.SetString("Value"),
// UnitsColumn: output.SetString("Units"),
// SearchString: output.SetString(""),
// MinLeftAxis: output.SetFloat(0),
// MaxLeftAxis: output.SetFloat(0),
// })
OutputType output.OutputType
Directory string
SaveAsFile bool
FileSuffix string
FilePrefix string
GraphRequest output.GraphRequest
}
type SunGrowDataResponses map[string]SunGrowDataResponse
@ -426,18 +411,6 @@ type SunGrowDataResponse struct {
Error error
}
// func (sgd *SunGrowDataResponse) CreateResultTable(full bool) output.Table {
// ret := sgd.Data.CreateResultTable(full)
// sgd.Error = sgd.Data.Error
// return ret
// }
// func (sgd *SunGrowDataResponse) CreateDataTables() api.Tables {
// tables := sgd.Data.CreateDataTables()
// sgd.Error = sgd.Data.Error
// return tables
// }
func (sgd *SunGrowDataResponse) Output() error {
for range Only.Once {
// Outputs that don't drop through.
@ -446,6 +419,8 @@ func (sgd *SunGrowDataResponse) Output() error {
table.OutputType = sgd.Options.OutputType
table.SetSaveFile(sgd.Options.SaveAsFile)
table.AppendTitle(" - %s", sgd.Options.TitleSuffix)
table.SetDirectory(sgd.Options.Directory)
table.PrependFilePrefix(sgd.Options.FilePrefix)
table.AppendFilePrefix(sgd.Options.FileSuffix)
sgd.Error = table.Output()
break
@ -457,6 +432,8 @@ func (sgd *SunGrowDataResponse) Output() error {
table.OutputType = sgd.Options.OutputType
table.SetSaveFile(sgd.Options.SaveAsFile)
table.AppendTitle(" - %s", sgd.Options.TitleSuffix)
table.SetDirectory(sgd.Options.Directory)
table.PrependFilePrefix(sgd.Options.FilePrefix)
table.AppendFilePrefix(sgd.Options.FileSuffix)
sgd.Error = table.Output()
if sgd.Error != nil {
@ -571,10 +548,10 @@ func (sgd *SunGrowDataResponse) OutputDataTables() error {
sgd.Options.GraphRequest.DataColumn = &value
if sgd.Options.PrimaryKey != "" {
data.Table.SetTitle("%s - %s - %s", title, sgd.Options.PrimaryKey, value)
data.Table.SetFilePrefix("%s-%s-%s", file, sgd.Options.PrimaryKey, value)
data.Table.SetFilePrefix("%s-%s-%s-%s", sgd.Options.FilePrefix, file, sgd.Options.PrimaryKey, value)
} else {
data.Table.SetTitle("%s - %s", title, value)
data.Table.SetFilePrefix("%s-%s", file, value)
data.Table.SetFilePrefix("%s-%s-%s", sgd.Options.FilePrefix, file, value)
}
sgd.Options.GraphRequest.Title = data.Table.GetTitle()
@ -583,6 +560,7 @@ func (sgd *SunGrowDataResponse) OutputDataTables() error {
break
}
data.Table.SetDirectory(sgd.Options.Directory)
sgd.Error = data.Table.Output()
if sgd.Error != nil {
break
@ -593,6 +571,8 @@ func (sgd *SunGrowDataResponse) OutputDataTables() error {
}
data.Table.AppendTitle(" - %s", sgd.Options.TitleSuffix)
data.Table.SetDirectory(sgd.Options.Directory)
data.Table.PrependFilePrefix(sgd.Options.FilePrefix)
data.Table.AppendFilePrefix(sgd.Options.FileSuffix)
fmt.Println()
sgd.Error = data.Table.Output()

View File

@ -6,6 +6,8 @@ import (
"encoding/json"
"fmt"
"github.com/MickMake/GoUnify/Only"
"hash/fnv"
"sort"
"strings"
"time"
)
@ -755,10 +757,17 @@ func (sgd *SunGrowDataRequest) Validate(endpoint api.EndPoint) bool {
func (sgd *SunGrowDataRequest) GetArgs(endpoint api.EndPoint) string {
var ret string
for range Only.Once {
args := endpoint.GetRequestArgNames()
for key, value := range args {
if value != "true" {
var sorted []string
for key := range args {
sorted = append(sorted, key)
}
sort.Strings(sorted)
for _, key := range sorted {
if args[key] != "true" {
continue
}
@ -773,6 +782,20 @@ func (sgd *SunGrowDataRequest) GetArgs(endpoint api.EndPoint) string {
ret += fmt.Sprintf("%s:%s ", key, sgd.Get(key))
}
}
return ret
}
func (sgd *SunGrowDataRequest) GetArgsHash(endpoint api.EndPoint) string {
var ret string
for range Only.Once {
ret = sgd.GetArgs(endpoint)
h := fnv.New32a()
_, _ = h.Write([]byte(ret))
ret = fmt.Sprintf("%X", h.Sum32())
}
return ret
}

View File

@ -189,6 +189,40 @@ func (sg *SunGrow) DeviceTypeData(deviceType string, startDate string, endDate s
return sg.Error
}
// DeviceTypeSave - Return all point data associated a device_type and save as files.
func (sg *SunGrow) DeviceTypeSave(deviceType string, startDate string, endDate string, interval string) error {
for range Only.Once {
if deviceType == "" {
sg.Error = errors.New("no template defined")
break
}
fmt.Println("NOT YET IMPLEMENTED.")
// data := sg.QueryUserCurveDeviceData(deviceType)
// if sg.IsError() {
// break
// }
//
// var points []string
// for an := range data.PointsData.Devices {
// // fmt.Println(an)
// for _, b := range data.PointsData.Devices[an].Points {
// points = append(points, b.PointId.Full())
// // fmt.Println(bn)
// // fmt.Printf("%v\n", b)
// }
// }
//
// sg.PointData(startDate, endDate, interval, points...)
// if sg.Error != nil {
// break
// }
}
return sg.Error
}
// GetDeviceList - AppService.getDeviceList
func (sg *SunGrow) GetDeviceList(psIds ...string) ([]getDeviceList.Device, error) {

View File

@ -356,7 +356,9 @@ func (sg *SunGrow) GetDevicePointAttrs(psId valueTypes.PsId) (getDevicePointAttr
}
func (sg *SunGrow) PointData(startDate string, endDate string, interval string, points ...string) error {
func (sg *SunGrow) getPointData(startDate string, endDate string, interval string, points ...string) (SunGrowData, error) {
var data SunGrowData
for range Only.Once {
// _, _ = sg.QueryMultiPointDataList(
// valueTypes.SetDateTimeString(startDate),
@ -365,7 +367,7 @@ func (sg *SunGrow) PointData(startDate string, endDate string, interval string,
// valueTypes.SetPointIdsString(points...),
// )
data := sg.NewSunGrowData()
data = sg.NewSunGrowData()
// req := iSolarCloud.RequestArgs {
// StartTimeStamp: startDate,
// EndTimeStamp: endDate,
@ -373,6 +375,7 @@ func (sg *SunGrow) PointData(startDate string, endDate string, interval string,
// var req iSolarCloud.RequestArgs
// data.Request.SetPoints(points)
// Also set the startDate based on the ps_id deployment endDate if not set.
sd := valueTypes.NewDateTime(startDate)
var ed valueTypes.DateTime
if endDate == "" {
@ -382,6 +385,10 @@ func (sg *SunGrow) PointData(startDate string, endDate string, interval string,
ed = valueTypes.NewDateTime(endDate)
}
if interval == "" {
interval = "5"
}
// _, _ = fmt.Fprintf(os.Stderr,"Points: %s\n", strings.Join(points, " "))
data.SetArgs(
"StartTimeStamp:" + sd.Format(valueTypes.DateTimeLayoutSecond),
@ -395,6 +402,18 @@ func (sg *SunGrow) PointData(startDate string, endDate string, interval string,
if sg.Error != nil {
break
}
}
return data, sg.Error
}
func (sg *SunGrow) PointData(startDate string, endDate string, interval string, points ...string) error {
for range Only.Once {
var data SunGrowData
data, sg.Error = sg.getPointData(startDate, endDate, interval, points...)
if sg.Error != nil {
break
}
sg.Error = data.OutputDataTables()
if sg.Error != nil {
@ -405,6 +424,70 @@ func (sg *SunGrow) PointData(startDate string, endDate string, interval string,
return sg.Error
}
func (sg *SunGrow) PointDataSave(startDate string, endDate string, interval string, points ...string) error {
// sot := sg.OutputType
for range Only.Once {
var data SunGrowData
data, sg.Error = sg.getPointData(startDate, endDate, interval, points...)
if sg.Error != nil {
break
}
for _, d := range data.Args {
if strings.HasPrefix(d, "StartTimeStamp:") {
startDate = strings.TrimPrefix(d, "StartTimeStamp:")
}
if strings.HasPrefix(d, "EndTimeStamp:") {
endDate = strings.TrimPrefix(d, "EndTimeStamp:")
}
}
sd := valueTypes.NewDateTime(startDate)
ed := valueTypes.NewDateTime(endDate)
switch {
case sd.Day() == ed.Day():
// Within the same day.
data.sunGrow.Directory = sd.Format(valueTypes.DateHumanLayout)
case sd.Month() == ed.Month():
// Within the same month.
data.sunGrow.Directory = sd.Format(valueTypes.DateHumanMonth)
default:
data.sunGrow.Directory = sd.Format(valueTypes.DateLayoutDay) + "-" + ed.Format(valueTypes.DateLayoutDay)
}
data.sunGrow.SaveAsFile = true
data.sunGrow.OutputType.SetJson()
// table.SetFilePrefix(data.SetFilenamePrefix(""))
// for _, r := range data.Results {
// r.Response.Output()
// }
sg.Error = data.Output()
if sg.Error != nil {
break
}
data.sunGrow.OutputType.SetTable()
sg.Error = data.Output()
if sg.Error != nil {
break
}
data.sunGrow.OutputType.SetCsv()
sg.Error = data.Output()
if sg.Error != nil {
break
}
data.sunGrow.OutputType.SetRaw()
sg.Error = data.Output()
if sg.Error != nil {
break
}
}
// sg.OutputType = sot
return sg.Error
}
func (sg *SunGrow) PointScan(min string, max string) (string, error) {
var ret string
@ -568,7 +651,6 @@ func (sg *SunGrow) QueryMultiPointDataList(startDate valueTypes.DateTime, endDat
if sg.IsError() {
break
}
}
return ret, sg.Error

View File

@ -200,6 +200,43 @@ func (sg *SunGrow) PsPointsData(psIds []string, deviceType string, startDate str
// _, _ = fmt.Fprintf(os.Stderr, "Found points: %s\n", strings.Join(ps, " "))
sg.Error = sg.PointData(startDate, endDate, interval, ps...)
if sg.Error != nil {
break
}
}
return sg.Error
}
// PsPointsDataSave - Return all points associated with psIds and device_type filter and save to files.
func (sg *SunGrow) PsPointsDataSave(psIds []string, deviceType string, startDate string, endDate string, interval string) error {
for range Only.Once {
var pskeys valueTypes.PsKeys
pskeys, sg.Error = sg.GetPsKeys()
if sg.Error != nil {
break
}
_, _ = 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))
}
}
// _, _ = fmt.Fprintf(os.Stderr, "Found points: %s\n", strings.Join(ps, " "))
sg.Error = sg.PointDataSave(startDate, endDate, interval, ps...)
if sg.Error != nil {
break
}
}
return sg.Error

View File

@ -6,6 +6,7 @@ import (
"GoSungrow/iSolarCloud/api/GoStruct/valueTypes"
"errors"
"github.com/MickMake/GoUnify/Only"
"strings"
"time"
)
@ -49,7 +50,7 @@ func (sg *SunGrow) TemplateList() error {
return sg.Error
}
// TemplatePoints - Return all points associated a template_id.
// TemplatePoints - Return all points associated with a template_id.
func (sg *SunGrow) TemplatePoints(template string) error {
for range Only.Once {
if template == "" {
@ -121,7 +122,7 @@ func (sg *SunGrow) TemplatePoints(template string) error {
return sg.Error
}
// TemplateData - Return all point data associated a template_id.
// TemplateData - Return all point data associated with a template_id.
func (sg *SunGrow) TemplateData(template string, startDate string, endDate string, interval string) error {
for range Only.Once {
if template == "" {
@ -136,14 +137,14 @@ func (sg *SunGrow) TemplateData(template string, startDate string, endDate strin
}
var points []string
for an := range data.PointsData.Devices {
// fmt.Println(an)
for _, b := range data.PointsData.Devices[an].Points {
points = append(points, b.PointId.Full())
// fmt.Println(bn)
// fmt.Printf("%v\n", b)
}
}
// for an := range data.PointsData.Devices {
// for _, b := range data.PointsData.Devices[an].Points {
// points = append(points, b.PointId.Full())
// }
// }
// Alternative - this maintains the original order defined in the template.
ps := strings.ReplaceAll(data.PointsData.Order.String(), "&", ".p")
points = strings.Split(ps, ",")
// data2 := sg.NewSunGrowData()
// data2.SetEndpoints(queryMutiPointDataList.EndPointName)
@ -198,6 +199,83 @@ func (sg *SunGrow) TemplateData(template string, startDate string, endDate strin
return sg.Error
}
// TemplateDataSave - Return all point data associated with a template_id and save to files.
func (sg *SunGrow) TemplateDataSave(template string, startDate string, endDate string, interval string) error {
for range Only.Once {
if template == "" {
sg.Error = errors.New("no template defined")
break
}
var data queryUserCurveTemplateData.ResultData
data, sg.Error = sg.QueryUserCurveTemplateData(template)
if sg.IsError() {
break
}
var points []string
// for an := range data.PointsData.Devices {
// for _, b := range data.PointsData.Devices[an].Points {
// points = append(points, b.PointId.Full())
// }
// }
// Alternative - this maintains the original order defined in the template.
ps := strings.ReplaceAll(data.PointsData.Order.String(), "&", ".p")
points = strings.Split(ps, ",")
// data2 := sg.NewSunGrowData()
// data2.SetEndpoints(queryMutiPointDataList.EndPointName)
// // req := iSolarCloud.RequestArgs{
// // StartTimeStamp: startDate,
// // EndTimeStamp: endDate,
// // }
// // var req iSolarCloud.RequestArgs
// // data.Request.SetPoints(points)
//
// startDate = valueTypes.NewDateTime(startDate).Format(valueTypes.DateTimeLayoutSecond)
// endDate = valueTypes.NewDateTime(endDate).Format(valueTypes.DateTimeLayoutSecond)
//
// data2.SetArgs(
// "StartTimeStamp:" + startDate,
// "EndTimeStamp:" + endDate,
// "MinuteInterval:" + interval,
// "Points:" + strings.Join(points, ","),
// )
//
// sg.Error = data2.GetData()
// if sg.Error != nil {
// break
// }
//
// sg.Error = data2.Process()
// if sg.Error != nil {
// break
// }
//
// // @TODO - Figure out a way to push the Unit values from QueryUserCurveTemplateData to this table.
// // result := queryMutiPointDataList.Assert(data2.Results["queryMutiPointDataList/1129147"].EndPoint)
// // for nr, r := range result.Response.ResultData.Data {
// // for nr2, r2 := range r.Points {
// // result.Response.ResultData.Data[nr].Points[r2].
// // }
// // }
// sg.Error = data2.OutputDataTables()
// if sg.Error != nil {
// break
// }
// @TODO - Figure out a way to push the Unit values from QueryUserCurveTemplateData to this table.
// @TODO - Maybe use a point cache?!
sg.Error = sg.PointDataSave(startDate, endDate, interval, points...)
if sg.Error != nil {
break
}
}
return sg.Error
}
// GetTemplateList - AppService.getTemplateList
func (sg *SunGrow) GetTemplateList() (getTemplateList.ResultData, error) {

View File

@ -33,6 +33,7 @@ type SunGrow struct {
NeedLogin bool
AuthDetails *login.SunGrowAuth
Directory string
OutputType output.OutputType
SaveAsFile bool
}