mirror of
https://github.com/MickMake/GoSungrow.git
synced 2025-03-26 17:41:42 +01:00
v3.0.0-alpha - MQTT fixes (debug)
This commit is contained in:
parent
1ad86d4395
commit
c3cfd1cf8c
147
.idea/workspace.xml
generated
147
.idea/workspace.xml
generated
@ -7,13 +7,25 @@
|
||||
<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_mqtt.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_mqtt.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsList/data.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$/defaults/const.go" beforeDir="false" afterPath="$PROJECT_DIR$/defaults/const.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/Common/images.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/Common/images.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/const.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/const.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/struct_epp.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_epp.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/structmap.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/float.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/float.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/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/data.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/api/struct_point.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/struct_point.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/web.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/web.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/config.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/config.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/mmHa/lights.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/lights.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/mmHa/sensors.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/sensors.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/mmHa/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/struct.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/mmHa/switch.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/switch.go" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -98,23 +110,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">
|
||||
@ -138,19 +133,9 @@
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go</url>
|
||||
<line>189</line>
|
||||
<line>190</line>
|
||||
<option name="timeStamp" value="202" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
|
||||
<line>333</line>
|
||||
<option name="timeStamp" value="437" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
|
||||
<line>332</line>
|
||||
<option name="timeStamp" value="446" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
|
||||
<line>350</line>
|
||||
@ -238,32 +223,32 @@
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/mmHa/binary_sensor.go</url>
|
||||
<line>103</line>
|
||||
<line>88</line>
|
||||
<option name="timeStamp" value="4693" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
|
||||
<line>118</line>
|
||||
<line>122</line>
|
||||
<option name="timeStamp" value="5494" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
|
||||
<line>122</line>
|
||||
<line>126</line>
|
||||
<option name="timeStamp" value="5495" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
|
||||
<line>114</line>
|
||||
<line>118</line>
|
||||
<option name="timeStamp" value="5496" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
|
||||
<line>945</line>
|
||||
<line>951</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>956</line>
|
||||
<line>962</line>
|
||||
<option name="timeStamp" value="5786" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
@ -278,12 +263,12 @@
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
|
||||
<line>83</line>
|
||||
<line>87</line>
|
||||
<option name="timeStamp" value="6475" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
|
||||
<line>78</line>
|
||||
<line>82</line>
|
||||
<option name="timeStamp" value="6495" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
@ -293,42 +278,37 @@
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
|
||||
<line>901</line>
|
||||
<line>911</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>878</line>
|
||||
<line>888</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>811</line>
|
||||
<line>821</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>766</line>
|
||||
<line>776</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>726</line>
|
||||
<line>736</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>722</line>
|
||||
<option name="timeStamp" value="6797" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
|
||||
<line>640</line>
|
||||
<line>650</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>1137</line>
|
||||
<line>1165</line>
|
||||
<option name="timeStamp" value="6822" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
@ -353,7 +333,7 @@
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
|
||||
<line>627</line>
|
||||
<line>643</line>
|
||||
<option name="timeStamp" value="7135" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
@ -516,11 +496,6 @@
|
||||
<line>462</line>
|
||||
<option name="timeStamp" value="7975" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
|
||||
<line>827</line>
|
||||
<option name="timeStamp" value="7987" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_table.go</url>
|
||||
<line>246</line>
|
||||
@ -588,7 +563,7 @@
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
|
||||
<line>475</line>
|
||||
<line>491</line>
|
||||
<option name="timeStamp" value="8080" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
@ -608,17 +583,17 @@
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
|
||||
<line>581</line>
|
||||
<line>597</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>499</line>
|
||||
<line>515</line>
|
||||
<option name="timeStamp" value="8144" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
|
||||
<line>118</line>
|
||||
<line>122</line>
|
||||
<option name="timeStamp" value="8152" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
@ -643,8 +618,43 @@
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
|
||||
<line>295</line>
|
||||
<option name="timeStamp" value="8197" />
|
||||
<line>355</line>
|
||||
<option name="timeStamp" value="8224" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_point.go</url>
|
||||
<line>52</line>
|
||||
<option name="timeStamp" value="8236" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_point.go</url>
|
||||
<line>47</line>
|
||||
<option name="timeStamp" value="8237" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
|
||||
<line>71</line>
|
||||
<option name="timeStamp" value="8311" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/mmHa/config.go</url>
|
||||
<line>50</line>
|
||||
<option name="timeStamp" value="8337" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/mmHa/sensors.go</url>
|
||||
<line>93</line>
|
||||
<option name="timeStamp" value="8356" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/mmHa/binary_sensor.go</url>
|
||||
<line>96</line>
|
||||
<option name="timeStamp" value="8357" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
|
||||
<line>976</line>
|
||||
<option name="timeStamp" value="8365" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
<default-breakpoints>
|
||||
@ -653,9 +663,12 @@
|
||||
</breakpoint-manager>
|
||||
<watches-manager>
|
||||
<configuration name="GoApplicationRunConfiguration">
|
||||
<watch expression="t.tablib" language="go" />
|
||||
<watch expression="d" language="go" />
|
||||
<watch expression="table.tablib" language="go" />
|
||||
<watch expression="foo.DataStructure.Endpoint" language="go" />
|
||||
<watch expression="foo.Value" language="go" />
|
||||
<watch expression="entries.StructMap.Map["queryDeviceList.1171348.devices.1171348_14_1_2.data.p13112"]" language="go" />
|
||||
<watch expression="entries.StructMap.Map["virtual.1171348_14_1_2.p13112"]" language="go" />
|
||||
<watch expression="totalDailyEnergy.Value.mapValues[""]" language="go" />
|
||||
<watch expression="gridToLoadEnergy.Value.mapValues[""]" language="go" />
|
||||
</configuration>
|
||||
</watches-manager>
|
||||
</component>
|
||||
|
380
cmd/cmd_mqtt.go
380
cmd/cmd_mqtt.go
@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"GoSungrow/iSolarCloud/api"
|
||||
"GoSungrow/iSolarCloud/api/GoStruct/output"
|
||||
"GoSungrow/mmHa"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -11,18 +12,24 @@ import (
|
||||
"github.com/go-co-op/gocron"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
const (
|
||||
DefaultServiceName = "GoSungrow"
|
||||
DefaultServiceArea = "Roof"
|
||||
DefaultVendor = "MickMake"
|
||||
flagMqttUsername = "mqtt-user"
|
||||
flagMqttPassword = "mqtt-password"
|
||||
flagMqttHost = "mqtt-host"
|
||||
flagMqttPort = "mqtt-port"
|
||||
)
|
||||
|
||||
|
||||
//goland:noinspection GoNameStartsWithPackageName
|
||||
type CmdMqtt struct {
|
||||
CmdDefault
|
||||
@ -35,7 +42,7 @@ type CmdMqtt struct {
|
||||
MqttPort string
|
||||
|
||||
Client *mmHa.Mqtt
|
||||
// SunGrow *iSolarCloud.SunGrow
|
||||
endpoints MqttEndPoints
|
||||
}
|
||||
|
||||
func NewCmdMqtt() *CmdMqtt {
|
||||
@ -89,13 +96,13 @@ func (c *CmdMqtt) AttachCommand(cmd *cobra.Command) *cobra.Command {
|
||||
if cmds.Error != nil {
|
||||
return cmds.Error
|
||||
}
|
||||
cmds.Error = cmds.MqttArgs(cmd, args)
|
||||
cmds.Error = cmds.Mqtt.MqttArgs(cmd, args)
|
||||
if cmds.Error != nil {
|
||||
return cmds.Error
|
||||
}
|
||||
return nil
|
||||
},
|
||||
RunE: cmds.CmdMqttRun,
|
||||
RunE: cmds.Mqtt.CmdMqttRun,
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
}
|
||||
cmdMqtt.AddCommand(cmdMqttRun)
|
||||
@ -114,13 +121,13 @@ func (c *CmdMqtt) AttachCommand(cmd *cobra.Command) *cobra.Command {
|
||||
if cmds.Error != nil {
|
||||
return cmds.Error
|
||||
}
|
||||
cmds.Error = cmds.MqttArgs(cmd, args)
|
||||
cmds.Error = cmds.Mqtt.MqttArgs(cmd, args)
|
||||
if cmds.Error != nil {
|
||||
return cmds.Error
|
||||
}
|
||||
return nil
|
||||
},
|
||||
RunE: cmds.CmdMqttSync,
|
||||
RunE: cmds.Mqtt.CmdMqttSync,
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
}
|
||||
cmdMqtt.AddCommand(cmdMqttSync)
|
||||
@ -142,126 +149,119 @@ func (c *CmdMqtt) AttachFlags(cmd *cobra.Command, viper *viper.Viper) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ca *Cmds) MqttArgs(_ *cobra.Command, _ []string) error {
|
||||
func (c *CmdMqtt) MqttArgs(_ *cobra.Command, _ []string) error {
|
||||
for range Only.Once {
|
||||
cmdLog.LogPrintDate("Connecting to MQTT HASSIO Service...\n")
|
||||
ca.Mqtt.Client = mmHa.New(mmHa.Mqtt {
|
||||
ClientId: "GoSungrow",
|
||||
EntityPrefix: "GoSungrow",
|
||||
Username: ca.Mqtt.MqttUsername,
|
||||
Password: ca.Mqtt.MqttPassword,
|
||||
Host: ca.Mqtt.MqttHost,
|
||||
Port: ca.Mqtt.MqttPort,
|
||||
c.Client = mmHa.New(mmHa.Mqtt {
|
||||
ClientId: DefaultServiceName,
|
||||
EntityPrefix: DefaultServiceName,
|
||||
Username: c.MqttUsername,
|
||||
Password: c.MqttPassword,
|
||||
Host: c.MqttHost,
|
||||
Port: c.MqttPort,
|
||||
})
|
||||
ca.Error = ca.Mqtt.Client.GetError()
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Client.GetError()
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
cmdLog.LogPrintDate("Connecting to SunGrow...\n")
|
||||
ca.Mqtt.Client.SungrowDevices, ca.Error = ca.Api.SunGrow.GetDeviceList()
|
||||
c.Client.SungrowDevices, c.Error = cmds.Api.SunGrow.GetDeviceList()
|
||||
// ca.Mqtt.Client.SungrowDevices, ca.Error = ca.Api.SunGrow.GetPsKeys()
|
||||
// ca.Mqtt.Client.SungrowDevices, ca.Error = ca.Api.SunGrow.GetPsIds()
|
||||
// ca.Mqtt.Client.SungrowDevices, ca.Error = ca.Api.SunGrow.GetPsTreeMenu()
|
||||
if ca.Error != nil {
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
cmdLog.LogPrintDate("Found SunGrow %d devices\n", len(ca.Mqtt.Client.SungrowDevices))
|
||||
ca.Mqtt.Client.DeviceName = "GoSungrow"
|
||||
ca.Error = ca.Mqtt.Client.SetDeviceConfig(
|
||||
ca.Mqtt.Client.DeviceName,
|
||||
ca.Mqtt.Client.DeviceName,
|
||||
cmdLog.LogPrintDate("Found SunGrow %d devices\n", len(c.Client.SungrowDevices))
|
||||
c.Client.DeviceName = DefaultServiceName
|
||||
c.Error = c.Client.SetDeviceConfig(
|
||||
c.Client.DeviceName,
|
||||
c.Client.DeviceName,
|
||||
"virtual",
|
||||
"virtual",
|
||||
"",
|
||||
"",
|
||||
"Roof",
|
||||
DefaultServiceArea,
|
||||
)
|
||||
if ca.Error != nil {
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
ca.Error = ca.Mqtt.Client.SetDeviceConfig(
|
||||
ca.Mqtt.Client.DeviceName,
|
||||
ca.Mqtt.Client.DeviceName,
|
||||
c.Error = c.Client.SetDeviceConfig(
|
||||
c.Client.DeviceName,
|
||||
c.Client.DeviceName,
|
||||
"system",
|
||||
"system",
|
||||
"",
|
||||
"",
|
||||
"Roof",
|
||||
DefaultServiceArea,
|
||||
)
|
||||
if ca.Error != nil {
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
for _, psId := range ca.Mqtt.Client.SungrowDevices {
|
||||
// ca.Error = ca.Mqtt.Mqtt.SetDeviceConfig("GoSungrow", strconv.FormatInt(id, 10), "GoSungrow", model[0], "Sungrow", "Roof")
|
||||
for _, psId := range c.Client.SungrowDevices {
|
||||
// ca.Error = ca.Mqtt.Mqtt.SetDeviceConfig(DefaultServiceName, strconv.FormatInt(id, 10), DefaultServiceName, model[0], "Sungrow", DefaultServiceArea)
|
||||
parent := psId.PsId.String()
|
||||
if parent == psId.PsKey.Value() {
|
||||
parent = ca.Mqtt.Client.DeviceName
|
||||
parent = c.Client.DeviceName
|
||||
}
|
||||
ca.Error = ca.Mqtt.Client.SetDeviceConfig(
|
||||
"GoSungrow",
|
||||
|
||||
c.Error = c.Client.SetDeviceConfig(
|
||||
DefaultServiceName,
|
||||
parent,
|
||||
psId.PsKey.Value(),
|
||||
psId.DeviceName.Value(),
|
||||
psId.DeviceModel.Value(),
|
||||
psId.FactoryName.Value(),
|
||||
"Roof",
|
||||
)
|
||||
if ca.Error != nil {
|
||||
DefaultServiceArea,
|
||||
)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
ca.Error = ca.Mqtt.Client.SetDeviceConfig(
|
||||
"GoSungrow",
|
||||
"GoSungrow",
|
||||
|
||||
c.Error = c.Client.SetDeviceConfig(
|
||||
DefaultServiceName,
|
||||
DefaultServiceName,
|
||||
psId.PsId.String(),
|
||||
psId.FactoryName.Value(),
|
||||
psId.FactoryName.Value(),
|
||||
psId.FactoryName.Value(),
|
||||
"Roof",
|
||||
DefaultServiceArea,
|
||||
)
|
||||
if ca.Error != nil {
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
ca.Mqtt.Client.SungrowPsIds[psId.PsId] = true
|
||||
c.Client.SungrowPsIds[psId.PsId] = true
|
||||
}
|
||||
|
||||
ca.Error = ca.Mqtt.Client.Connect()
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Client.Connect()
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
// if c.Mqtt.PsId == 0 {
|
||||
// c.Mqtt.PsId, c.Error = c.Api.SunGrow.GetPsId()
|
||||
// if c.Error != nil {
|
||||
// break
|
||||
// }
|
||||
// cmdLog.LogPrintDate("Found SunGrow device %d\n", c.Mqtt.PsId)
|
||||
// }
|
||||
}
|
||||
|
||||
return ca.Error
|
||||
return c.Error
|
||||
}
|
||||
|
||||
|
||||
func (c *CmdMqtt) CmdMqtt(cmd *cobra.Command, _ []string) error {
|
||||
return cmd.Help()
|
||||
}
|
||||
|
||||
func (ca *Cmds) CmdMqttRun(_ *cobra.Command, _ []string) error {
|
||||
func (c *CmdMqtt) CmdMqttRun(_ *cobra.Command, _ []string) error {
|
||||
for range Only.Once {
|
||||
// switch1 := mmMqtt.BinarySensor {
|
||||
// Device: mmMqtt.Device {
|
||||
// Connections: [][]string{{"sungrow_address", "0"}},
|
||||
// Identifiers: []string{"sungrow_bin_sensor_0"},
|
||||
// Manufacturer: "MickMake",
|
||||
// Manufacturer: DefaultVendor,
|
||||
// Model: "SunGrow inverter",
|
||||
// Name: "SunGrow inverter online",
|
||||
// SwVersion: "GoSungrow https://github.com/MickMake/GoSungrow",
|
||||
// ViaDevice: "GoSungrow",
|
||||
// ViaDevice: DefaultServiceName,
|
||||
// },
|
||||
// Name: "SunGrow inverter online",
|
||||
// StateTopic: "homeassistant/binary_sensor/GoSungrow_0/state",
|
||||
@ -276,8 +276,8 @@ func (ca *Cmds) CmdMqttRun(_ *cobra.Command, _ []string) error {
|
||||
// break
|
||||
// }
|
||||
|
||||
ca.Error = ca.MqttCron()
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Cron()
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
@ -293,18 +293,17 @@ func (ca *Cmds) CmdMqttRun(_ *cobra.Command, _ []string) error {
|
||||
|
||||
updateCounter = 0
|
||||
cmdLog.LogPrintDate("Update: %s\n", t.String())
|
||||
ca.Error = ca.MqttCron()
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Cron()
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ca.Error
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (ca *Cmds) CmdMqttSync(_ *cobra.Command, args []string) error {
|
||||
|
||||
func (c *CmdMqtt) CmdMqttSync(_ *cobra.Command, args []string) error {
|
||||
for range Only.Once {
|
||||
// */1 * * * * /dir/command args args
|
||||
cronString := "*/5 * * * *"
|
||||
@ -317,92 +316,90 @@ func (ca *Cmds) CmdMqttSync(_ *cobra.Command, args []string) error {
|
||||
cron = cron.Cron(cronString)
|
||||
cron = cron.SingletonMode()
|
||||
|
||||
ca.Error = ca.MqttCron()
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Cron()
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
var job *gocron.Job
|
||||
job, ca.Error = cron.Do(ca.MqttCron)
|
||||
if ca.Error != nil {
|
||||
job, c.Error = cron.Do(c.Cron)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
job.IsRunning()
|
||||
|
||||
cmdLog.LogPrintDate("Created job schedule using '%s'\n", cronString)
|
||||
cron.StartBlocking()
|
||||
if ca.Error != nil {
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return ca.Error
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (ca *Cmds) MqttCron() error {
|
||||
|
||||
func (c *CmdMqtt) Cron() error {
|
||||
for range Only.Once {
|
||||
if ca.Mqtt == nil {
|
||||
ca.Error = errors.New("mqtt not available")
|
||||
if c == nil {
|
||||
c.Error = errors.New("mqtt not available")
|
||||
break
|
||||
}
|
||||
|
||||
if ca.Api.SunGrow == nil {
|
||||
ca.Error = errors.New("sungrow not available")
|
||||
if cmds.Api.SunGrow == nil {
|
||||
c.Error = errors.New("sungrow not available")
|
||||
break
|
||||
}
|
||||
|
||||
if ca.Mqtt.Client.IsFirstRun() {
|
||||
ca.Mqtt.Client.UnsetFirstRun()
|
||||
c.Error = c.GetEndPoints()
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
if c.Client.IsFirstRun() {
|
||||
c.Client.UnsetFirstRun()
|
||||
} else {
|
||||
time.Sleep(time.Second * 40) // Takes up to 40 seconds for data to come in.
|
||||
}
|
||||
|
||||
newDay := false
|
||||
if ca.Mqtt.Client.IsNewDay() {
|
||||
if c.Client.IsNewDay() {
|
||||
newDay = true
|
||||
}
|
||||
|
||||
data := ca.Api.SunGrow.NewSunGrowData()
|
||||
data := cmds.Api.SunGrow.NewSunGrowData()
|
||||
data.SetPsIds()
|
||||
if data.Error != nil {
|
||||
ca.Error = data.Error
|
||||
c.Error = data.Error
|
||||
break
|
||||
}
|
||||
|
||||
All := []string{ "queryDeviceList", "getPsList", "getPsDetailWithPsType", "getPsDetail", "getKpiInfo"} //, queryMutiPointDataList, getDevicePointMinuteDataList }
|
||||
// All := []string{ "queryDeviceList", "WebIscmAppService.queryDeviceListForBackSys", "WebIscmAppService.getDeviceModel" }
|
||||
// All := []string{ "queryDeviceList", "getPsList", "getPsDetailWithPsType", "getPsDetail", "getKpiInfo"}
|
||||
// All := []string{ "queryDeviceList", "getPsList", "getPsDetailWithPsType", "getPsDetail", "getKpiInfo"} //, queryMutiPointDataList, getDevicePointMinuteDataList }
|
||||
// All := []string{ "WebIscmAppService.getDeviceModel" }
|
||||
data.SetEndpoints(All...)
|
||||
ca.Error = data.GetData()
|
||||
if ca.Error != nil {
|
||||
data.SetEndpoints(c.endpoints.Names()...)
|
||||
c.Error = data.GetData()
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
// results := data.GetResults()
|
||||
|
||||
for _, result := range data.Results {
|
||||
// ca.Error = result.ProcessMapForMqtt()
|
||||
ca.Error = result.Process()
|
||||
if ca.Error != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
ca.Error = ca.Update(string(result.EndPointName), result.Response.Data, newDay)
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Update(result.EndPointName.String(), result.Response.Data, newDay)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
ca.Mqtt.Client.LastRefresh = time.Now()
|
||||
c.Client.LastRefresh = time.Now()
|
||||
}
|
||||
|
||||
if ca.Error != nil {
|
||||
cmdLog.LogPrintDate("Error: %s\n", ca.Error)
|
||||
if c.Error != nil {
|
||||
cmdLog.LogPrintDate("Error: %s\n", c.Error)
|
||||
}
|
||||
return ca.Error
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (ca *Cmds) Update(endpoint string, data api.DataMap, newDay bool) error {
|
||||
func (c *CmdMqtt) Update(endpoint string, data api.DataMap, newDay bool) error {
|
||||
for range Only.Once {
|
||||
// Also getPowerStatistics, getHouseholdStoragePsReport, getPsList, getUpTimePoint,
|
||||
cmdLog.LogPrintDate("Syncing %d entries with HASSIO from %s.\n", len(data.Map), endpoint)
|
||||
@ -411,25 +408,49 @@ func (ca *Cmds) Update(endpoint string, data api.DataMap, newDay bool) error {
|
||||
entries := data.Map[o]
|
||||
r := entries.GetEntry(api.LastEntry) // Gets the last entry
|
||||
|
||||
fullId := r.EndPoint
|
||||
if r.Point.GroupName == "alias" {
|
||||
fullId = mmHa.JoinStringsForId(r.Parent.Key, r.Point.Parents.Index[0], r.Point.Id)
|
||||
if !r.Point.Valid {
|
||||
// cmdLog.LogPrintDate("\n[%s] - invalid value - %s ...\n", r.Current.FieldPath.String(), r.Value.String())
|
||||
fmt.Printf("?")
|
||||
continue
|
||||
}
|
||||
|
||||
if !c.endpoints.IsOK(r) {
|
||||
continue
|
||||
}
|
||||
|
||||
var id string
|
||||
var name string
|
||||
switch {
|
||||
case r.Point.GroupName == "alias":
|
||||
id = mmHa.JoinStringsForId(r.Parent.Key, r.Point.Parents.Index[0], r.Point.Id)
|
||||
name = mmHa.JoinStringsForName(" - ", r.Parent.Key, r.Point.Parents.Index[0], r.Point.Id)
|
||||
case r.Point.GroupName != "":
|
||||
id = r.EndPoint
|
||||
name = mmHa.JoinStringsForName(" - ", r.Parent.Key, r.Point.Id, r.Point.GroupName, r.Point.Description)
|
||||
default:
|
||||
id = r.EndPoint
|
||||
name = r.EndPoint
|
||||
}
|
||||
// name = mmHa.JoinStringsForName(" - ", name)
|
||||
|
||||
if r.Point.Unit == "" {
|
||||
r.Point.Unit = r.Point.ValueType
|
||||
}
|
||||
if r.Point.Unit == "Bool" {
|
||||
r.Point.Unit = mmHa.LabelBinarySensor
|
||||
}
|
||||
if r.Point.ValueType == "Bool" {
|
||||
r.Point.Unit = mmHa.LabelBinarySensor
|
||||
}
|
||||
|
||||
re := mmHa.EntityConfig {
|
||||
Name: mmHa.JoinStringsForName(" - ", fullId), // r.Point.Name, // PointName,
|
||||
Name: name, // mmHa.JoinStringsForName(" - ", id), // r.Point.Name, // PointName,
|
||||
SubName: "",
|
||||
ParentId: r.EndPoint,
|
||||
ParentName: r.Parent.Key,
|
||||
UniqueId: r.Point.Id,
|
||||
// UniqueId: r.Id,
|
||||
FullId: fullId, // string(r.FullId), // WAS r.Point.FullId
|
||||
FullId: id, // string(r.FullId), // WAS r.Point.FullId
|
||||
// FullName: r.Point.Name,
|
||||
Units: r.Point.Unit,
|
||||
ValueName: r.Point.Description,
|
||||
@ -440,55 +461,156 @@ func (ca *Cmds) Update(endpoint string, data api.DataMap, newDay bool) error {
|
||||
|
||||
// Icon: "",
|
||||
// ValueTemplate: "",
|
||||
// LastReset: "",
|
||||
LastReset: r.Point.WhenReset(),
|
||||
// LastResetValueTemplate: "",
|
||||
}
|
||||
|
||||
if !r.Point.Valid {
|
||||
cmdLog.LogPrintDate("\n[%s] - invalid value - %s ...\n", r.Current.FieldPath.String(), r.Value.String())
|
||||
// re.Value = r.Value.String()
|
||||
// // var mapIt map[string]string
|
||||
// // ca.Error = json.Unmarshal([]byte(r.Value.String()), &mapIt)
|
||||
// // if ca.Error != nil {
|
||||
// // continue
|
||||
// // }
|
||||
// re.ValueTemplate = ""
|
||||
continue
|
||||
fmt.Println(re.UniqueId)
|
||||
if strings.Contains(r.EndPoint, "p13121") {
|
||||
fmt.Printf("")
|
||||
}
|
||||
|
||||
if strings.Contains(r.Current.DataStructure.Endpoint.String(), "active") {
|
||||
if strings.Contains(r.EndPoint, "power_pv_to_grid") {
|
||||
fmt.Printf("")
|
||||
}
|
||||
|
||||
if re.Value == "--" {
|
||||
re.Value = ""
|
||||
}
|
||||
switch {
|
||||
case r.Point.IsTotal():
|
||||
re.StateClass = "total"
|
||||
default:
|
||||
re.StateClass = "measurement"
|
||||
}
|
||||
|
||||
if newDay {
|
||||
fmt.Printf("C")
|
||||
ca.Error = ca.Mqtt.Client.BinarySensorPublishConfig(re)
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Client.BinarySensorPublishConfig(re)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
ca.Error = ca.Mqtt.Client.SensorPublishConfig(re)
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Client.SensorPublishConfig(re)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("U")
|
||||
ca.Error = ca.Mqtt.Client.BinarySensorPublishValue(re)
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Client.BinarySensorPublishValue(re)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
ca.Error = ca.Mqtt.Client.SensorPublishValue(re)
|
||||
if ca.Error != nil {
|
||||
c.Error = c.Client.SensorPublishValue(re)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
if ca.Error != nil {
|
||||
cmdLog.LogPrintDate("Error: %s\n", ca.Error)
|
||||
if c.Error != nil {
|
||||
cmdLog.LogPrintDate("Error: %s\n", c.Error)
|
||||
}
|
||||
return ca.Error
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *CmdMqtt) GetEndPoints() error {
|
||||
for range Only.Once {
|
||||
fn := filepath.Join(cmds.ConfigDir, "mqtt_endpoints.json")
|
||||
c.Error = output.FileRead(fn, &c.endpoints)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
for name := range c.endpoints {
|
||||
c.Error = c.Client.SetDeviceConfig(
|
||||
DefaultServiceName,
|
||||
DefaultServiceName,
|
||||
name,
|
||||
DefaultServiceName + "." + name,
|
||||
DefaultServiceName,
|
||||
DefaultVendor,
|
||||
DefaultServiceArea,
|
||||
)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
|
||||
type MqttEndPoints map[string]MqttEndPoint
|
||||
type MqttEndPoint struct {
|
||||
Include []string `json:"include"`
|
||||
Exclude []string `json:"exclude"`
|
||||
}
|
||||
func (c *MqttEndPoints) Names() []string {
|
||||
var ret []string
|
||||
for name := range *c {
|
||||
ret = append(ret, name)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (c *MqttEndPoints) IsOK(check *api.DataEntry) bool {
|
||||
var yes bool
|
||||
for range Only.Once {
|
||||
field := check.Current.GetFieldPath()
|
||||
name := field.First()
|
||||
|
||||
var ep MqttEndPoint
|
||||
if ep, yes = (*c)[name]; !yes {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
|
||||
if len(ep.Include) == 0 {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
|
||||
for _, reStr := range ep.Exclude {
|
||||
reStr = strings.ReplaceAll(reStr, `.`, `\.`)
|
||||
reStr = strings.ReplaceAll(reStr, `*`, `.*?`)
|
||||
reStr = "^" + strings.TrimPrefix(reStr, "^")
|
||||
re := regexp.MustCompile(reStr)
|
||||
if re.MatchString(check.EndPoint) {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
if re.MatchString(check.Current.FieldPath.String()) {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
if re.MatchString(check.Current.DataStructure.Endpoint.String()) {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, reStr := range ep.Include {
|
||||
reStr = strings.ReplaceAll(reStr, `.`, `\.`)
|
||||
reStr = strings.ReplaceAll(reStr, `*`, `.*`)
|
||||
reStr = "^" + strings.TrimPrefix(reStr, "^")
|
||||
re := regexp.MustCompile(reStr)
|
||||
if re.MatchString(check.EndPoint) {
|
||||
yes = true
|
||||
break
|
||||
}
|
||||
if re.MatchString(check.Current.FieldPath.String()) {
|
||||
yes = true
|
||||
break
|
||||
}
|
||||
if re.MatchString(check.Current.DataStructure.Endpoint.String()) {
|
||||
yes = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return yes
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ var Examples string
|
||||
const (
|
||||
Description = "GoSungrow - GoLang implementation to access the iSolarCloud API updated by SunGrow inverters"
|
||||
BinaryName = "GoSungrow"
|
||||
BinaryVersion = "2.3.0"
|
||||
BinaryVersion = "3.0.0"
|
||||
SourceRepo = "github.com/MickMake/" + BinaryName
|
||||
BinaryRepo = "github.com/MickMake/" + BinaryName
|
||||
|
||||
|
@ -37,6 +37,7 @@ type ResultData struct {
|
||||
} `json:"dev_count_by_status_map" PointId:"device_status_count"`
|
||||
DevCountByTypeMap map[string]valueTypes.Integer `json:"dev_count_by_type_map" PointId:"device_type_count" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
DevTypeDefinition map[string]valueTypes.String `json:"dev_type_definition" PointId:"device_types" PointUpdateFreq:"UpdateFreqBoot"` // DataTable:"true"`
|
||||
|
||||
RowCount valueTypes.Integer `json:"rowCount" PointId:"row_count"`
|
||||
}
|
||||
// DevCountByTypeMap struct {
|
||||
@ -229,10 +230,35 @@ func (e *EndPoint) GetData() api.DataMap {
|
||||
// var TotalPvYield
|
||||
// var DailyTotalLoad
|
||||
// var TotalEnergyConsumption
|
||||
for _, device := range e.Response.ResultData.PageList {
|
||||
epp := GoStruct.NewEndPointPath("virtual", device.PsKey.String())
|
||||
deviceId := device.PsKey.String()
|
||||
if device.PsKey.String() == "" {
|
||||
epp = GoStruct.NewEndPointPath("virtual", device.PsId.String())
|
||||
deviceId = device.PsId.String()
|
||||
}
|
||||
// Points are embedded within []PointStruct. So manually add virtuals instead of using the structure.
|
||||
|
||||
for _, point := range device.PointData {
|
||||
name := point.PointId.String()
|
||||
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.Value.SetDeviceId(deviceId)
|
||||
foo.DataStructure.PointGroupName = point.PointGroupName.String()
|
||||
foo.DataStructure.PointDevice = deviceId
|
||||
foo.DataStructure.ValueType = foo.Value.TypeValue
|
||||
foo.DataStructure.PointUnit = point.Unit.String()
|
||||
foo.DataStructure.PointTimestamp = point.TimeStamp.Time
|
||||
foo.IsOk = true
|
||||
fmt.Printf("%s.%s -> %s\n", epp, name, foo.DataStructure.PointDevice)
|
||||
}
|
||||
}
|
||||
|
||||
e.GetEnergyStorageSystem(entries)
|
||||
e.GetCommunicationModule(entries)
|
||||
e.GetBattery(entries)
|
||||
// e.GetCommunicationModule(entries)
|
||||
// e.GetBattery(entries)
|
||||
}
|
||||
|
||||
return entries
|
||||
@ -264,161 +290,527 @@ func (e *EndPoint) GetEnergyStorageSystem(entries api.DataMap) {
|
||||
// Only looking for a Solar Storage System.
|
||||
continue
|
||||
}
|
||||
epp := GoStruct.NewEndPointPath("virtual", device.PsId.String(), device.PsKey.String())
|
||||
// Points are embedded within []PointStruct. So manually add virtuals instead of using the structure.
|
||||
|
||||
// BatteryChargingPower
|
||||
batteryChargePower := entries.CopyPointFromName("p13126.value", epp, "battery_charge_power", "")
|
||||
|
||||
// BatteryDischargingPower
|
||||
batteryDischargePower := entries.CopyPointFromName("p13150.value", epp, "battery_discharge_power", "")
|
||||
|
||||
// Daily PV Yield
|
||||
dailyPvEnergy := entries.CopyPointFromName("p13112.value", epp, "daily_pv_energy", "")
|
||||
|
||||
// DailyBatteryChargingEnergyFromPv
|
||||
pvBatteryChargeEnergy := entries.CopyPointFromName("p13174.value", epp, "pv_battery_charge_energy", "")
|
||||
|
||||
// DailyBatteryDischargingEnergy
|
||||
batteryDischarge := entries.CopyPointFromName("p13029.value", epp, "battery_discharge", "")
|
||||
|
||||
// DailyFeedInEnergy - @TODO - This may differ from DailyFeedInEnergyPv
|
||||
_ = entries.CopyPointFromName("p13122.value", epp, "pv_feed_in2", "")
|
||||
|
||||
// DailyFeedInEnergyPv
|
||||
pvFeedIn := entries.CopyPointFromName("p13173.value", epp, "pv_feed_in", "")
|
||||
|
||||
// DailyPurchasedEnergy
|
||||
dailyPurchasedEnergy := entries.CopyPointFromName("p13147.value", epp, "daily_purchased_energy", "")
|
||||
|
||||
// DailyLoadEnergyConsumptionFromPv
|
||||
pvSelfConsumption := entries.CopyPointFromName("p13116.value", epp, "pv_self_consumption", "")
|
||||
|
||||
// TotalPvYield
|
||||
_ = entries.CopyPointFromName("p13134.value", epp, "pv_total_yield", "")
|
||||
|
||||
// Daily Load Energy Consumption
|
||||
dailyTotalEnergy := entries.CopyPointFromName("p13199.value", epp, "daily_total_energy", "")
|
||||
|
||||
// Total Load Energy Consumption
|
||||
_ = entries.CopyPointFromName("p13130.value", epp, "total_energy_consumption", "")
|
||||
|
||||
pvDailyYield := entries.CopyPointFromName(pvSelfConsumption.PointId(), epp, "pv_daily_yield", "")
|
||||
pvDailyYield.SetValue(GoStruct.AddFloatValues(pvSelfConsumption, pvBatteryChargeEnergy, pvFeedIn))
|
||||
|
||||
pvSelfConsumptionPercent := entries.CopyPoint(dailyPvEnergy, epp, "pv_self_consumption_percent", "")
|
||||
pvSelfConsumptionPercent.SetValue(entries.GetPercent(pvSelfConsumption, dailyPvEnergy))
|
||||
|
||||
batteryEnergy := entries.CopyPoint(pvBatteryChargeEnergy, epp, "battery_energy", "")
|
||||
batteryEnergy.SetValue(entries.LowerUpper(pvBatteryChargeEnergy, batteryDischarge))
|
||||
|
||||
pvBatteryChargePercent := entries.CopyPoint(dailyPvEnergy, epp, "pv_battery_charge_percent", "")
|
||||
pvBatteryChargePercent.SetValue(entries.LowerUpper(pvBatteryChargeEnergy, dailyPvEnergy))
|
||||
|
||||
pvFeedInPercent := entries.CopyPoint(dailyPvEnergy, epp, "pv_feed_in_percent", "")
|
||||
pvFeedInPercent.SetValue(entries.LowerUpper(pvFeedIn, dailyPvEnergy))
|
||||
|
||||
dailyPvEnergyPercent := entries.CopyPoint(dailyTotalEnergy, epp, "daily_pv_energy_percent", "")
|
||||
DailyPvEnergy := dailyTotalEnergy.Value.First().ValueFloat() - dailyPurchasedEnergy.Value.First().ValueFloat()
|
||||
dailyPvEnergyPercent.SetValue(api.GetPercent(DailyPvEnergy, dailyTotalEnergy.Value.First().ValueFloat()))
|
||||
|
||||
dailyPurchasedEnergyPercent := entries.CopyPoint(dailyTotalEnergy, epp, "daily_purchased_energy_percent", "")
|
||||
dailyPurchasedEnergyPercent.SetValue(entries.LowerUpper(dailyPurchasedEnergy, dailyTotalEnergy))
|
||||
|
||||
|
||||
// PV src
|
||||
powerPv := entries.CopyPointFromName("p13003.value", epp, "power_pv", "Total DC Power")
|
||||
_ = entries.MakeState(powerPv, epp, "power_pv_active", "")
|
||||
|
||||
powerPvToBattery := entries.CopyPoint(batteryChargePower, epp, "power_pv_to_battery", "")
|
||||
powerPvToBattery.SetValue(batteryChargePower.Value.First().ValueFloat())
|
||||
_ = entries.MakeState(powerPvToBattery, epp, "power_pv_to_battery_active", "")
|
||||
|
||||
powerPvToGrid := entries.CopyPointFromName("p13121.value", epp, "power_pv_to_grid", "Total Export Active Power")
|
||||
_ = entries.MakeState(powerPvToGrid, epp, "power_pv_to_grid_active", "")
|
||||
|
||||
powerPvToLoad := entries.CopyPoint(powerPv, epp, "power_pv_to_load", "")
|
||||
powerPvToLoad.SetValue(powerPv.Value.First().ValueFloat() - batteryChargePower.Value.First().ValueFloat() - powerPvToGrid.Value.First().ValueFloat())
|
||||
_ = entries.MakeState(powerPvToLoad, epp, "power_pv_to_load_active", "")
|
||||
|
||||
|
||||
// Battery src
|
||||
powerBattery := entries.CopyPoint(batteryChargePower, epp, "power_battery", "")
|
||||
powerBattery.SetValue(entries.LowerUpper(batteryDischargePower, batteryChargePower))
|
||||
_ = entries.MakeState(powerBattery, epp, "power_battery_active", "")
|
||||
|
||||
powerBatteryToLoad := entries.CopyPoint(batteryDischargePower, epp, "power_battery_to_load", "")
|
||||
powerBatteryToLoad.SetValue(batteryDischargePower.Value.First().ValueFloat())
|
||||
_ = entries.MakeState(powerBatteryToLoad, epp, "power_battery_to_load_active", "")
|
||||
|
||||
powerBatteryToGrid := entries.CopyPoint(batteryChargePower, epp, "power_battery_to_grid", "")
|
||||
powerBatteryToGrid.SetValue(0.0)
|
||||
_ = entries.MakeState(powerBatteryToGrid, epp, "power_battery_to_grid_active", "")
|
||||
|
||||
|
||||
// Grid src
|
||||
powerGridToLoad := entries.CopyPointFromName("p13149.value", epp, "power_grid_to_load", "Purchased Power")
|
||||
_ = entries.MakeState(powerGridToLoad, epp, "power_grid_to_load_active", "")
|
||||
|
||||
powerGrid := entries.CopyPoint(powerGridToLoad, epp, "power_grid", "")
|
||||
powerGrid.SetValue(entries.LowerUpper(powerPvToGrid, powerGridToLoad))
|
||||
_ = entries.MakeState(powerGrid, epp, "power_grid_active", "")
|
||||
|
||||
powerGridToBattery := entries.CopyPoint(powerGridToLoad, epp, "power_grid_to_battery", "")
|
||||
powerGridToBattery.SetValue(0.0)
|
||||
_ = entries.MakeState(powerGridToBattery, epp, "power_grid_to_battery_active", "")
|
||||
|
||||
gridEnergy := entries.CopyPoint(pvFeedIn, epp, "grid_energy", "")
|
||||
gridEnergy.SetValue(entries.LowerUpper(pvFeedIn, dailyPurchasedEnergy))
|
||||
|
||||
|
||||
// Load src
|
||||
powerLoad := entries.CopyPointFromName("p13119.value", epp, "power_load", "Total Load Active Power")
|
||||
_ = entries.MakeState(powerLoad, epp, "power_load_active", "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EndPoint) GetCommunicationModule(entries api.DataMap) {
|
||||
for range Only.Once {
|
||||
for _, device := range e.Response.ResultData.PageList {
|
||||
if !device.DeviceType.Match(api.DeviceNameCommunicationModule) {
|
||||
// Only looking for a Communication Module.
|
||||
continue
|
||||
epp := GoStruct.NewEndPointPath("virtual", device.PsKey.String())
|
||||
if device.PsKey.String() == "" {
|
||||
epp = GoStruct.NewEndPointPath("virtual", device.PsId.String())
|
||||
}
|
||||
epp := GoStruct.NewEndPointPath("virtual", device.PsId.String(), device.PsKey.String())
|
||||
// Points are embedded within []PointStruct. So manually add virtuals instead of using the structure.
|
||||
e.SetBatteryPoints(epp, entries)
|
||||
e.SetPvPoints(epp, entries)
|
||||
e.SetGridPoints(epp, entries)
|
||||
e.SetLoadPoints(epp, entries)
|
||||
|
||||
// WLAN Signal Strength
|
||||
_ = entries.CopyPointFromName("p23014.value", epp, "wlan_signal_strength", "")
|
||||
// // BatteryChargingPower
|
||||
// batteryChargePower := entries.CopyPointFromName(epp.AddString("p13126"), epp, "battery_charge_power", "")
|
||||
// // batteryChargePower := entries.GetReflect(epp.AddString("p13126"))
|
||||
//
|
||||
// // BatteryDischargingPower
|
||||
// batteryDischargePower := entries.CopyPointFromName(epp.AddString("p13150"), epp, "battery_discharge_power", "")
|
||||
// // batteryDischargePower := entries.GetReflect(epp.AddString("p13150"))
|
||||
//
|
||||
// // Daily PV Yield
|
||||
// // dailyPvEnergy := entries.CopyPointFromName(epp.AddString("p13112"), epp, "daily_pv_energy", "")
|
||||
// dailyPvEnergy := entries.GetReflect(epp.AddString("p13112"))
|
||||
//
|
||||
// // DailyBatteryChargingEnergyFromPv
|
||||
// pvBatteryChargeEnergy := entries.CopyPointFromName(epp.AddString("p13174"), epp, "battery_charge_energy", "")
|
||||
// // pvBatteryChargeEnergy := entries.GetReflect(epp.AddString("p13174"))
|
||||
//
|
||||
// // DailyBatteryDischargingEnergy
|
||||
// batteryDischarge := entries.CopyPointFromName(epp.AddString("p13029"), epp, "battery_discharge_energy", "")
|
||||
// // batteryDischarge := entries.GetReflect(epp.AddString("p13029"))
|
||||
//
|
||||
// // DailyFeedInEnergy - @TODO - This may differ from DailyFeedInEnergyPv
|
||||
// // _ = entries.CopyPointFromName(epp.AddString("p13122"), epp, "pv_to_grid2", "")
|
||||
//
|
||||
// // DailyFeedInEnergyPv
|
||||
// pvToGridEnergy := entries.CopyPointFromName(epp.AddString("p13173"), epp, "pv_to_grid_energy", "")
|
||||
// // pvFeedIn := entries.GetReflect(epp.AddString("p13173"))
|
||||
//
|
||||
// // DailyPurchasedEnergy
|
||||
// dailyPurchasedEnergy := entries.CopyPointFromName(epp.AddString("p13147"), epp, "purchased_energy", "")
|
||||
// // dailyPurchasedEnergy := entries.GetReflect(epp.AddString("p13147"))
|
||||
//
|
||||
// // DailyLoadEnergyConsumptionFromPv
|
||||
// pvSelfConsumption := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_self_consumption", "")
|
||||
// // pvSelfConsumption := entries.GetReflect(epp.AddString("p13116"))
|
||||
//
|
||||
// // TotalPvYield
|
||||
// // _ = entries.CopyPointFromName(epp.AddString("p13134"), epp, "pv_total_yield", "")
|
||||
//
|
||||
// // Daily Load Energy Consumption
|
||||
// dailyTotalEnergy := entries.CopyPointFromName(epp.AddString("p13199"), epp, "daily_total_energy", "")
|
||||
// // dailyTotalEnergy := entries.GetReflect(epp.AddString("p13199"))
|
||||
//
|
||||
// // Total Load Energy Consumption
|
||||
// // _ = entries.CopyPointFromName(epp.AddString("p13130"), epp, "total_energy_consumption", "")
|
||||
//
|
||||
//
|
||||
// pvDailyYield := entries.CopyPointFromName(pvSelfConsumption.PointId(), epp, "pv_yield_energy", "Pv Yield Energy (Calc)")
|
||||
// // pvDailyYield := entries.GetReflect(pvSelfConsumption.PointId())
|
||||
// pvDailyYield.SetValue(GoStruct.AddFloatValues(3, pvSelfConsumption, pvBatteryChargeEnergy, pvToGridEnergy))
|
||||
//
|
||||
// pvSelfConsumptionPercent := entries.CopyPoint(dailyPvEnergy, epp, "pv_self_consumption_percent", "Pv Self Consumption Percent (Calc)")
|
||||
// pvSelfConsumptionPercent.SetValue(entries.GetPercent(pvSelfConsumption, dailyPvEnergy, 1))
|
||||
// pvSelfConsumptionPercent.Value.SetUnit("%")
|
||||
//
|
||||
// batteryEnergy := entries.CopyPoint(pvBatteryChargeEnergy, epp, "battery_energy", "Battery Energy (Calc)")
|
||||
// batteryEnergy.SetValue(entries.LowerUpper(pvBatteryChargeEnergy, batteryDischarge))
|
||||
//
|
||||
// pvBatteryChargePercent := entries.CopyPoint(dailyPvEnergy, epp, "battery_charge_energy_percent", "Battery Charge Percent (Calc)")
|
||||
// pvBatteryChargePercent.SetValue(entries.GetPercent(pvBatteryChargeEnergy, dailyPvEnergy, 1))
|
||||
// pvBatteryChargePercent.Value.SetUnit("%")
|
||||
//
|
||||
// pvFeedInPercent := entries.CopyPoint(dailyPvEnergy, epp, "pv_to_grid_energy_percent", "Pv Feed In Energy Percent (Calc)")
|
||||
// pvFeedInPercent.SetValue(entries.GetPercent(pvToGridEnergy, dailyPvEnergy, 1))
|
||||
// pvFeedInPercent.Value.SetUnit("%")
|
||||
//
|
||||
// dailyPvEnergyPercent := entries.CopyPoint(dailyTotalEnergy, epp, "daily_pv_energy_percent", "")
|
||||
// DailyPvEnergy := dailyTotalEnergy.Value.First().ValueFloat() - dailyPurchasedEnergy.Value.First().ValueFloat()
|
||||
// dailyPvEnergyPercent.SetValue(api.GetPercent(DailyPvEnergy, dailyTotalEnergy.Value.First().ValueFloat(), 1))
|
||||
// dailyPvEnergyPercent.Value.SetUnit("%")
|
||||
//
|
||||
// dailyPurchasedEnergyPercent := entries.CopyPoint(dailyTotalEnergy, epp, "daily_purchased_energy_percent", "")
|
||||
// dailyPurchasedEnergyPercent.SetValue(entries.GetPercent(dailyPurchasedEnergy, dailyTotalEnergy, 1))
|
||||
// dailyPurchasedEnergyPercent.Value.SetUnit("%")
|
||||
//
|
||||
//
|
||||
// // PV Active
|
||||
// powerPv := entries.GetReflect(epp.AddString("p13003"))
|
||||
// powerPvActive := entries.CopyPoint(powerPv, epp, "power_pv_active", "Power Pv Active (p13003)")
|
||||
// _ = entries.MakeState(powerPvActive)
|
||||
//
|
||||
// powerPvToBatteryActive := entries.CopyPoint(batteryChargePower, epp, "power_pv_to_battery_active", "")
|
||||
// powerPvToBatteryActive.SetValue(batteryChargePower.Value.First().ValueFloat())
|
||||
// _ = entries.MakeState(powerPvToBatteryActive)
|
||||
//
|
||||
// // powerPvToGrid := entries.GetReflect(epp.AddString("p13121"))
|
||||
// powerPvToGrid := entries.CopyPointFromName(epp.AddString("p13121"), epp, "power_pv_to_grid", "")
|
||||
// powerPvToGridActive := entries.CopyPoint(powerPvToGrid, epp, "power_pv_to_grid_active", "")
|
||||
// _ = entries.MakeState(powerPvToGridActive)
|
||||
//
|
||||
// powerPvToLoad := entries.CopyPoint(powerPv, epp, "power_pv_to_load", "Power Pv To Load (Calc)")
|
||||
// one := powerPv.Value.First().ValueFloat()
|
||||
// two := batteryChargePower.Value.First().ValueFloat()
|
||||
// three := powerPvToGrid.Value.First().ValueFloat()
|
||||
// powerPvToLoad.SetValue(one - two - three)
|
||||
// powerPvToLoadActive := entries.CopyPoint(powerPvToLoad, epp, "power_pv_to_load_active", "Power Pv To Load Active (Calc)")
|
||||
// _ = entries.MakeState(powerPvToLoadActive)
|
||||
//
|
||||
//
|
||||
// // Battery src
|
||||
// powerBatteryActive := entries.CopyPoint(batteryChargePower, epp, "power_battery_active", "Power Battery Active (Calc)")
|
||||
// powerBatteryActive.SetValue(entries.LowerUpper(batteryDischargePower, batteryChargePower))
|
||||
// _ = entries.MakeState(powerBatteryActive)
|
||||
//
|
||||
// powerBatteryToLoadActive := entries.CopyPoint(batteryDischargePower, epp, "power_battery_to_load_active", "Power Battery To Load Active (Calc)")
|
||||
// powerBatteryToLoadActive.SetValue(batteryDischargePower.Value.First().ValueFloat())
|
||||
// _ = entries.MakeState(powerBatteryToLoadActive)
|
||||
//
|
||||
// powerBatteryToGridActive := entries.CopyPoint(batteryChargePower, epp, "power_battery_to_grid_active", "Power Battery To Grid Active (Calc)")
|
||||
// powerBatteryToGridActive.SetValue(0.0)
|
||||
// _ = entries.MakeState(powerBatteryToGridActive)
|
||||
//
|
||||
//
|
||||
// // Grid src
|
||||
// powerGridToLoad := entries.GetReflect(epp.AddString("p13149"))
|
||||
// powerGridToLoadActive := entries.CopyPoint(powerGridToLoad, epp, "power_grid_to_load_active", "Power Grid To Load Active (p13149)")
|
||||
// _ = entries.MakeState(powerGridToLoadActive)
|
||||
//
|
||||
// powerGridActive := entries.CopyPoint(powerGridToLoad, epp, "power_grid_active", "Power Grid Active (Calc)")
|
||||
// powerGridActive.SetValue(entries.LowerUpper(powerPvToGrid, powerGridToLoad))
|
||||
// _ = entries.MakeState(powerGridActive)
|
||||
//
|
||||
// powerGridToBatteryActive := entries.CopyPoint(powerGridToLoad, epp, "power_grid_to_battery_active", "Power Grid To Battery Active (Calc)")
|
||||
// powerGridToBatteryActive.SetValue(0.0)
|
||||
// _ = entries.MakeState(powerGridToBatteryActive)
|
||||
//
|
||||
// gridEnergy := entries.CopyPoint(pvToGridEnergy, epp, "grid_energy", "Grid Energy (Calc)")
|
||||
// gridEnergy.SetValue(entries.LowerUpper(pvToGridEnergy, dailyPurchasedEnergy))
|
||||
//
|
||||
//
|
||||
// // Load src
|
||||
// powerLoadActive := entries.CopyPointFromName(epp.AddString("p13119"), epp, "power_load_active", "Power Load Active (p13119)")
|
||||
// _ = entries.MakeState(powerLoadActive)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EndPoint) GetBattery(entries api.DataMap) {
|
||||
func (e *EndPoint) SetBatteryPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
for range Only.Once {
|
||||
for _, device := range e.Response.ResultData.PageList {
|
||||
if !device.DeviceType.Match(api.DeviceNameBattery) {
|
||||
// Only looking for a Battery.
|
||||
continue
|
||||
}
|
||||
epp := GoStruct.NewEndPointPath("virtual", device.PsId.String(), device.PsKey.String())
|
||||
// Points are embedded within []PointStruct. So manually add virtuals instead of using the structure.
|
||||
// /////////////////////////////////////////////////////// //
|
||||
// Battery Power
|
||||
batteryChargePower := entries.CopyPointFromName(epp.AddString("p13126"), epp, "battery_charge_power", "Battery Charge Power (p13126)")
|
||||
|
||||
// Battery Voltage
|
||||
_ = entries.CopyPointFromName("p58601.value", epp, "battery_voltage", "")
|
||||
// Battery Current
|
||||
_ = entries.CopyPointFromName("p58602.value", epp, "battery_current", "")
|
||||
// Battery Temperature
|
||||
_ = entries.CopyPointFromName("p58603.value", epp, "battery_temperature", "")
|
||||
// Battery Level
|
||||
_ = entries.CopyPointFromName("p58604.value", epp, "battery_level", "")
|
||||
// Battery Health (SOH)
|
||||
_ = entries.CopyPointFromName("p58605.value", epp, "battery_health", "")
|
||||
// Total Battery Charging Energy
|
||||
_ = entries.CopyPointFromName("p58606.value", epp, "total_battery_charging_energy", "")
|
||||
// Total Battery Discharging Energy
|
||||
_ = entries.CopyPointFromName("p58607.value", epp, "total_battery_discharging_energy", "")
|
||||
}
|
||||
batteryDischargePower := entries.CopyPointFromName(epp.AddString("p13150"), epp, "battery_discharge_power", "Battery Discharge Power (p13150)")
|
||||
|
||||
batteryPower := entries.CopyPoint(batteryChargePower, epp, "battery_power", "Battery Power (Calc)")
|
||||
batteryPower.SetValue(entries.LowerUpper(batteryDischargePower, batteryChargePower))
|
||||
|
||||
batteryPowerActive := entries.CopyPoint(batteryPower, epp, "battery_power_active", "Battery Power Active (Calc)")
|
||||
_ = entries.MakeState(batteryPowerActive)
|
||||
|
||||
|
||||
// /////////////////////////////////////////////////////// //
|
||||
batteryDischargeEnergy := entries.CopyPointFromName(epp.AddString("p13029"), epp, "battery_discharge_energy", "Battery Discharge Energy (p13029)")
|
||||
|
||||
batteryChargeEnergy := entries.CopyPointFromName(epp.AddString("p13174"), epp, "battery_charge_energy", "Battery Charge Energy (p13174)")
|
||||
|
||||
batteryEnergy := entries.CopyPoint(batteryChargeEnergy, epp, "battery_energy", "Battery Energy (Calc)")
|
||||
batteryEnergy.SetValue(entries.LowerUpper(batteryChargeEnergy, batteryDischargeEnergy))
|
||||
|
||||
batteryEnergyActive := entries.CopyPoint(batteryEnergy, epp, "battery_energy_active", "Battery Energy Active (Calc)")
|
||||
_ = entries.MakeState(batteryEnergyActive)
|
||||
|
||||
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.Value.SetUnit("%")
|
||||
|
||||
|
||||
// /////////////////////////////////////////////////////// //
|
||||
batteryToLoadPower := entries.CopyPoint(batteryDischargePower, epp, "battery_to_load_power", "Battery To Load Power (Calc)")
|
||||
|
||||
batteryToLoadPowerActive := entries.CopyPoint(batteryToLoadPower, epp, "battery_to_load_power_active", "Battery To Load Power Active (Calc)")
|
||||
_ = entries.MakeState(batteryToLoadPowerActive)
|
||||
|
||||
batteryToGridPowerActive := entries.CopyPoint(batteryDischargePower, epp, "battery_to_grid_power_active", "Battery To Grid Power Active (Calc)")
|
||||
batteryToGridPowerActive.SetValue(0.0)
|
||||
_ = entries.MakeState(batteryToGridPowerActive)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
for range Only.Once {
|
||||
// /////////////////////////////////////////////////////// //
|
||||
// PV Power
|
||||
pvPower := entries.CopyPointFromName(epp.AddString("p13003"), epp, "pv_power", "Power Pv (p13003)")
|
||||
|
||||
pvPowerActive := entries.CopyPoint(pvPower, epp, "pv_power_active", "Power Pv Active (p13003)")
|
||||
_ = entries.MakeState(pvPowerActive)
|
||||
|
||||
pvToGridPower := entries.CopyPointFromName(epp.AddString("p13121"), epp, "pv_to_grid_power", "Pv To Grid Power (p13121)")
|
||||
|
||||
PvToGridPowerActive := entries.CopyPoint(pvToGridPower, epp, "pv_to_grid_power_active", "Pv To Grid Power Active (p13121)")
|
||||
_ = entries.MakeState(PvToGridPowerActive)
|
||||
|
||||
pvToBatteryPower := entries.CopyPointFromName(epp.AddString("p13126"), epp, "pv_to_battery_power", "Pv To Battery Power (p13126)")
|
||||
|
||||
pvToBatteryPowerActive := entries.CopyPoint(pvToBatteryPower, epp, "pv_to_battery_power_active", "Pv To Battery Power Active (p13126)")
|
||||
pvToBatteryPowerActive.SetValue(pvToBatteryPower.Value.First().ValueFloat())
|
||||
_ = entries.MakeState(pvToBatteryPowerActive)
|
||||
|
||||
pvToLoadPower := entries.CopyPoint(pvPower, epp, "pv_to_load_power", "Pv To Load Power (Calc)")
|
||||
one := pvPower.Value.First().ValueFloat()
|
||||
two := pvToBatteryPower.Value.First().ValueFloat()
|
||||
three := pvToGridPower.Value.First().ValueFloat()
|
||||
pvToLoadPower.SetValue(one - two - three)
|
||||
|
||||
pvToLoadPowerActive := entries.CopyPoint(pvToLoadPower, epp, "pv_to_load_power_active", "Pv To Load Power Active (Calc)")
|
||||
_ = entries.MakeState(pvToLoadPowerActive)
|
||||
|
||||
pvDailyEnergy := entries.CopyPointFromName(epp.AddString("p13112"), epp, "pv_daily_energy", "Pv Daily Energy (p13112)")
|
||||
|
||||
pvToGridEnergy := entries.CopyPointFromName(epp.AddString("p13173"), epp, "pv_to_grid_energy", "Pv To Grid Energy (p13173)")
|
||||
|
||||
pvToGridEnergyPercent := entries.CopyPoint(pvDailyEnergy, epp, "pv_to_grid_energy_percent", "Pv To Grid Energy Percent (Calc)")
|
||||
pvToGridEnergyPercent.SetValue(entries.GetPercent(pvToGridEnergy, pvDailyEnergy, 1))
|
||||
pvToGridEnergyPercent.Value.SetUnit("%")
|
||||
|
||||
pvToBatteryEnergy := entries.CopyPointFromName(epp.AddString("p13174"), epp, "pv_to_battery_energy", "Pv To Battery Energy (p13174)")
|
||||
|
||||
totalDailyEnergy := entries.CopyPointFromName(epp.AddString("p13199"), epp, "total_daily_energy", "Total Daily Energy (p13199)")
|
||||
|
||||
// p13112 (Pv Daily Energy) - p13122 (Daily Feed-in Energy) - p13174 (Daily Battery Charging Energy from PV)
|
||||
// 60.4 - 44.5 - 6.3
|
||||
dailyFeedInEnergy := entries.GetReflect(epp.AddString("p13122"))
|
||||
batteryChargeEnergy := entries.GetReflect(epp.AddString("p13174"))
|
||||
selfConsumptionOfPv := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_consumption_energy", "Pv Consumption Energy (Calc)")
|
||||
tmp1 := pvDailyEnergy.Value.First().Value() - dailyFeedInEnergy.Value.First().Value() - batteryChargeEnergy.Value.First().Value()
|
||||
selfConsumptionOfPv.SetValue(tmp1)
|
||||
selfConsumptionOfPv.SetValuePrecision(3)
|
||||
|
||||
selfConsumptionOfPvPercent := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_consumption_energy_percent", "Pv Consumption Energy Percent (Calc)")
|
||||
selfConsumptionOfPvPercent.SetValue(entries.GetPercent(selfConsumptionOfPv, pvDailyEnergy, 1))
|
||||
selfConsumptionOfPvPercent.Value.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)")
|
||||
gridToLoadEnergy := entries.GetReflect(epp.AddString("p13147"))
|
||||
pvToLoadEnergy := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_to_load_energy", "Pv To Load Energy (Calc)")
|
||||
tmp2 := totalDailyEnergy.Value.First().Value() - gridToLoadEnergy.Value.First().Value()
|
||||
pvToLoadEnergy.SetValue(tmp2)
|
||||
pvToLoadEnergy.SetValuePrecision(3)
|
||||
|
||||
pvToLoadEnergyPercent := entries.CopyPoint(pvDailyEnergy, epp, "pv_to_load_energy_percent", "Pv To Load Energy Percent (Calc)")
|
||||
pvToLoadEnergyPercent.SetValue(entries.GetPercent(pvToLoadEnergy, totalDailyEnergy, 1))
|
||||
pvToLoadEnergyPercent.Value.SetUnit("%")
|
||||
|
||||
gridToLoadDailyEnergy := entries.GetReflect(epp.AddString("p13147"))
|
||||
pvDailyEnergyPercent := entries.CopyPoint(totalDailyEnergy, epp, "pv_daily_energy_percent", "Pv Daily Energy Percent (Calc)")
|
||||
dpe := totalDailyEnergy.Value.First().ValueFloat() - gridToLoadDailyEnergy.Value.First().ValueFloat()
|
||||
pvDailyEnergyPercent.SetValue(api.GetPercent(dpe, totalDailyEnergy.Value.First().ValueFloat(), 1))
|
||||
pvDailyEnergyPercent.Value.SetUnit("%")
|
||||
|
||||
pvEnergy := entries.CopyPointFromName(pvToLoadEnergy.PointId(), epp, "pv_energy", "Pv Energy (Calc)")
|
||||
// pvDailyYield := entries.GetReflect(pvSelfConsumption.PointId())
|
||||
pvEnergy.SetValue(GoStruct.AddFloatValues(3, pvToLoadEnergy, pvToBatteryEnergy, pvToGridEnergy))
|
||||
|
||||
// DailyFeedInEnergy - @TODO - This may differ from DailyFeedInEnergyPv
|
||||
// _ = entries.CopyPointFromName(epp.AddString("p13122"), epp, "pv_to_grid2", "")
|
||||
|
||||
// TotalPvYield
|
||||
_ = entries.CopyPointFromName(epp.AddString("p13134"), epp, "pv_total_energy", "Pv Total Energy (p13134)")
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EndPoint) SetGridPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
for range Only.Once {
|
||||
gridToLoadPower := entries.CopyPointFromName(epp.AddString("p13149"), epp, "grid_to_load_power", "Grid To Load Power (p13149)")
|
||||
|
||||
gridToLoadPowerActive := entries.CopyPoint(gridToLoadPower, epp, "grid_to_load_power_active", "Grid To Load Power Active (p13149)")
|
||||
_ = entries.MakeState(gridToLoadPowerActive)
|
||||
|
||||
gridToLoadEnergy := entries.CopyPointFromName(epp.AddString("p13147"), epp, "grid_to_load_energy", "Grid To Load Energy (p13147)")
|
||||
|
||||
totalLoadEnergy := entries.CopyPointFromName(epp.AddString("p13199"), epp, "total_load_energy", "Total Load Energy (Calc)")
|
||||
gridToLoadEnergyPercent := entries.CopyPoint(totalLoadEnergy, epp, "grid_to_load_energy_percent", "")
|
||||
gridToLoadEnergyPercent.SetValue(entries.GetPercent(gridToLoadEnergy, totalLoadEnergy, 1))
|
||||
gridToLoadEnergyPercent.Value.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)")
|
||||
gridPower.SetValue(entries.LowerUpper(pvToGridPower, gridToLoadPower))
|
||||
|
||||
gridPowerActive := entries.CopyPoint(gridPower, epp, "grid_power_active", "Grid Power Active (Calc)")
|
||||
_ = entries.MakeState(gridPowerActive)
|
||||
|
||||
gridToBatteryPowerActive := entries.CopyPoint(gridToLoadPower, epp, "grid_to_battery_power_active", "Grid To Battery Power Active (Calc)")
|
||||
gridToBatteryPowerActive.SetValue(0.0)
|
||||
_ = entries.MakeState(gridToBatteryPowerActive)
|
||||
|
||||
pvToGridEnergy := entries.CopyPointFromName(epp.AddString("p13173"), epp, "pv_to_grid_energy", "Pv To Grid Energy (p13173)")
|
||||
|
||||
gridEnergy := entries.CopyPoint(pvToGridEnergy, epp, "grid_energy", "Grid Energy (Calc)")
|
||||
gridEnergy.SetValue(entries.LowerUpper(pvToGridEnergy, gridToLoadEnergy))
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EndPoint) SetLoadPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
for range Only.Once {
|
||||
// Daily Load Energy Consumption
|
||||
_ = entries.CopyPointFromName(epp.AddString("p13199"), epp, "daily_total_energy", "Daily Total Energy (p13199)")
|
||||
|
||||
// Total Load Energy Consumption
|
||||
// _ = entries.CopyPointFromName(epp.AddString("p13130"), epp, "total_energy_consumption", "")
|
||||
|
||||
loadPower := entries.CopyPointFromName(epp.AddString("p13119"), epp, "load_power", "Load Power (p13119)")
|
||||
|
||||
loadPowerActive := entries.CopyPoint(loadPower, epp, "load_power_active", "Load Power Active (p13119)")
|
||||
_ = entries.MakeState(loadPowerActive)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// func (e *EndPoint) SetBatteryPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
// for range Only.Once {
|
||||
// // /////////////////////////////////////////////////////// //
|
||||
// // Battery Power
|
||||
// batteryChargePower := entries.CopyPointFromName(epp.AddString("p13126"), epp, "battery_charge_power", "Battery Charge Power (p13126)")
|
||||
//
|
||||
// batteryDischargePower := entries.CopyPointFromName(epp.AddString("p13150"), epp, "battery_discharge_power", "Battery Discharge Power (p13150)")
|
||||
//
|
||||
// batteryPower := entries.CopyPoint(batteryChargePower, epp, "battery_power", "Battery Power (Calc)")
|
||||
// batteryPower.SetValue(entries.LowerUpper(batteryDischargePower, batteryChargePower))
|
||||
// batteryPowerActive := entries.CopyPoint(batteryPower, epp, "battery_power_active", "Battery Power Active (Calc)")
|
||||
// _ = entries.MakeState(batteryPowerActive)
|
||||
//
|
||||
//
|
||||
// // /////////////////////////////////////////////////////// //
|
||||
// batteryDischargeEnergy := entries.CopyPointFromName(epp.AddString("p13029"), epp, "battery_discharge_energy", "Battery Discharge Energy (p13029)")
|
||||
//
|
||||
// batteryChargeEnergy := entries.CopyPointFromName(epp.AddString("p13174"), epp, "battery_charge_energy", "Battery Charge Energy (p13174)")
|
||||
//
|
||||
// batteryEnergy := entries.CopyPoint(batteryChargeEnergy, epp, "battery_energy", "Battery Energy (Calc)")
|
||||
// batteryEnergy.SetValue(entries.LowerUpper(batteryChargeEnergy, batteryDischargeEnergy))
|
||||
//
|
||||
// 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.Value.SetUnit("%")
|
||||
//
|
||||
//
|
||||
// // /////////////////////////////////////////////////////// //
|
||||
// batteryToLoadPowerActive := entries.CopyPoint(batteryDischargePower, epp, "battery_to_load_power_active", "Battery To Load Power Active (Calc)")
|
||||
// batteryToLoadPowerActive.SetValue(batteryDischargePower.Value.First().ValueFloat())
|
||||
// _ = entries.MakeState(batteryToLoadPowerActive)
|
||||
//
|
||||
// batteryToGridPowerActive := entries.CopyPoint(batteryDischargePower, epp, "battery_to_grid_power_active", "Battery To Grid Power Active (Calc)")
|
||||
// batteryToGridPowerActive.SetValue(0.0)
|
||||
// _ = entries.MakeState(batteryToGridPowerActive)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
// for range Only.Once {
|
||||
// // /////////////////////////////////////////////////////// //
|
||||
// // PV Power
|
||||
// pvPower := entries.CopyPointFromName(epp.AddString("p13003"), epp, "pv_power", "")
|
||||
// pvPowerActive := entries.CopyPoint(pvPower, epp, "pv_power_active", "Power Pv Active (p13003)")
|
||||
// _ = entries.MakeState(pvPowerActive)
|
||||
//
|
||||
// pvToGridPower := entries.CopyPointFromName(epp.AddString("p13121"), epp, "pv_to_grid_power", "")
|
||||
// PvToGridPowerActive := entries.CopyPoint(pvToGridPower, epp, "pv_to_grid_power_active", "Pv To Grid Power Active (p13121)")
|
||||
// _ = entries.MakeState(PvToGridPowerActive)
|
||||
//
|
||||
// pvToBatteryPower := entries.CopyPointFromName(epp.AddString("p13126"), epp, "pv_to_battery_power", "")
|
||||
// pvToBatteryPowerActive := entries.CopyPoint(pvToBatteryPower, epp, "pv_to_battery_power_active", "Pv To Battery Power Active (p13126)")
|
||||
// pvToBatteryPowerActive.SetValue(pvToBatteryPower.Value.First().ValueFloat())
|
||||
// _ = entries.MakeState(pvToBatteryPowerActive)
|
||||
//
|
||||
// pvToLoadPower := entries.CopyPoint(pvPower, epp, "pv_to_load_power", "Pv To Load Power (Calc)")
|
||||
// one := pvPower.Value.First().ValueFloat()
|
||||
// two := pvToBatteryPower.Value.First().ValueFloat()
|
||||
// three := pvToGridPower.Value.First().ValueFloat()
|
||||
// pvToLoadPower.SetValue(one - two - three)
|
||||
// pvToLoadPowerActive := entries.CopyPoint(pvToLoadPower, epp, "pv_to_load_power_active", "Pv To Load Power Active (Calc)")
|
||||
// _ = entries.MakeState(pvToLoadPowerActive)
|
||||
//
|
||||
//
|
||||
// // Daily PV Yield
|
||||
// pvDailyEnergy := entries.CopyPointFromName(epp.AddString("p13112"), epp, "pv_daily_energy", "")
|
||||
// // dailyPvEnergy := entries.GetReflect(epp.AddString("p13112"))
|
||||
//
|
||||
//
|
||||
// // DailyFeedInEnergyPv
|
||||
// pvToGridEnergy := entries.CopyPointFromName(epp.AddString("p13173"), epp, "pv_to_grid_energy", "")
|
||||
//
|
||||
// pvToGridEnergyPercent := entries.CopyPoint(pvDailyEnergy, epp, "pv_to_grid_energy_percent", "Pv To Grid Energy Percent (Calc)")
|
||||
// pvToGridEnergyPercent.SetValue(entries.GetPercent(pvToGridEnergy, pvDailyEnergy, 1))
|
||||
// pvToGridEnergyPercent.Value.SetUnit("%")
|
||||
//
|
||||
//
|
||||
// // DailyLoadEnergyConsumptionFromPv
|
||||
// pvToLoadEnergy := entries.CopyPointFromName(epp.AddString("p13116"), epp, "pv_to_load_energy", "")
|
||||
// // pvSelfConsumption := entries.GetReflect(epp.AddString("p13116"))
|
||||
//
|
||||
//
|
||||
// pvToBatteryEnergy := entries.GetReflect(epp.AddString("p13174"))
|
||||
// pvEnergy := entries.CopyPointFromName(pvToLoadEnergy.PointId(), epp, "pv_energy", "Pv Energy (Calc)")
|
||||
// // pvDailyYield := entries.GetReflect(pvSelfConsumption.PointId())
|
||||
// pvEnergy.SetValue(GoStruct.AddFloatValues(3, pvToLoadEnergy, pvToBatteryEnergy, pvToGridEnergy))
|
||||
//
|
||||
// pvToLoadPercent := entries.CopyPoint(pvDailyEnergy, epp, "pv_to_load_energy_percent", "Pv To Load Energy Percent (Calc)")
|
||||
// pvToLoadPercent.SetValue(entries.GetPercent(pvToLoadEnergy, pvDailyEnergy, 1))
|
||||
// pvToLoadPercent.Value.SetUnit("%")
|
||||
//
|
||||
// totalDailyEnergy := entries.GetReflect(epp.AddString("p13199"))
|
||||
// gridToLoadDailyEnergy := entries.GetReflect(epp.AddString("p13147"))
|
||||
// pvDailyEnergyPercent := entries.CopyPoint(totalDailyEnergy, epp, "pv_daily_energy_percent", "")
|
||||
// dpe := totalDailyEnergy.Value.First().ValueFloat() - gridToLoadDailyEnergy.Value.First().ValueFloat()
|
||||
// pvDailyEnergyPercent.SetValue(api.GetPercent(dpe, totalDailyEnergy.Value.First().ValueFloat(), 1))
|
||||
// pvDailyEnergyPercent.Value.SetUnit("%")
|
||||
//
|
||||
// // DailyFeedInEnergy - @TODO - This may differ from DailyFeedInEnergyPv
|
||||
// // _ = entries.CopyPointFromName(epp.AddString("p13122"), epp, "pv_to_grid2", "")
|
||||
//
|
||||
// // TotalPvYield
|
||||
// // _ = entries.CopyPointFromName(epp.AddString("p13134"), epp, "pv_total_yield", "")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (e *EndPoint) SetGridPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
// for range Only.Once {
|
||||
// gridToLoadPower := entries.GetReflect(epp.AddString("p13149"))
|
||||
// gridToLoadPowerActive := entries.CopyPoint(gridToLoadPower, epp, "grid_to_load_power_active", "Power Grid To Load Active (p13149)")
|
||||
// _ = entries.MakeState(gridToLoadPowerActive)
|
||||
//
|
||||
// // DailyPurchasedEnergy
|
||||
// _ = entries.CopyPointFromName(epp.AddString("p13147"), epp, "grid_to_load_energy", "Grid To Load Energy (p13147)")
|
||||
// // _ = entries.GetReflect(epp.AddString("p13147"))
|
||||
//
|
||||
// dailyTotalEnergy := entries.GetReflect(epp.AddString("p13199"))
|
||||
// dailyPurchasedEnergy := entries.GetReflect(epp.AddString("p13147"))
|
||||
// gridToLoadEnergyPercent := entries.CopyPoint(dailyTotalEnergy, epp, "grid_to_load_energy_percent", "")
|
||||
// gridToLoadEnergyPercent.SetValue(entries.GetPercent(dailyPurchasedEnergy, dailyTotalEnergy, 1))
|
||||
// gridToLoadEnergyPercent.Value.SetUnit("%")
|
||||
//
|
||||
// pvToGridPower := entries.GetReflect(epp.AddString("p13121"))
|
||||
// gridPowerActive := entries.CopyPoint(gridToLoadPower, epp, "grid_power_active", "Grid Power Active (Calc)")
|
||||
// gridPowerActive.SetValue(entries.LowerUpper(pvToGridPower, gridToLoadPower))
|
||||
// _ = entries.MakeState(gridPowerActive)
|
||||
//
|
||||
// gridToBatteryPowerActive := entries.CopyPoint(gridToLoadPower, epp, "grid_to_battery_power_active", "Power Grid To Battery Active (Calc)")
|
||||
// gridToBatteryPowerActive.SetValue(0.0)
|
||||
// _ = entries.MakeState(gridToBatteryPowerActive)
|
||||
//
|
||||
// pvToGridEnergy := entries.GetReflect(epp.AddString("p13173"))
|
||||
// gridEnergy := entries.CopyPoint(pvToGridEnergy, epp, "grid_energy", "Grid Energy (Calc)")
|
||||
// gridEnergy.SetValue(entries.LowerUpper(pvToGridEnergy, dailyPurchasedEnergy))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (e *EndPoint) SetLoadPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
|
||||
// for range Only.Once {
|
||||
// // Daily Load Energy Consumption
|
||||
// _ = entries.CopyPointFromName(epp.AddString("p13199"), epp, "daily_total_energy", "Daily Total Energy (p13199)")
|
||||
//
|
||||
// // Total Load Energy Consumption
|
||||
// // _ = entries.CopyPointFromName(epp.AddString("p13130"), epp, "total_energy_consumption", "")
|
||||
//
|
||||
// // Load src
|
||||
// powerLoadActive := entries.CopyPointFromName(epp.AddString("p13119"), epp, "power_load_active", "Power Load Active (p13119)")
|
||||
// _ = entries.MakeState(powerLoadActive)
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// func (e *EndPoint) GetCommunicationModule(entries api.DataMap) {
|
||||
// for range Only.Once {
|
||||
// for _, device := range e.Response.ResultData.PageList {
|
||||
// if !device.DeviceType.Match(api.DeviceNameCommunicationModule) {
|
||||
// // Only looking for a Communication Module.
|
||||
// continue
|
||||
// }
|
||||
// epp := GoStruct.NewEndPointPath("virtual", device.PsKey.String())
|
||||
// if device.PsKey.String() == "" {
|
||||
// epp = GoStruct.NewEndPointPath("virtual", device.PsId.String())
|
||||
// }
|
||||
// // Points are embedded within []PointStruct. So manually add virtuals instead of using the structure.
|
||||
//
|
||||
// // WLAN Signal Strength
|
||||
// _ = entries.CopyPointFromName("p23014.value", epp, "wlan_signal_strength", "")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (e *EndPoint) GetBattery(entries api.DataMap) {
|
||||
// for range Only.Once {
|
||||
// for _, device := range e.Response.ResultData.PageList {
|
||||
// if !device.DeviceType.Match(api.DeviceNameBattery) {
|
||||
// // Only looking for a Battery.
|
||||
// continue
|
||||
// }
|
||||
// epp := GoStruct.NewEndPointPath("virtual", device.PsKey.String())
|
||||
// if device.PsKey.String() == "" {
|
||||
// epp = GoStruct.NewEndPointPath("virtual", device.PsId.String())
|
||||
// }
|
||||
// // Points are embedded within []PointStruct. So manually add virtuals instead of using the structure.
|
||||
//
|
||||
// // Battery Voltage
|
||||
// _ = entries.CopyPointFromName("p58601.value", epp, "battery_voltage", "")
|
||||
// // Battery Current
|
||||
// _ = entries.CopyPointFromName("p58602.value", epp, "battery_current", "")
|
||||
// // Battery Temperature
|
||||
// _ = entries.CopyPointFromName("p58603.value", epp, "battery_temperature", "")
|
||||
// // Battery Level
|
||||
// _ = entries.CopyPointFromName("p58604.value", epp, "battery_level", "")
|
||||
// // Battery Health (SOH)
|
||||
// _ = entries.CopyPointFromName("p58605.value", epp, "battery_health", "")
|
||||
// // Total Battery Charging Energy
|
||||
// _ = entries.CopyPointFromName("p58606.value", epp, "total_battery_charging_energy", "")
|
||||
// // Total Battery Discharging Energy
|
||||
// _ = entries.CopyPointFromName("p58607.value", epp, "total_battery_discharging_energy", "")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
@ -5,15 +5,14 @@ import (
|
||||
"GoSungrow/iSolarCloud/api/GoStruct/valueTypes"
|
||||
)
|
||||
|
||||
|
||||
type Device struct {
|
||||
GoStruct GoStruct.GoStruct `json:"GoStruct" PointIdFrom:"PsId" PointIdReplace:"true" PointDeviceFrom:"PsId"`
|
||||
GoStruct GoStruct.GoStruct `json:"GoStruct" PointIdFrom:"PsId" PointIdReplace:"true" PointDeviceFrom:"PsId"`
|
||||
|
||||
PsKey valueTypes.PsKey `json:"ps_key" PointId:"ps_key" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
PsId valueTypes.PsId `json:"ps_id" PointId:"ps_id" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
DeviceType valueTypes.Integer `json:"device_type" PointId:"device_type" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
DeviceCode valueTypes.Integer `json:"device_code" PointId:"device_code" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
ChannelId valueTypes.Integer `json:"chnnl_id" PointId:"channel_id" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
PsKey valueTypes.PsKey `json:"ps_key" PointId:"ps_key" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
PsId valueTypes.PsId `json:"ps_id" PointId:"ps_id" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
DeviceType valueTypes.Integer `json:"device_type" PointId:"device_type" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
DeviceCode valueTypes.Integer `json:"device_code" PointId:"device_code" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
ChannelId valueTypes.Integer `json:"chnnl_id" PointId:"channel_id" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
|
||||
PsName valueTypes.String `json:"ps_name"`
|
||||
PsStatus valueTypes.Bool `json:"ps_status"`
|
||||
@ -38,14 +37,9 @@ type Device struct {
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
BuildStatus valueTypes.Integer `json:"build_status" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
Co2Reduce valueTypes.UnitValue `json:"co2_reduce"`
|
||||
Co2ReduceTotal valueTypes.UnitValue `json:"co2_reduce_total" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
CurrPower valueTypes.UnitValue `json:"curr_power"`
|
||||
DailyIrradiation valueTypes.UnitValue `json:"daily_irradiation" PointUpdateFreq:"UpdateFreqDay"`
|
||||
DailyIrradiationVirgin valueTypes.Float `json:"daily_irradiation_virgin" PointIgnore:"true"`
|
||||
Description valueTypes.String `json:"description"`
|
||||
DesignCapacity valueTypes.Float `json:"design_capacity" PointUnitFrom:"design_capacity_unit"`
|
||||
DesignCapacityUnit valueTypes.String `json:"design_capacity_unit"`
|
||||
DesignCapacity valueTypes.Float `json:"design_capacity" PointUnitFrom:"DesignCapacityUnit"`
|
||||
DesignCapacityUnit valueTypes.String `json:"design_capacity_unit" PointIgnore:"true"`
|
||||
DesignCapacityVirgin valueTypes.Float `json:"design_capacity_virgin" PointIgnore:"true"`
|
||||
EquivalentHour valueTypes.UnitValue `json:"equivalent_hour" PointUpdateFreq:"UpdateFreqDay"`
|
||||
FaultAlarmOfflineDevCount valueTypes.Count `json:"fault_alarm_offline_dev_count"`
|
||||
@ -86,16 +80,16 @@ type Device struct {
|
||||
ZipCode valueTypes.String `json:"zip_code"`
|
||||
Images PowerStationImages `json:"images" PointArrayFlatten:"false"`
|
||||
|
||||
P83022y valueTypes.String `json:"p83022y" PointId:"p83022" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83046 valueTypes.Float `json:"p83046" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83048 valueTypes.Float `json:"p83048" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83049 valueTypes.Float `json:"p83049" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83050 valueTypes.Float `json:"p83050" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83051 valueTypes.Float `json:"p83051" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83054 valueTypes.Float `json:"p83054" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83055 valueTypes.Float `json:"p83055" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83067 valueTypes.Float `json:"p83067" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83070 valueTypes.Float `json:"p83070" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
P83022y valueTypes.String `json:"p83022y" PointId:"p83022" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83046 valueTypes.Float `json:"p83046" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83048 valueTypes.Float `json:"p83048" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83049 valueTypes.Float `json:"p83049" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83050 valueTypes.Float `json:"p83050" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83051 valueTypes.Float `json:"p83051" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83054 valueTypes.Float `json:"p83054" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83055 valueTypes.Float `json:"p83055" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83067 valueTypes.Float `json:"p83067" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83070 valueTypes.Float `json:"p83070" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
P83076 valueTypes.Float `json:"p83076" PointId:"_p83076" PointName:"Pv Power" PointIgnore:"true"` // Dupe of PvPower
|
||||
P83077 valueTypes.Float `json:"p83077" PointId:"_p83077" PointName:"Pv Energy" PointIgnore:"true"` // Dupe of PvEnergy
|
||||
P83081 valueTypes.Float `json:"p83081" PointId:"_p83081" PointName:"Es Power" PointIgnore:"true"` // Dupe of EsPower
|
||||
@ -104,34 +98,42 @@ type Device struct {
|
||||
P83118 valueTypes.Float `json:"p83118" PointId:"_p83118" PointName:"Use Energy" PointIgnore:"true"` // Dupe of UseEnergy
|
||||
P83120 valueTypes.Float `json:"p83120" PointId:"_p83120" PointName:"Es Energy" PointIgnore:"true"` // Dupe of EsEnergy
|
||||
P83127 valueTypes.Float `json:"p83127" PointId:"_p83127" PointName:"Es Total Energy" PointIgnore:"true"` // Dupe of EsTotalEnergy
|
||||
PvPower valueTypes.UnitValue `json:"pv_power" PointId:"p83076" PointName:"Pv Power" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
PvEnergy valueTypes.UnitValue `json:"pv_energy" PointId:"p83077" PointName:"Pv Energy" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
EsPower valueTypes.UnitValue `json:"es_power" PointId:"p83081" PointName:"ES Power" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
EsDischargeEnergy valueTypes.UnitValue `json:"es_disenergy" PointId:"p83089" PointName:"ES Discharge Energy" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
EsTotalDischargeEnergy valueTypes.UnitValue `json:"es_total_disenergy" PointId:"p83095" PointName:"ES Total Discharge Energy" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
UseEnergy valueTypes.UnitValue `json:"use_energy" PointId:"p83118" PointName:"Use Energy" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
EsEnergy valueTypes.UnitValue `json:"es_energy" PointId:"p83120" PointName:"ES Energy" PointUpdateFreq:"UpdateFreq5Mins"`
|
||||
EsTotalEnergy valueTypes.UnitValue `json:"es_total_energy" PointId:"p83127" PointName:"ES Total Energy" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
ParamCo2 valueTypes.Float `json:"param_co2"`
|
||||
ParamCoal valueTypes.Float `json:"param_coal"`
|
||||
ParamIncome valueTypes.Float `json:"param_income"`
|
||||
ParamMeter valueTypes.Float `json:"param_meter"`
|
||||
ParamNox valueTypes.Float `json:"param_nox"`
|
||||
ParamPowder valueTypes.Float `json:"param_powder"`
|
||||
ParamSo2 valueTypes.Float `json:"param_so2"`
|
||||
ParamTree valueTypes.Float `json:"param_tree"`
|
||||
ParamWater valueTypes.Float `json:"param_water"`
|
||||
PrScale string `json:"pr_scale"`
|
||||
Radiation valueTypes.UnitValue `json:"radiation"`
|
||||
|
||||
Co2Reduce valueTypes.UnitValue `json:"co2_reduce" PointVirtual:"true"`
|
||||
Co2ReduceTotal valueTypes.UnitValue `json:"co2_reduce_total" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
CurrPower valueTypes.UnitValue `json:"curr_power" PointVirtual:"true"`
|
||||
DailyIrradiation valueTypes.UnitValue `json:"daily_irradiation" PointUpdateFreq:"UpdateFreqDay" PointVirtual:"true"`
|
||||
DailyIrradiationVirgin valueTypes.Float `json:"daily_irradiation_virgin" PointIgnore:"true"`
|
||||
PvPower valueTypes.UnitValue `json:"pv_power" PointId:"p83076" PointName:"Pv Power" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
PvEnergy valueTypes.UnitValue `json:"pv_energy" PointId:"p83077" PointName:"Pv Energy" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
EsPower valueTypes.UnitValue `json:"es_power" PointId:"p83081" PointName:"ES Power" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
EsDischargeEnergy valueTypes.UnitValue `json:"es_disenergy" PointId:"p83089" PointName:"ES Discharge Energy" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
EsTotalDischargeEnergy valueTypes.UnitValue `json:"es_total_disenergy" PointId:"p83095" PointName:"ES Total Discharge Energy" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
UseEnergy valueTypes.UnitValue `json:"use_energy" PointId:"p83118" PointName:"Use Energy" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
EsEnergy valueTypes.UnitValue `json:"es_energy" PointId:"p83120" PointName:"ES Energy" PointUpdateFreq:"UpdateFreq5Mins" PointVirtual:"true"`
|
||||
EsTotalEnergy valueTypes.UnitValue `json:"es_total_energy" PointId:"p83127" PointName:"ES Total Energy" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
|
||||
ParamCo2 valueTypes.Float `json:"param_co2" PointVirtual:"true"`
|
||||
ParamCoal valueTypes.Float `json:"param_coal" PointVirtual:"true"`
|
||||
ParamIncome valueTypes.Float `json:"param_income" PointVirtual:"true"`
|
||||
ParamMeter valueTypes.Float `json:"param_meter" PointVirtual:"true"`
|
||||
ParamNox valueTypes.Float `json:"param_nox" PointVirtual:"true"`
|
||||
ParamPowder valueTypes.Float `json:"param_powder" PointVirtual:"true"`
|
||||
ParamSo2 valueTypes.Float `json:"param_so2" PointVirtual:"true"`
|
||||
ParamTree valueTypes.Float `json:"param_tree" PointVirtual:"true"`
|
||||
ParamWater valueTypes.Float `json:"param_water" PointVirtual:"true"`
|
||||
|
||||
PrScale valueTypes.String `json:"pr_scale"`
|
||||
Radiation valueTypes.UnitValue `json:"radiation" PointVirtual:"true"`
|
||||
RadiationVirgin valueTypes.Float `json:"radiation_virgin" PointIgnore:"true"`
|
||||
TodayEnergy valueTypes.UnitValue `json:"today_energy" PointUpdateFreq:"UpdateFreqDay"`
|
||||
TodayIncome valueTypes.UnitValue `json:"today_income" PointUpdateFreq:"UpdateFreqDay"`
|
||||
TotalCapacity valueTypes.UnitValue `json:"total_capcity" PointId:"total_capacity" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
TotalEnergy valueTypes.UnitValue `json:"total_energy" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
TotalIncome valueTypes.UnitValue `json:"total_income" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
TotalInitCo2Accelerate valueTypes.Float `json:"total_init_co2_accelerate" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
TotalInitElec valueTypes.Float `json:"total_init_elec" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
TotalInitProfit valueTypes.Float `json:"total_init_profit" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
TodayEnergy valueTypes.UnitValue `json:"today_energy" PointUpdateFreq:"UpdateFreqDay" PointVirtual:"true"`
|
||||
TodayIncome valueTypes.UnitValue `json:"today_income" PointUpdateFreq:"UpdateFreqDay" PointVirtual:"true"`
|
||||
TotalCapacity valueTypes.UnitValue `json:"total_capcity" PointId:"total_capacity" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
TotalEnergy valueTypes.UnitValue `json:"total_energy" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
TotalIncome valueTypes.UnitValue `json:"total_income" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
TotalInitCo2Accelerate valueTypes.Float `json:"total_init_co2_accelerate" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
TotalInitElec valueTypes.Float `json:"total_init_elec" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
TotalInitProfit valueTypes.Float `json:"total_init_profit" PointUpdateFreq:"UpdateFreqTotal" PointVirtual:"true"`
|
||||
}
|
||||
|
||||
// PowerStationImage - `json:"images" PointArrayFlatten:"false"`
|
||||
@ -147,7 +149,6 @@ type PowerStationImage struct {
|
||||
}
|
||||
type PowerStationImages []PowerStationImage
|
||||
|
||||
|
||||
// PsDirectOrgList - `json:"ps_direct_org_list" PointArrayFlatten:"false"`
|
||||
type PsDirectOrgList []struct {
|
||||
OrgId valueTypes.Integer `json:"org_id"`
|
||||
@ -155,7 +156,6 @@ type PsDirectOrgList []struct {
|
||||
OrgName valueTypes.String `json:"org_name"`
|
||||
}
|
||||
|
||||
|
||||
// PsOrgInfo - `json:"ps_org_info" PointArrayFlatten:"false"`
|
||||
type PsOrgInfo []struct {
|
||||
DealerOrgCode valueTypes.String `json:"dealer_org_code"`
|
||||
@ -169,7 +169,6 @@ type PsOrgInfo []struct {
|
||||
UpOrgId valueTypes.Integer `json:"up_org_id"`
|
||||
}
|
||||
|
||||
|
||||
// SelectedOrgList - `json:"selectedOrgList" PointId:"selected_org_list" PointArrayFlatten:"false"`
|
||||
type SelectedOrgList []struct {
|
||||
OrgId valueTypes.Integer `json:"org_id"`
|
||||
@ -177,7 +176,6 @@ type SelectedOrgList []struct {
|
||||
OrgName valueTypes.String `json:"org_name"`
|
||||
}
|
||||
|
||||
|
||||
// SnDetailList - `json:"sn_detail_list" PointArrayFlatten:"false"`
|
||||
type SnDetailList []struct {
|
||||
CommunicateDeviceType valueTypes.Integer `json:"communicate_device_type"`
|
||||
@ -187,10 +185,9 @@ type SnDetailList []struct {
|
||||
Sn valueTypes.String `json:"sn" PointName:"Serial Number"`
|
||||
}
|
||||
|
||||
|
||||
// ReportInfo - `json:"info" PointArrayFlatten:"false"`
|
||||
type ReportInfo []struct {
|
||||
GoStruct GoStruct.GoStruct `json:"-" PointIdFrom:"PsId" PointIdReplace:"true" PointDeviceFrom:"PsId"`
|
||||
GoStruct GoStruct.GoStruct `json:"-" PointIdFrom:"PsId" PointIdReplace:"true" PointDeviceFrom:"PsId"`
|
||||
|
||||
PsId valueTypes.PsId `json:"ps_id"`
|
||||
PsName valueTypes.String `json:"ps_name"`
|
||||
|
@ -37,6 +37,8 @@ const (
|
||||
PointUpdateFreq = "PointUpdateFreq"
|
||||
UpdateFreqInstant = "instant"
|
||||
UpdateFreq5Mins = "5mins"
|
||||
UpdateFreq15Mins = "15mins"
|
||||
UpdateFreq30Mins = "30mins"
|
||||
UpdateFreqBoot = "boot"
|
||||
UpdateFreqDay = "daily"
|
||||
UpdateFreqMonth = "monthly"
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -84,7 +84,7 @@ func PlainFileRead(fn string) ([]byte, error) {
|
||||
//goland:noinspection GoUnhandledErrorResult,GoDeferInLoop
|
||||
defer f.Close()
|
||||
|
||||
data, err = ioutil.ReadAll(f)
|
||||
data, err = io.ReadAll(f)
|
||||
}
|
||||
|
||||
return data, err
|
||||
|
@ -115,3 +115,10 @@ func (e *EndPointPath) PopLast() {
|
||||
return
|
||||
// return (*e)[:len(*e) - 1]
|
||||
}
|
||||
|
||||
func (e *EndPointPath) AddString(path ...string) string {
|
||||
var ret EndPointPath
|
||||
ret = *e
|
||||
ret.path = append(ret.path, path...)
|
||||
return ret.String()
|
||||
}
|
||||
|
@ -925,6 +925,12 @@ func (r *Reflect) SetValue(value interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Reflect) SetValuePrecision(precision int) {
|
||||
for range Only.Once {
|
||||
r.Value.SetPrecision(precision)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Reflect) SetUnit() {
|
||||
for range Only.Once {
|
||||
switch {
|
||||
@ -1699,14 +1705,14 @@ func GetStructValuesAsArray(ref *Reflect) []string {
|
||||
return ret
|
||||
}
|
||||
|
||||
func AddFloatValues(refs ...*Reflect) float64 {
|
||||
func AddFloatValues(precision int, refs ...*Reflect) float64 {
|
||||
var ret float64
|
||||
for _, ref := range refs {
|
||||
for _, value := range ref.Value.Range(true) {
|
||||
ret += value.ValueFloat()
|
||||
}
|
||||
}
|
||||
return ret
|
||||
return valueTypes.SetPrecision(ret, precision)
|
||||
}
|
||||
|
||||
func AddIntegerValues(refs ...*Reflect) int64 {
|
||||
|
@ -60,6 +60,10 @@ func (sm *StructMap) InitScan(current interface{}, options StructMapOptions) {
|
||||
|
||||
sm.PrintDebug("InitScan() EndPoint: '%s' Current: %s\n", sm.StructMapOptions.Name, sm.Start)
|
||||
|
||||
sm.Map = make(map[string]*Reflect)
|
||||
sm.VirtualMap = make(map[string]*Reflect)
|
||||
sm.TableMap = make(map[string]*Reflect)
|
||||
|
||||
sm.Scan(&Parent, &Parent)
|
||||
// fmt.Printf("sm.Current size: %v\n", unsafe.Sizeof(sm.Current))
|
||||
// fmt.Printf("sm.Map size: %v\n", unsafe.Sizeof(sm.Map))
|
||||
|
@ -3,6 +3,7 @@ package valueTypes
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -114,6 +115,14 @@ func (t *Float) SetValue(value float64) Float {
|
||||
return *t
|
||||
}
|
||||
|
||||
func (t *Float) SetPrecision(precision int) Float {
|
||||
for range Only.Once {
|
||||
t.float64 = SetPrecision(t.float64, precision)
|
||||
}
|
||||
|
||||
return *t
|
||||
}
|
||||
|
||||
func (t *Float) ToUnitValue() UnitValue {
|
||||
return SetUnitValueFloat("", "", t.float64)
|
||||
}
|
||||
@ -127,3 +136,12 @@ func SetFloatValue(value float64) Float {
|
||||
var t Float
|
||||
return t.SetValue(value)
|
||||
}
|
||||
|
||||
func round(num float64) int {
|
||||
return int(num + math.Copysign(0.5, num))
|
||||
}
|
||||
|
||||
func SetPrecision(num float64, precision int) float64 {
|
||||
output := math.Pow(10, float64(precision))
|
||||
return float64(round(num * output)) / output
|
||||
}
|
||||
|
@ -560,6 +560,16 @@ func (t *UnitValue) SetKey(key string) UnitValue {
|
||||
return *t
|
||||
}
|
||||
|
||||
func (t *UnitValue) SetPrecision(precision int) UnitValue {
|
||||
for range Only.Once {
|
||||
if t.float64 != nil {
|
||||
v := SetPrecision(*t.float64, precision)
|
||||
t.SetFloat(v)
|
||||
}
|
||||
}
|
||||
return *t
|
||||
}
|
||||
|
||||
func (t *UnitValue) IsZero() bool {
|
||||
var yes bool
|
||||
switch {
|
||||
@ -961,6 +971,24 @@ func (t *UnitValues) Last() *UnitValue {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (t *UnitValues) SetPrecision(precision int) {
|
||||
for range Only.Once {
|
||||
if t.IsArray() {
|
||||
for k := range t.arrayValues {
|
||||
t.arrayValues[k].SetPrecision(precision)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if t.IsMap() {
|
||||
for k := range t.mapValues {
|
||||
t.mapValues[k].SetPrecision(precision)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// mapValuess.
|
||||
|
||||
|
@ -57,7 +57,11 @@ func (dm *DataMap) StructToDataMap(endpoint EndPoint, parentDeviceId string, nam
|
||||
AddNil: false,
|
||||
AddEmpty: false,
|
||||
})
|
||||
if dm.parentDeviceId == "" {
|
||||
dm.parentDeviceId = name.First()
|
||||
}
|
||||
}
|
||||
|
||||
return *dm
|
||||
}
|
||||
|
||||
@ -131,9 +135,14 @@ func (dm *DataMap) CopyPoint(refEndpoint *GoStruct.Reflect, endpoint GoStruct.En
|
||||
if pointId != "" {
|
||||
Current.DataStructure.PointId = pointId
|
||||
}
|
||||
|
||||
if pointName != "" {
|
||||
Current.DataStructure.PointName = pointName
|
||||
// Current.DataStructure.PointName += " (" + Current.DataStructure.PointId + ")"
|
||||
// } else {
|
||||
|
||||
}
|
||||
|
||||
if !endpoint.IsZero() {
|
||||
Current.DataStructure.Endpoint.Clear()
|
||||
Current.DataStructure.Endpoint = endpoint
|
||||
@ -194,10 +203,10 @@ func (dm *DataMap) GetReflect(refEndpoint string) *GoStruct.Reflect {
|
||||
return Current
|
||||
}
|
||||
|
||||
func (dm *DataMap) MakeState(refEndpoint *GoStruct.Reflect, endpoint GoStruct.EndPointPath, pointId string, pointName string) *GoStruct.Reflect {
|
||||
var Current *GoStruct.Reflect
|
||||
func (dm *DataMap) MakeState(Current *GoStruct.Reflect) *GoStruct.Reflect {
|
||||
// func (dm *DataMap) MakeState(refEndpoint *GoStruct.Reflect, endpoint GoStruct.EndPointPath, pointId string, pointName string) *GoStruct.Reflect {
|
||||
for range Only.Once {
|
||||
Current = dm.CopyPoint(refEndpoint, endpoint, pointId, pointName)
|
||||
// Current = dm.CopyPoint(refEndpoint, endpoint, pointId, pointName)
|
||||
bv := Current.Value.First().IsNotZero()
|
||||
Current.Value.Reset()
|
||||
vt := valueTypes.SetUnitValueBool(bv)
|
||||
@ -222,8 +231,8 @@ func (dm *DataMap) LowerUpper(lowerEntry *GoStruct.Reflect, upperEntry *GoStruct
|
||||
return ret
|
||||
}
|
||||
|
||||
func (dm *DataMap) GetPercent(entry *GoStruct.Reflect, max *GoStruct.Reflect) float64 {
|
||||
return GetPercent(entry.Value.First().ValueFloat(), max.Value.First().ValueFloat())
|
||||
func (dm *DataMap) GetPercent(entry *GoStruct.Reflect, max *GoStruct.Reflect, precision int) float64 {
|
||||
return GetPercent(entry.Value.First().ValueFloat(), max.Value.First().ValueFloat(), precision)
|
||||
}
|
||||
|
||||
func (dm *DataMap) AppendMap(add DataMap) {
|
||||
@ -284,6 +293,13 @@ func (dm *DataMap) ProcessMap() {
|
||||
continue
|
||||
}
|
||||
|
||||
// key := Child.EndPointPath().String()
|
||||
// if strings.HasPrefix(key, "virtual") {
|
||||
// // Move virtual mappings over.
|
||||
// dm.StructMap.VirtualMap[key] = Child
|
||||
// delete(dm.StructMap.Map, key)
|
||||
// }
|
||||
|
||||
var when valueTypes.DateTime
|
||||
if Child.IsPointTimestampNotZero() {
|
||||
when = valueTypes.SetDateTimeValue(Child.DataStructure.PointTimestamp)
|
||||
@ -692,11 +708,13 @@ func CreatePoint(Current *GoStruct.Reflect, parentDeviceId string) Point {
|
||||
return point
|
||||
}
|
||||
|
||||
func GetPercent(value float64, max float64) float64 {
|
||||
func GetPercent(value float64, max float64, precision int) float64 {
|
||||
if max == 0 {
|
||||
return 0
|
||||
}
|
||||
return (value / max) * 100
|
||||
|
||||
percent := valueTypes.SetPrecision((value / max) * 100, precision)
|
||||
return percent
|
||||
}
|
||||
|
||||
func JoinWithDots(intSize int, dateFormat string, args ...interface{}) string {
|
||||
|
@ -39,8 +39,30 @@ func (p *Point) WhenReset() string {
|
||||
now := time.Now()
|
||||
|
||||
switch {
|
||||
case p.Is5Minute():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 5).Format("2006-01-02T15:04:05"))
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
|
||||
case p.Is15Minute():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 15).Format("2006-01-02T15:04:05"))
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
|
||||
case p.Is30Minute():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Truncate(time.Minute * 30).Format("2006-01-02T15:04:05"))
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
|
||||
|
||||
case p.IsInstant():
|
||||
ret = ""
|
||||
// ret = ""
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
|
||||
case p.IsBoot():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Format("2006-01-02") + "T00:00:00")
|
||||
// ret = fmt.Sprintf("%d", now.Unix())
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
|
||||
case p.IsDaily():
|
||||
now, err = time.Parse("2006-01-02T15:04:05", now.Format("2006-01-02") + "T00:00:00")
|
||||
@ -58,15 +80,14 @@ func (p *Point) WhenReset() string {
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
|
||||
case p.IsTotal():
|
||||
// ret = "0"
|
||||
ret = "1970-01-01T00:00:00"
|
||||
|
||||
default:
|
||||
// ret = "0"
|
||||
ret = "1970-01-01T00:00:00"
|
||||
// ret = "1970-01-01T00:00:00"
|
||||
ret = now.Format("2006-01-02T15:04:05") + ""
|
||||
}
|
||||
if err != nil {
|
||||
now := time.Now()
|
||||
// now := time.Now()
|
||||
ret = fmt.Sprintf("%d", now.Unix())
|
||||
}
|
||||
}
|
||||
@ -78,6 +99,34 @@ func (p Point) String() string {
|
||||
return fmt.Sprintf("Id:%s\tName:%s\tUnits:%s\tUpdateFreq:%s", p.Id, p.Description, p.Unit, p.UpdateFreq)
|
||||
}
|
||||
|
||||
func (p Point) Is5Minute() bool {
|
||||
if p.UpdateFreq == GoStruct.UpdateFreq5Mins {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p Point) Is15Minute() bool {
|
||||
if p.UpdateFreq == GoStruct.UpdateFreq15Mins {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p Point) Is30Minute() bool {
|
||||
if p.UpdateFreq == GoStruct.UpdateFreq30Mins {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p Point) IsBoot() bool {
|
||||
if p.UpdateFreq == GoStruct.UpdateFreqBoot {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p Point) IsInstant() bool {
|
||||
if p.UpdateFreq == GoStruct.UpdateFreqInstant {
|
||||
return true
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
|
||||
|
||||
type Web struct {
|
||||
Url EndPointUrl
|
||||
Body []byte
|
||||
Error error
|
||||
ServerUrl EndPointUrl
|
||||
Body []byte
|
||||
Error error
|
||||
|
||||
cacheDir string
|
||||
cacheTimeout time.Duration
|
||||
@ -32,18 +32,17 @@ type Web struct {
|
||||
|
||||
|
||||
func (w *Web) SetUrl(u string) error {
|
||||
w.Url = SetUrl(u)
|
||||
// w.Error = w.Url.Error
|
||||
w.ServerUrl = SetUrl(u)
|
||||
return w.Error
|
||||
}
|
||||
|
||||
func (w *Web) AppendUrl(endpoint string) EndPointUrl {
|
||||
return w.Url.AppendPath(endpoint)
|
||||
return w.ServerUrl.AppendPath(endpoint)
|
||||
}
|
||||
|
||||
func (w *Web) Get(endpoint EndPoint) EndPoint {
|
||||
for range Only.Once {
|
||||
w.Error = w.Url.IsValid()
|
||||
w.Error = w.ServerUrl.IsValid()
|
||||
if w.Error != nil {
|
||||
w.Error = errors.New("Sungrow API EndPoint not yet implemented")
|
||||
fmt.Println(w.Error)
|
||||
@ -87,9 +86,8 @@ func (w *Web) Get(endpoint EndPoint) EndPoint {
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
if isCached {
|
||||
|
||||
// Do nothing.
|
||||
} else {
|
||||
w.Error = w.WebCacheWrite(endpoint, w.Body)
|
||||
if w.Error != nil {
|
||||
@ -123,7 +121,7 @@ func (w *Web) getApi(endpoint EndPoint) ([]byte, error) {
|
||||
break
|
||||
}
|
||||
|
||||
postUrl := w.Url.AppendPath(u.String()).String()
|
||||
postUrl := w.ServerUrl.AppendPath(u.String()).String()
|
||||
var j []byte
|
||||
j, w.Error = json.Marshal(request)
|
||||
if w.Error != nil {
|
||||
|
@ -2,6 +2,7 @@ package mmHa
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"strings"
|
||||
)
|
||||
@ -15,23 +16,6 @@ func (m *Mqtt) BinarySensorPublishConfig(config EntityConfig) error {
|
||||
break
|
||||
}
|
||||
|
||||
// LastReset := m.GetLastReset(config.UniqueId)
|
||||
// LastResetValueTemplate := ""
|
||||
// if LastReset != "" {
|
||||
// LastResetValueTemplate = "{{ value_json.last_reset | as_datetime() }}"
|
||||
// }
|
||||
|
||||
// device := m.Device
|
||||
// // device.Name = JoinStrings(m.Device.Name, config.ParentId)
|
||||
// device.Name = JoinStrings(m.Device.Name, config.ParentName) // , config.ValueName)
|
||||
// device.Connections = [][]string {
|
||||
// { m.Device.Name, JoinStringsForId(m.Device.Name, config.ParentName) },
|
||||
// { JoinStringsForId(m.Device.Name, config.ParentName), JoinStringsForId(m.Device.Name, config.ParentId) },
|
||||
// // { JoinStringsForId(m.Device.Name, config.ParentId), JoinStringsForId(m.Device.Name, config.ParentId, config.Name) },
|
||||
// }
|
||||
// // device.Identifiers = []string{ JoinStringsForId(m.Device.Name, config.ParentId, config.Name) }
|
||||
// device.Identifiers = []string{ JoinStringsForId(m.Device.Name, config.ParentId) }
|
||||
|
||||
ok, newDevice := m.NewDevice(config)
|
||||
if !ok {
|
||||
break
|
||||
@ -45,6 +29,7 @@ func (m *Mqtt) BinarySensorPublishConfig(config EntityConfig) error {
|
||||
Name: JoinStrings(m.DeviceName, config.Name),
|
||||
StateTopic: JoinStringsForTopic(m.binarySensorPrefix, id, "state"),
|
||||
StateClass: config.StateClass,
|
||||
ObjectId: id,
|
||||
UniqueId: id,
|
||||
UnitOfMeasurement: config.Units,
|
||||
DeviceClass: config.DeviceClass,
|
||||
@ -108,6 +93,9 @@ func (m *Mqtt) BinarySensorPublishValue(config EntityConfig) error {
|
||||
break
|
||||
}
|
||||
|
||||
if strings.Contains(tag, "GoSunGrow") {
|
||||
fmt.Println("")
|
||||
}
|
||||
payload := MqttState {
|
||||
LastReset: m.GetLastReset(config.UniqueId),
|
||||
Value: config.Value,
|
||||
|
@ -3,6 +3,7 @@ package mmHa
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"github.com/MickMake/GoUnify/cmdLog"
|
||||
)
|
||||
|
||||
|
||||
@ -46,6 +47,7 @@ func (m *Mqtt) NewDevice(config EntityConfig) (bool, Device) {
|
||||
for range Only.Once {
|
||||
var parent Device
|
||||
if parent, ok = m.MqttDevices[config.ParentName]; !ok {
|
||||
cmdLog.LogPrintDate("Unknown parentDevice: %s - will ignore.\n", config.ParentName)
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package mmHa
|
||||
|
||||
import (
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"encoding/json"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
)
|
||||
|
||||
|
||||
@ -25,6 +25,8 @@ func (m *Mqtt) PublishLightConfig(config EntityConfig) error {
|
||||
Device: newDevice,
|
||||
Name: JoinStrings(m.DeviceName, config.Name),
|
||||
StateTopic: JoinStringsForTopic(m.switchPrefix, id, "state"),
|
||||
UniqueId: id,
|
||||
ObjectId: id,
|
||||
|
||||
// StateClass: config.StateClass,
|
||||
// UniqueId: id,
|
||||
@ -42,7 +44,6 @@ func (m *Mqtt) PublishLightConfig(config EntityConfig) error {
|
||||
// Icon: config.Icon,
|
||||
|
||||
// StateClass: "measurement",
|
||||
// UniqueId: id,
|
||||
// UnitOfMeasurement: units,
|
||||
// DeviceClass: class,
|
||||
// Qos: 0,
|
||||
@ -139,6 +140,7 @@ type Light struct {
|
||||
MaxMireds int `json:"max_mireds,omitempty"`
|
||||
MinMireds int `json:"min_mireds,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ObjectId string `json:"object_id,omitempty" required:"false"`
|
||||
OnCommandType string `json:"on_command_type,omitempty"`
|
||||
Optimistic bool `json:"opt,omitempty"`
|
||||
PayloadAvailable string `json:"payload_available,omitempty"`
|
||||
@ -154,7 +156,7 @@ type Light struct {
|
||||
Schema string `json:"schema,omitempty"`
|
||||
StateTopic string `json:"state_topic,omitempty"`
|
||||
StateValueTemplate string `json:"state_value_template,omitempty"`
|
||||
UniqueID string `json:"unique_id,omitempty"`
|
||||
UniqueId string `json:"unique_id,omitempty" required:"false"`
|
||||
WhiteValueCommandTopic string `json:"white_value_command_topic,omitempty"`
|
||||
WhiteValueScale int `json:"white_value_scale,omitempty"`
|
||||
WhiteValueStateTopic string `json:"white_value_state_topic,omitempty"`
|
||||
|
103
mmHa/sensors.go
103
mmHa/sensors.go
@ -1,9 +1,9 @@
|
||||
package mmHa
|
||||
|
||||
import (
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -16,93 +16,6 @@ func (m *Mqtt) SensorPublishConfig(config EntityConfig) error {
|
||||
break
|
||||
}
|
||||
|
||||
// if config.LastReset == "" {
|
||||
// config.LastReset = m.GetLastReset(config.UniqueId)
|
||||
// }
|
||||
// if config.LastReset != "" {
|
||||
// if config.LastResetValueTemplate == "" {
|
||||
// config.LastResetValueTemplate = "{{ value_json.last_reset | as_datetime() }}"
|
||||
// }
|
||||
// // LastResetValueTemplate = "{{ value_json.last_reset | int | timestamp_local | as_datetime }}"
|
||||
// }
|
||||
|
||||
// switch config.Units {
|
||||
// case "MW":
|
||||
// fallthrough
|
||||
// case "kW":
|
||||
// fallthrough
|
||||
// case "W":
|
||||
// config.DeviceClass = "power"
|
||||
//
|
||||
// case "MWh":
|
||||
// fallthrough
|
||||
// case "kWh":
|
||||
// fallthrough
|
||||
// case "Wh":
|
||||
// config.DeviceClass = "energy"
|
||||
//
|
||||
// case "kvar":
|
||||
// config.DeviceClass = "reactive_power"
|
||||
//
|
||||
// case "Hz":
|
||||
// config.DeviceClass = "frequency"
|
||||
//
|
||||
// case "V":
|
||||
// config.DeviceClass = "voltage"
|
||||
//
|
||||
// case "A":
|
||||
// config.DeviceClass = "current"
|
||||
//
|
||||
// case "℃":
|
||||
// config.DeviceClass = "temperature"
|
||||
// // point.Unit = "C"
|
||||
//
|
||||
// case "℉":
|
||||
// config.DeviceClass = "temperature"
|
||||
// // point.Unit = "C"
|
||||
//
|
||||
// case "C":
|
||||
// config.DeviceClass = "temperature"
|
||||
// config.Units = "℃"
|
||||
//
|
||||
// case "%":
|
||||
// config.DeviceClass = "battery"
|
||||
//
|
||||
// default:
|
||||
// ValueTemplate = "{{ value_json.value }}"
|
||||
// }
|
||||
|
||||
// var ok bool
|
||||
// var device Device
|
||||
// if device, ok = m.Devices[config.ParentName]; !ok {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// newDevice := Device{
|
||||
// ConfigurationUrl: device.ConfigurationUrl,
|
||||
// Connections: [][]string {
|
||||
// { device.Name, JoinStringsForId(device.Name, config.ParentName) },
|
||||
// { JoinStringsForId(device.Name, config.ParentName), JoinStringsForId(device.Name, config.ParentId) },
|
||||
// },
|
||||
// Identifiers: []string{ JoinStringsForId(device.Name, config.ParentId) },
|
||||
// Manufacturer: device.Manufacturer,
|
||||
// Model: device.Model,
|
||||
// Name: JoinStrings(device.Name, config.ParentName),
|
||||
// SuggestedArea: device.SuggestedArea,
|
||||
// SwVersion: device.SwVersion,
|
||||
// ViaDevice: device.ViaDevice,
|
||||
// }
|
||||
|
||||
// // device.Name = JoinStrings(m.Device.Name, config.ParentId)
|
||||
// device.Name = JoinStrings(m.Device.Name, config.ParentName) // , config.ValueName)
|
||||
// device.Connections = [][]string {
|
||||
// { m.Device.Name, JoinStringsForId(m.Device.Name, config.ParentName) },
|
||||
// { JoinStringsForId(m.Device.Name, config.ParentName), JoinStringsForId(m.Device.Name, config.ParentId) },
|
||||
// // { JoinStringsForId(m.Device.Name, config.ParentId), JoinStringsForId(m.Device.Name, config.ParentId, config.Name) },
|
||||
// }
|
||||
// // device.Identifiers = []string{ JoinStringsForId(m.Device.Name, config.ParentId, config.Name) }
|
||||
// device.Identifiers = []string{ JoinStringsForId(m.Device.Name, config.ParentId) }
|
||||
|
||||
ok, newDevice := m.NewDevice(config)
|
||||
if !ok {
|
||||
break
|
||||
@ -116,6 +29,7 @@ func (m *Mqtt) SensorPublishConfig(config EntityConfig) error {
|
||||
Name: JoinStrings(m.DeviceName, config.Name),
|
||||
StateTopic: JoinStringsForTopic(m.sensorPrefix, id, "state"),
|
||||
StateClass: config.StateClass,
|
||||
ObjectId: id,
|
||||
UniqueId: id,
|
||||
UnitOfMeasurement: config.Units,
|
||||
DeviceClass: config.DeviceClass,
|
||||
@ -176,10 +90,19 @@ func (m *Mqtt) SensorPublishValue(config EntityConfig) error {
|
||||
break
|
||||
}
|
||||
|
||||
payload := MqttState{
|
||||
LastReset: m.GetLastReset(config.FullId),
|
||||
if strings.Contains(tag, "GoSunGrow") {
|
||||
fmt.Println("")
|
||||
}
|
||||
payload := MqttState {
|
||||
LastReset: config.LastReset, // m.GetLastReset(config.FullId),
|
||||
Value: config.Value,
|
||||
}
|
||||
if config.StateClass != "total" {
|
||||
payload = MqttState {
|
||||
Value: config.Value,
|
||||
}
|
||||
}
|
||||
fmt.Printf("\nValue: %v ", payload)
|
||||
t := m.client.Publish(tag, 0, true, payload.Json())
|
||||
if !t.WaitTimeout(m.Timeout) {
|
||||
m.err = t.Error()
|
||||
|
@ -470,9 +470,9 @@ type EntityConfig struct {
|
||||
ParentId string
|
||||
ParentName string
|
||||
|
||||
UniqueId string
|
||||
FullId string
|
||||
Units string
|
||||
UniqueId string
|
||||
FullId string
|
||||
Units string
|
||||
ValueName string
|
||||
DeviceClass string
|
||||
StateClass string
|
||||
@ -481,6 +481,7 @@ type EntityConfig struct {
|
||||
Value string
|
||||
ValueTemplate string
|
||||
|
||||
UpdateFreq string
|
||||
LastReset string
|
||||
LastResetValueTemplate string
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package mmHa
|
||||
|
||||
import (
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"encoding/json"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
)
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ func (m *Mqtt) SwitchPublishConfig(config EntityConfig) error {
|
||||
Name: JoinStrings(m.DeviceName, config.Name),
|
||||
StateTopic: JoinStringsForTopic(m.switchPrefix, id, "state"),
|
||||
CommandTopic: JoinStringsForTopic(m.switchPrefix, id, "cmd"),
|
||||
ObjectId: id,
|
||||
UniqueId: id,
|
||||
Qos: 0,
|
||||
Retain: true,
|
||||
@ -157,6 +158,7 @@ type Switch struct {
|
||||
JSONAttributesTemplate string `json:"json_attr_tpl,omitempty"`
|
||||
JSONAttributesTopic string `json:"json_attr_t,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ObjectId string `json:"object_id,omitempty" required:"false"`
|
||||
Optimistic bool `json:"opt,omitempty"`
|
||||
PayloadAvailable string `json:"pl_avail,omitempty"`
|
||||
PayloadNotAvailable string `json:"pl_not_avail,omitempty"`
|
||||
|
Loading…
x
Reference in New Issue
Block a user