v3.0.0-alpha - MQTT fixes (final)

This commit is contained in:
MickMake 2022-12-14 17:50:18 +11:00
parent c3cfd1cf8c
commit 6e1fb965d8
16 changed files with 503 additions and 223 deletions

51
.idea/workspace.xml generated
View File

@ -7,25 +7,20 @@
<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$/defaults/const.go" beforeDir="false" afterPath="$PROJECT_DIR$/defaults/const.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_show_point.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_show_point.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_show_psid.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_show_psid.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPlantReportPDFList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPlantReportPDFList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsDetail/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsDetail/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsDetailWithPsType/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsDetailWithPsType/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/powerDevicePointList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/powerDevicePointList/data.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/WebAppService/getDevicePointAttrs/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/WebAppService/getDevicePointAttrs/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/file.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/file.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/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/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$/iSolarCloud/highlevel_point.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/highlevel_point.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/highlevel_ps.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/highlevel_ps.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/mmHa/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" />
@ -223,7 +218,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/mmHa/binary_sensor.go</url>
<line>88</line>
<line>87</line>
<option name="timeStamp" value="4693" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -463,12 +458,12 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>547</line>
<line>566</line>
<option name="timeStamp" value="7893" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>525</line>
<line>544</line>
<option name="timeStamp" value="7902" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -568,7 +563,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go</url>
<line>415</line>
<line>434</line>
<option name="timeStamp" value="8082" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -616,11 +611,6 @@
<line>139</line>
<option name="timeStamp" value="8165" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<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>
@ -641,21 +631,16 @@
<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>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/WebAppService/getDevicePointAttrs/data.go</url>
<line>97</line>
<option name="timeStamp" value="8398" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
<breakpoint type="DlvErrorBreakpoint" />

View File

@ -1,6 +1,7 @@
package cmd
import (
"GoSungrow/iSolarCloud/WebAppService/getDevicePointAttrs"
"GoSungrow/iSolarCloud/api"
"GoSungrow/iSolarCloud/api/GoStruct/output"
"GoSungrow/mmHa"
@ -43,6 +44,7 @@ type CmdMqtt struct {
Client *mmHa.Mqtt
endpoints MqttEndPoints
points getDevicePointAttrs.PointsMap
}
func NewCmdMqtt() *CmdMqtt {
@ -242,6 +244,18 @@ func (c *CmdMqtt) MqttArgs(_ *cobra.Command, _ []string) error {
if c.Error != nil {
break
}
cmdLog.LogPrintDate("Caching Sungrow metadata...\n")
c.Error = c.GetEndPoints()
if c.Error != nil {
break
}
c.points, c.Error = cmds.Api.SunGrow.DevicePointAttrsMap(nil, "")
if c.Error != nil {
break
}
cmdLog.LogPrintDate("Cached %d Sungrow data points...\n", len(c.points))
}
return c.Error
@ -351,11 +365,6 @@ func (c *CmdMqtt) Cron() error {
break
}
c.Error = c.GetEndPoints()
if c.Error != nil {
break
}
if c.Client.IsFirstRun() {
c.Client.UnsetFirstRun()
} else {
@ -374,9 +383,6 @@ func (c *CmdMqtt) Cron() error {
break
}
// All := []string{ "queryDeviceList", "getPsList", "getPsDetailWithPsType", "getPsDetail", "getKpiInfo"}
// All := []string{ "queryDeviceList", "getPsList", "getPsDetailWithPsType", "getPsDetail", "getKpiInfo"} //, queryMutiPointDataList, getDevicePointMinuteDataList }
// All := []string{ "WebIscmAppService.getDeviceModel" }
data.SetEndpoints(c.endpoints.Names()...)
c.Error = data.GetData()
if c.Error != nil {
@ -418,6 +424,8 @@ func (c *CmdMqtt) Update(endpoint string, data api.DataMap, newDay bool) error {
continue
}
_ = c.UpdatePoint(r)
var id string
var name string
switch {
@ -431,7 +439,6 @@ func (c *CmdMqtt) Update(endpoint string, data api.DataMap, newDay bool) error {
id = r.EndPoint
name = r.EndPoint
}
// name = mmHa.JoinStringsForName(" - ", name)
if r.Point.Unit == "" {
r.Point.Unit = r.Point.ValueType
@ -465,15 +472,6 @@ func (c *CmdMqtt) Update(endpoint string, data api.DataMap, newDay bool) error {
// LastResetValueTemplate: "",
}
fmt.Println(re.UniqueId)
if strings.Contains(r.EndPoint, "p13121") {
fmt.Printf("")
}
if strings.Contains(r.EndPoint, "power_pv_to_grid") {
fmt.Printf("")
}
if re.Value == "--" {
re.Value = ""
}
@ -520,11 +518,21 @@ func (c *CmdMqtt) Update(endpoint string, data api.DataMap, newDay bool) error {
func (c *CmdMqtt) GetEndPoints() error {
for range Only.Once {
fn := filepath.Join(cmds.ConfigDir, "mqtt_endpoints.json")
if !output.FileExists(fn) {
c.Error = output.PlainFileWrite(fn, []byte(DefaultMqttFile), 0644)
if c.Error != nil {
break
}
}
c.Error = output.FileRead(fn, &c.endpoints)
if c.Error != nil {
break
}
// All := []string{ "queryDeviceList", "getPsList", "getPsDetailWithPsType", "getPsDetail", "getKpiInfo"}
// All := []string{ "queryDeviceList", "getPsList", "getPsDetailWithPsType", "getPsDetail", "getKpiInfo"} //, queryMutiPointDataList, getDevicePointMinuteDataList }
// All := []string{ "WebIscmAppService.getDeviceModel" }
for name := range c.endpoints {
c.Error = c.Client.SetDeviceConfig(
DefaultServiceName,
@ -543,6 +551,58 @@ func (c *CmdMqtt) GetEndPoints() error {
return c.Error
}
func (c *CmdMqtt) UpdatePoint(entry *api.DataEntry) error {
for range Only.Once {
if !c.points.Exists(entry.Point.Id) {
// fmt.Printf("entry.Point: %s - NOT FOUND\n", entry.Point.Id)
break
}
p := c.points.Get(entry.Point.Id)
if p == nil {
// fmt.Printf("entry.Point: %s - FOUND - EMPTY\n", entry.Point.Id)
break
}
// {
// fmt.Printf("entry.Point: %s - FOUND - %v\n", entry.Point.Id, p)
// // fmt.Printf("\tValue - Description:'-'\t\tUnit:'%s'\tGroupName:'-'\tValueType:'%s'\n",
// // r.Value.UnitValue, r.Point.ValueType)
// fmt.Printf("\tDescription:'%s'\tPointName:'%s' - SAME:%t\n",
// entry.Point.Description, entry.Current.DataStructure.PointName, entry.Current.DataStructure.PointName == entry.Point.Description)
// fmt.Printf("\tUnit:'%s'\tPointUnit:'%s' - SAME:%t\n",
// entry.Point.Unit, entry.Current.DataStructure.PointUnit, entry.Current.DataStructure.PointUnit == entry.Point.Unit)
// fmt.Printf("\tGroupName:'%s'\tPointGroupName:'%s' - SAME:%t\n",
// entry.Point.GroupName, entry.Current.DataStructure.PointGroupName, entry.Current.DataStructure.PointGroupName == entry.Point.GroupName)
// fmt.Printf("\tValueType:'%s'\tValueType:'%s' - SAME:%t\n",
// entry.Point.ValueType, entry.Current.DataStructure.ValueType, entry.Current.DataStructure.ValueType == entry.Point.ValueType)
// }
if (p.Name.String() != entry.Point.Description) && (p.Unit.String() != entry.Point.Unit) && (entry.Point.GroupName == "") {
// fmt.Printf("\nNOT SAME\n")
// fmt.Println("BEFORE:")
// fmt.Printf("\tName:'%s'\tDescription:'%s'\n", p.Name, entry.Point.Description)
// fmt.Printf("\tPointGroupId:'%s'\tGroupName:'%s'\n", p.PointGroupId, entry.Point.GroupName)
// fmt.Printf("\tUnitType:'%s'\tValueType:'%s'\n", p.UnitType, entry.Point.ValueType)
// fmt.Printf("\tUnit:'%s'\tUnit:'%s'\n", p.Unit, entry.Point.Unit)
entry.Point.Description = p.Name.String()
entry.Point.Unit = p.Unit.String()
entry.Point.GroupName = p.PointGroupName
entry.Point.ValueType = p.UnitType.String()
// fmt.Println("AFTER:")
// fmt.Printf("\tName:'%s'\tDescription:'%s'\n", p.Name, entry.Point.Description)
// fmt.Printf("\tPointGroupId:'%s'\tGroupName:'%s'\n", p.PointGroupId, entry.Point.GroupName)
// fmt.Printf("\tUnitType:'%s'\tValueType:'%s'\n", p.UnitType, entry.Point.ValueType)
// fmt.Printf("\tUnit:'%s'\tUnit:'%s'\n", p.Unit, entry.Point.Unit)
// fmt.Println("")
}
}
return c.Error
}
type MqttEndPoints map[string]MqttEndPoint
type MqttEndPoint struct {
@ -614,3 +674,30 @@ func (c *MqttEndPoints) IsOK(check *api.DataEntry) bool {
}
return yes
}
const DefaultMqttFile = `{
"queryDeviceList": {
"include": [
"virtual.*"
],
"exclude": [
"queryDeviceList.*.devices.*",
"queryDeviceList.*.device_types.*"
]
},
"getPsList": {
"include": [
"virtual.*"
],
"exclude": [
]
}
"getPsDetail": {
"include": [
"virtual.*"
],
"exclude": [
]
}
}
`

View File

@ -58,7 +58,7 @@ func (c *CmdShow) AttachPointPs(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcAttachPsPoints,
RunE: c.funcPsPoints,
Args: cobra.MinimumNArgs(0),
}
cmd.AddCommand(self)
@ -77,7 +77,7 @@ func (c *CmdShow) AttachPointPsTable(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcAttachPsData,
RunE: c.funcPsData,
Args: cobra.MinimumNArgs(0),
}
cmd.AddCommand(self)
@ -101,7 +101,7 @@ func (c *CmdShow) AttachPointPsGraph(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcAttachPsGraph,
RunE: c.funcPsGraph,
Args: cobra.MinimumNArgs(0),
}
cmd.AddCommand(self)

View File

@ -80,7 +80,7 @@ func (c *CmdShow) AttachPsIdList2(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcAttachPsIdList2,
RunE: c.funcPsIdList2,
Args: cobra.MinimumNArgs(0),
}
cmd.AddCommand(self)
@ -88,7 +88,7 @@ func (c *CmdShow) AttachPsIdList2(cmd *cobra.Command) *cobra.Command {
return cmd
}
func (c *CmdShow) funcAttachPsIdList2(_ *cobra.Command, args []string) error {
func (c *CmdShow) funcPsIdList2(_ *cobra.Command, args []string) error {
for range Only.Once {
pids := cmds.Api.SunGrow.SetPsIds(args...)
if c.Error != nil {
@ -110,7 +110,7 @@ func (c *CmdShow) AttachPsTree(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcAttachPsTree,
RunE: c.funcPsTree,
Args: cobra.MinimumNArgs(0),
}
cmd.AddCommand(self)
@ -118,7 +118,7 @@ func (c *CmdShow) AttachPsTree(cmd *cobra.Command) *cobra.Command {
return cmd
}
func (c *CmdShow) funcAttachPsTree(_ *cobra.Command, args []string) error {
func (c *CmdShow) funcPsTree(_ *cobra.Command, args []string) error {
for range Only.Once {
var pids iSolarCloud.PsTree
pids, c.Error = cmds.Api.SunGrow.PsTreeMenu(args...)
@ -141,7 +141,7 @@ func (c *CmdShow) AttachPsPoints(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcAttachPsPoints,
RunE: c.funcPsPoints,
Args: cobra.MinimumNArgs(0),
}
cmd.AddCommand(self)
@ -149,7 +149,7 @@ func (c *CmdShow) AttachPsPoints(cmd *cobra.Command) *cobra.Command {
return cmd
}
func (c *CmdShow) funcAttachPsPoints(_ *cobra.Command, args []string) error {
func (c *CmdShow) funcPsPoints(_ *cobra.Command, args []string) error {
for range Only.Once {
args = MinimumArraySize(2, args)
var points string
@ -173,7 +173,7 @@ func (c *CmdShow) AttachPsData(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcAttachPsData,
RunE: c.funcPsData,
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(self)
@ -181,7 +181,7 @@ func (c *CmdShow) AttachPsData(cmd *cobra.Command) *cobra.Command {
return cmd
}
func (c *CmdShow) funcAttachPsData(_ *cobra.Command, args []string) error {
func (c *CmdShow) funcPsData(_ *cobra.Command, args []string) error {
for range Only.Once {
cmds.Api.SunGrow.OutputType.SetTable()
args = MinimumArraySize(5, args)
@ -203,7 +203,7 @@ func (c *CmdShow) AttachPsGraph(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.funcAttachPsGraph,
RunE: c.funcPsGraph,
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(self)
@ -211,7 +211,7 @@ func (c *CmdShow) AttachPsGraph(cmd *cobra.Command) *cobra.Command {
return cmd
}
func (c *CmdShow) funcAttachPsGraph(_ *cobra.Command, args []string) error {
func (c *CmdShow) funcPsGraph(_ *cobra.Command, args []string) error {
for range Only.Once {
cmds.Api.SunGrow.OutputType.SetGraph()
args = MinimumArraySize(5, args)

View File

@ -3,8 +3,8 @@ package getPlantReportPDFList
import (
"GoSungrow/iSolarCloud/api"
"GoSungrow/iSolarCloud/api/GoStruct"
"GoSungrow/iSolarCloud/api/GoStruct/valueTypes"
"github.com/MickMake/GoUnify/Only"
"fmt"
)
@ -13,6 +13,7 @@ const Disabled = false
const EndPointName = "AppService.getPlantReportPDFList"
type RequestData struct {
PsId valueTypes.PsId `json:"ps_id" required:"true"`
}
func (rd RequestData) IsValid() error {
@ -24,9 +25,7 @@ func (rd RequestData) Help() string {
return ret
}
type ResultData struct {
// Dummy valueTypes.String `json:"dummy"`
}
func (e *ResultData) IsValid() error {
@ -34,31 +33,8 @@ func (e *ResultData) IsValid() error {
return err
}
//type DecodeResultData ResultData
//
//func (e *ResultData) UnmarshalJSON(data []byte) error {
// var err error
//
// for range Only.Once {
// if len(data) == 0 {
// break
// }
// var pd DecodeResultData
//
// // Store ResultData
// _ = json.Unmarshal(data, &pd)
// e.Dummy = pd.Dummy
// }
//
// return err
//}
func (e *EndPoint) GetData() api.DataMap {
entries := api.NewDataMap()
for range Only.Once {
entries.StructToDataMap(*e, "", GoStruct.EndPointPath{})
}
entries.StructToDataMap(*e, "", GoStruct.EndPointPath{})
return entries
}

View File

@ -179,7 +179,7 @@ type ResultData struct {
P83101MapVirgin valueTypes.UnitValue `json:"p83101_map_virgin" PointIgnore:"true"`
P83102Map valueTypes.UnitValue `json:"p83102_map" PointId:"p83102" PointName:"Energy Purchased" PointVirtual:"true"`
P83102MapVirgin valueTypes.UnitValue `json:"p83102_map_virgin" PointIgnore:"true"`
P83102Percent valueTypes.Float `json:"p83102_percent" PointId:"p83102_percent" PointName:"Energy Purchased Percent" PointVirtual:"true"`
P83102Percent valueTypes.Float `json:"p83102_percent" PointId:"p83102_percent" PointName:"Energy Purchased Percent" PointUnit:"%" PointVirtual:"true"`
P83105Map valueTypes.UnitValue `json:"p83105_map" PointId:"p83105" PointVirtual:"true"`
P83105MapVirgin valueTypes.UnitValue `json:"p83105_map_virgin" PointIgnore:"true"`
P83106Map valueTypes.UnitValue `json:"p83106_map" PointId:"p83106" PointVirtual:"true"`

View File

@ -34,11 +34,11 @@ type ResultData struct {
ConnectType valueTypes.Integer `json:"connect_type" PointId:"connect_type" PointUpdateFreq:"UpdateFreqBoot"`
CurrPower valueTypes.UnitValue `json:"curr_power" PointId:"curr_power" PointUpdateFreq:"UpdateFreqInstant"`
DesignCapacity valueTypes.UnitValue `json:"design_capacity" PointId:"design_capacity" PointUpdateFreq:"UpdateFreqBoot"`
EnergyScheme interface{} `json:"energy_scheme" PointId:"energy_scheme"`
EnergyScheme valueTypes.Generic `json:"energy_scheme" PointId:"energy_scheme"`
GcjLatitude valueTypes.Float `json:"gcj_latitude" PointId:"gcj_latitude" PointUpdateFreq:"UpdateFreqBoot"`
GcjLongitude valueTypes.Float `json:"gcj_longitude" PointId:"gcj_longitude" PointUpdateFreq:"UpdateFreqBoot"`
HasAmmeter valueTypes.Bool `json:"has_ammeter" PointId:"has_ammeter" PointUpdateFreq:"UpdateFreqBoot"`
HouseholdInverterData interface{} `json:"household_inverter_data" PointId:"household_inverter_data"`
HouseholdInverterData valueTypes.Generic `json:"household_inverter_data" PointId:"household_inverter_data"`
InstallerPsFaultStatus valueTypes.Integer `json:"installer_ps_fault_status" PointId:"installer_ps_fault_status" PointUpdateFreq:"UpdateFreqInstant"`
IsHaveEsInverter valueTypes.Bool `json:"is_have_es_inverter" PointId:"is_have_es_inverter" PointUpdateFreq:"UpdateFreqBoot"`
IsSingleInverter valueTypes.Bool `json:"is_single_inverter" PointId:"is_single_inverter" PointUpdateFreq:"UpdateFreqBoot"`
@ -54,7 +54,7 @@ type ResultData struct {
MonthEnergy valueTypes.UnitValue `json:"month_energy" PointId:"month_energy" PointUpdateFreq:"UpdateFreqMonth"`
MonthEnergyVirgin valueTypes.UnitValue `json:"month_energy_virgin" PointIgnore:"true"`
MonthIncome valueTypes.UnitValue `json:"month_income" PointId:"month_income" PointUpdateFreq:"UpdateFreqMonth"`
NegativeLoadMsg interface{} `json:"negative_load_msg" PointId:"negative_load_msg"`
NegativeLoadMsg valueTypes.Generic `json:"negative_load_msg" PointId:"negative_load_msg"`
OwnerPsFaultStatus valueTypes.Integer `json:"owner_ps_fault_status" PointId:"owner_ps_fault_status" PointUpdateFreq:"UpdateFreqInstant"`
P83081Map valueTypes.UnitValue `json:"p83081_map" PointId:"p83081" PointName:"Load Power" PointVirtual:"true" PointUpdateFreq:"UpdateFreq5Mins"`

View File

@ -5,7 +5,6 @@ import (
"GoSungrow/iSolarCloud/api/GoStruct"
"GoSungrow/iSolarCloud/api/GoStruct/valueTypes"
"fmt"
"github.com/MickMake/GoUnify/Only"
)
const Url = "/v1/reportService/powerDevicePointList"
@ -25,42 +24,31 @@ func (rd RequestData) Help() string {
}
type ResultData struct {
PageDataList []Point `json:"pageDataList" PointId:"points" PointArrayFlatten:"false" DataTable:"true"` // DataTableSortOn:"Id"`
CurrentPage valueTypes.Integer `json:"currentPage" PointIgnore:"true"`
PageDataList []struct {
CreateTime valueTypes.DateTime `json:"create_time" PointIgnore:"true" PointNameDateFormat:"2006-01-02 15:04:05"`
DeviceType valueTypes.Integer `json:"device_type"`
Id valueTypes.Integer `json:"id"`
Period valueTypes.Integer `json:"period"` // 0, 1, 2, 3, 4
PointId valueTypes.PointId `json:"point_id"`
PointName valueTypes.String `json:"point_name" PointIgnore:"true"` // Old name of point.
PointNameNew valueTypes.String `json:"point_name_new" PointId:"name"`
TypeName valueTypes.String `json:"type_name"`
} `json:"pageDataList" PointId:"points" PointArrayFlatten:"false" DataTable:"true"`
PageSize valueTypes.Integer `json:"pageSize" PointIgnore:"true"`
TotalCounts valueTypes.Integer `json:"totalCounts" PointId:"total_counts"`
TotalPages valueTypes.Integer `json:"totalPages" PointIgnore:"true"`
PageSize valueTypes.Integer `json:"pageSize" PointIgnore:"true"`
TotalCounts valueTypes.Integer `json:"totalCounts" PointId:"total_count"`
TotalPages valueTypes.Integer `json:"totalPages" PointIgnore:"true"`
}
type Point struct {
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
DeviceType valueTypes.Integer `json:"device_type"`
Id valueTypes.Integer `json:"id"`
Period valueTypes.Integer `json:"period"` // 0, 1, 2, 3, 4
PointId valueTypes.PointId `json:"point_id"`
PointName valueTypes.String `json:"point_name" PointIgnore:"true"` // Old name of point.
PointNameNew valueTypes.String `json:"point_name_new" PointId:"name"`
TypeName valueTypes.String `json:"type_name"`
}
func (e *ResultData) IsValid() error {
var err error
//switch {
//case e.Dummy == "":
// break
//default:
// err = errors.New(fmt.Sprintf("unknown error '%s'", e.Dummy))
//}
return err
}
func (e *EndPoint) GetData() api.DataMap {
entries := api.NewDataMap()
for range Only.Once {
// pkg := reflection.GetName("", *e)
// dt := valueTypes.NewDateTime(valueTypes.Now)
// name := pkg + "." + e.Request.PsId.String()
entries.StructToDataMap(*e, "", GoStruct.EndPointPath{})
}
entries.StructToDataMap(*e, "", GoStruct.EndPointPath{})
return entries
}

View File

@ -154,24 +154,24 @@ type PointStruct struct {
TimeStamp valueTypes.DateTime `json:"time_stamp" PointUpdateFreq:"UpdateFreq5Mins" PointNameDateFormat:"2006-01-02 15:04:05"`
PointId valueTypes.PointId `json:"point_id" PointUpdateFreq:"UpdateFreqBoot"`
PointGroupName valueTypes.String `json:"point_group_name" PointUpdateFreq:"UpdateFreqBoot"`
PointName valueTypes.String `json:"point_name" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
Value valueTypes.Float `json:"value" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUnitFrom:"Unit" PointVariableUnit:"true" PointUpdateFreq:"UpdateFreq5Mins"`
Unit valueTypes.String `json:"unit" PointUpdateFreq:"UpdateFreqBoot"`
PointSign valueTypes.String `json:"point_sign" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
Unit valueTypes.String `json:"unit" PointUpdateFreq:"UpdateFreqBoot"`
ValueDescription valueTypes.String `json:"value_description" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
OrderId valueTypes.Integer `json:"order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
PointGroupId valueTypes.Integer `json:"point_group_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
PointGroupName valueTypes.String `json:"point_group_name" PointUpdateFreq:"UpdateFreqBoot"`
Relate valueTypes.Integer `json:"relate" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
CodeId valueTypes.Integer `json:"code_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
CodeIdOrderId valueTypes.String `json:"code_id_order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
CodeName valueTypes.String `json:"code_name" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
DevPointLastUpdateTime valueTypes.DateTime `json:"dev_point_last_update_time" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreq5Mins" PointNameDateFormat:"2006-01-02 15:04:05"`
IsPlatformDefaultUnit valueTypes.Bool `json:"is_platform_default_unit" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
IsShow valueTypes.Bool `json:"is_show" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
OrderId valueTypes.Integer `json:"order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
OrderNum valueTypes.Integer `json:"order_num" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
PointGroupId valueTypes.Integer `json:"point_group_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
PointGroupIdOrderId valueTypes.Integer `json:"point_group_id_order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
Relate valueTypes.Integer `json:"relate" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
ValIsFixed valueTypes.Bool `json:"val_is_fixd" PointId:"value_is_fixed" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
ValidSize valueTypes.Integer `json:"valid_size" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
}
@ -252,7 +252,7 @@ func (e *EndPoint) GetData() api.DataMap {
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)
// fmt.Printf("%s.%s -> %s\n", epp, name, foo.DataStructure.PointDevice)
}
}
@ -505,6 +505,7 @@ func (e *EndPoint) SetPvPoints(epp GoStruct.EndPointPath, entries api.DataMap) {
two := pvToBatteryPower.Value.First().ValueFloat()
three := pvToGridPower.Value.First().ValueFloat()
pvToLoadPower.SetValue(one - two - three)
pvToLoadPower.SetValuePrecision(3)
pvToLoadPowerActive := entries.CopyPoint(pvToLoadPower, epp, "pv_to_load_power_active", "Pv To Load Power Active (Calc)")
_ = entries.MakeState(pvToLoadPowerActive)

View File

@ -4,6 +4,8 @@ import (
"GoSungrow/iSolarCloud/api"
"GoSungrow/iSolarCloud/api/GoStruct"
"GoSungrow/iSolarCloud/api/GoStruct/valueTypes"
"encoding/json"
"github.com/MickMake/GoUnify/Only"
"fmt"
)
@ -29,15 +31,35 @@ func (rd RequestData) Help() string {
type ResultData []Point
// type Points []Point
func (e *ResultData) IsValid() error {
var err error
return err
}
// powerDevicePointList
// ┏━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ Device Type ┃ Id ┃ Period ┃ Point Id ┃ Name ┃ Type Name ┃
// ┣━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ 11 ┃ 29 ┃ 1 ┃ p83001 ┃ AC Power Normalization (Inverter) ┃ Plant ┃
//
// ┏━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━┓
// ┃ Ps Id ┃ Device Type ┃ Channel Id ┃ Station Name ┃ Station Short Name ┃ Is Parent ┃ Device Model Id ┃ Device Name ┃ A Type ┃ Code Id ┃ C Type ┃ Id ┃ Node Key ┃ Name ┃ Target Unit ┃ Unit ┃ Unit Type ┃ Level ┃ Order Id ┃ Point Group Id ┃ Relate ┃
// ┣━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━┫
// ┃ 1171348 ┃ 11 ┃ 0 ┃ MickMake42 ┃ A2281658237 ┃ false ┃ 366316 ┃ Energy Storage System 02_01 ┃ 0 ┃ 0 ┃ 1 ┃ p83001 ┃ p83001 ┃ Inverter AC Power Normalization ┃ kW/kWp ┃ kW/kWp ┃ 43 ┃ 4 ┃ 10021 ┃ 9999 ┃ 0 ┃
type Point struct {
GoStruct.GoStructParent `json:"-" DataTable:"true" DataTableSortOn:"Id"`
// GoStruct.GoStruct `json:"-" PointIdFrom:"PsId" PointIdReplace:"false"`
PsId valueTypes.Integer `json:"psid" PointId:"ps_id"`
DeviceType valueTypes.Integer `json:"pid" PointId:"device_type"`
ChannelId valueTypes.Integer `json:"chnnlid" PointId:"channel_id"`
PsId valueTypes.PsId `json:"psid" PointId:"ps_id"`
DeviceType valueTypes.Integer `json:"pid" PointId:"device_type"`
ChannelId valueTypes.Integer `json:"chnnlid" PointId:"channel_id"`
Unit valueTypes.String `json:"unit"`
OrderId valueTypes.Integer `json:"orderid" PointId:"order_id"`
PointGroupId valueTypes.Integer `json:"point_group_id"`
Relate valueTypes.Integer `json:"relate"`
CodeId valueTypes.Integer `json:"code_id"`
StationName valueTypes.String `json:"stationname" PointId:"station_name"`
StationShortName valueTypes.String `json:"stationshortname" PointId:"station_short_name"`
@ -45,32 +67,255 @@ type Point struct {
DeviceModelId valueTypes.Integer `json:"device_model_id"`
DeviceName valueTypes.String `json:"devicename" PointId:"device_name"`
AType valueTypes.Integer `json:"atype" PointId:"a_type"`
CodeId valueTypes.Integer `json:"code_id"`
CType valueTypes.Integer `json:"ctype" PointId:"c_type"`
Id valueTypes.PointId `json:"id"`
NodeKey valueTypes.PointId `json:"nodekey" PointId:"node_key"`
Name valueTypes.String `json:"name"`
TargetUnit valueTypes.String `json:"target_unit"`
Unit valueTypes.String `json:"unit"`
UnitType valueTypes.Integer `json:"unit_type"`
Level valueTypes.Integer `json:"level"`
OrderId valueTypes.Integer `json:"orderid" PointId:"order_id"`
PointGroupId valueTypes.Integer `json:"point_group_id"`
Relate valueTypes.Integer `json:"relate"`
Id valueTypes.PointId `json:"id"`
NodeKey valueTypes.PointId `json:"nodekey" PointId:"node_key"`
Name valueTypes.String `json:"name"`
TargetUnit valueTypes.String `json:"target_unit"`
UnitType valueTypes.Integer `json:"unit_type"`
Level valueTypes.Integer `json:"level"`
// Added.
PointGroupName string `json:"point_group_name"`
UnitTypeName string `json:"unit_type_name"`
}
func (e *ResultData) IsValid() error {
func (p *Point) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
if len(data) == 0 {
break
}
type decode Point
var pd decode
// Store PointsData.Order
err = json.Unmarshal(data, &pd)
if err != nil {
fmt.Printf("getDevicePointAttrs[pd] - err:%s data: %s\n", err, data)
break
}
pd.PointGroupName = pointGroupNames.Get(pd.PointGroupId.String())
// pd.UnitTypeName = unitTypes.Get(pd.UnitType.String()) // Not working.
*p = Point(pd)
}
return err
}
type Points []Point
type PointsMap map[string]*Point
func (m *PointsMap) Exists(point string) bool {
if _, ok := (*m)[point]; ok {
return true
}
return false
}
func (m *PointsMap) Get(point string) *Point {
if m.Exists(point) {
return (*m)[point]
}
return nil
}
type UnitTypes map[string]string
var unitTypes = UnitTypes {
"": "Unknown", //
"NULL": "Unknown", //
"%": "Percent", // 10
"%RH": "Humidity", // 12
"A": "Current", //
"Ah": "Current Capacity", //
"mA": "Current", //
"Bar": "Pressure", //
"hPa": "Pressure", // 19
"Day": "Date/Time", // 15
"H": "Date/Time", // 15
"Hour": "Date/Time", // 15
"h": "Date/Time", // 15
"Year": "Date/Time", // 15
"Min": "Date/Time", // 15
"Mon": "Date/Time", // 15
"min": "Date/Time", // 15
"s": "Date/Time", // 15
"Hz": "Frequency", //
"KV": "Voltage", //
"kV ": "Voltage", //
"kV": "Voltage", //
"V": "Voltage", //
"mV": "Voltage", //
"MAh": "Energy", // 13
"MWh": "Energy", //
"MWp": "Energy", //
"Wh": "Energy", //
"kWh": "Energy", //
"MW": "Power", //
"kW": "Power", // 0 / 21
"W": "Power", //
"Mvar": "Reactive Power", //
"kVar": "Reactive Power", //
"kvar": "Reactive Power", //
"Var": "Reactive Power", //
"VA": "Apparent Power", // 21
"kVA": "Apparent Power", // 21
"kW/kWp": "Power Normalization", //
"kVarh": "Reactive Electricity", //
"kvarh": "Reactive Electricity", //
"PCS": "PCS", //
"V/mA": "Output", // 0
"W/㎡": "Irradiation", //
"Wh/㎡": "Irradiation", // 1
"dec": "dec", //
"g": "Weight", // 17
"kg": "Weight", // 17
"kΩ": "Resistance", //
"m/s": "Speed", //
"r/min": "Speed", //
"mm": "Length", //
"°": "Angle", //
"℃": "Temperature", // 2
"时": "Date/Time", // 15
"分": "Date/Time", // Operation Minutes
"台": "Count", // Number of Online PCSs
"排": "Count", //
"次": "Count", // Discharging Count
}
// 21 = kW
// 22 = kVarh
// 22 = kvarh
// 23 = kΩ
// 25 = m/s
// 28 = mm
// 3 = kVA
// 3 = kW
// 3 = kWh
// 31 = mV
// 32 = Mvar
// 33 =
// 33 = PCS
// 33 = 分
// 33 = 台
// 33 = 排
// 33 = 次
// 37 = KV
// 37 = kV
// 39 = VA
// 4 =
// 4 = V
// 40 = W/㎡
// 43 = kW/kWp
// 44 = °
// 5 = A
// 6 = Hz
// 7 = kWh
// 8 = kvar
// 999 =
// 999 = %
// 999 = %RH
// 999 = A
// 999 = Ah
// 999 = Bar
// 999 = Hz
// 999 = MAh
// 999 = MW
// 999 = MWh
// 999 = MWp
// 999 = Mvar
// 999 = NULL
// 999 = V
// 999 = VA
// 999 = Var
// 999 = W
// 999 = Wh
// 999 = dec
// 999 = h
// 999 = kV
// 999 = kV
// 999 = kVA
// 999 = kVar
// 999 = kW
// 999 = kWh
// 999 = kvar
// 999 = kΩ
// 999 = mA
// 999 = mV
// 999 = min
// 999 = r/min
// 999 = ℃
func (ut *UnitTypes) Get(name string) string {
if n, ok := (*ut)[name]; ok {
return n
}
return name
}
type PointGroupNames map[string]string
var pointGroupNames = PointGroupNames{
"1": "1",
"2": "2",
"7": "7",
"9": "Overview",
"10": "Battery Information",
"11": "11",
"12": "Grid Information",
"13": "Load Information",
"14": "14",
"16": "MPPT Information",
"17": "17",
"19": "19",
"20": "20",
"21": "21",
"9999": "Other Information",
}
func (pgn *PointGroupNames) Get(name string) string {
if n, ok := (*pgn)[name]; ok {
return n
}
return name
}
func (e *EndPoint) GetData() api.DataMap {
entries := api.NewDataMap()
entries.StructToDataMap(*e, e.Request.PsId2.String(), GoStruct.NewEndPointPath(e.Request.PsId2.String()))
return entries
}
func (e *EndPoint) Points() []Point {
return e.Response.ResultData
func (e *EndPoint) Points() Points {
return Points(e.Response.ResultData)
}

View File

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

View File

@ -258,8 +258,8 @@ func (sg *SunGrow) GetAllPointsData(psIds ...string) error {
// DevicePointAttrs - Return all points associated with psIds and device_type filter.
func (sg *SunGrow) DevicePointAttrs(psIds []string, deviceType string) ([]getDevicePointAttrs.Point, error) {
var points []getDevicePointAttrs.Point
func (sg *SunGrow) DevicePointAttrs(psIds []string, deviceType string) (getDevicePointAttrs.Points, error) {
var points getDevicePointAttrs.Points
for range Only.Once {
var pids valueTypes.PsIds
@ -269,7 +269,7 @@ func (sg *SunGrow) DevicePointAttrs(psIds []string, deviceType string) ([]getDev
}
for _, pid := range pids {
var p []getDevicePointAttrs.Point
var p getDevicePointAttrs.Points
p, sg.Error = sg.GetDevicePointAttrs(pid)
if sg.Error != nil {
break
@ -303,9 +303,28 @@ func (sg *SunGrow) DevicePointAttrs(psIds []string, deviceType string) ([]getDev
return points, sg.Error
}
// DevicePointAttrsMap - Return all points associated with psIds and device_type filter.
func (sg *SunGrow) DevicePointAttrsMap(psIds []string, deviceType string) (getDevicePointAttrs.PointsMap, error) {
points := make(getDevicePointAttrs.PointsMap)
for range Only.Once {
var pa getDevicePointAttrs.Points
pa, sg.Error = sg.DevicePointAttrs(psIds, deviceType)
if sg.Error != nil {
break
}
for index := range pa {
points[pa[index].Id.String()] = &pa[index]
}
}
return points, sg.Error
}
// GetDevicePointAttrs - WebAppService.getDevicePointAttrs Uuid: PsId: DeviceType
func (sg *SunGrow) GetDevicePointAttrs(psId valueTypes.PsId) ([]getDevicePointAttrs.Point, error) {
var ret []getDevicePointAttrs.Point
func (sg *SunGrow) GetDevicePointAttrs(psId valueTypes.PsId) (getDevicePointAttrs.Points, error) {
var ret getDevicePointAttrs.Points
for range Only.Once {
var tree PsTree

View File

@ -86,7 +86,7 @@ func (sg *SunGrow) PsPoints(psIds []string, deviceType string) (string, error) {
var ret string
for range Only.Once {
var points []getDevicePointAttrs.Point
var points getDevicePointAttrs.Points
points, sg.Error = sg.DevicePointAttrs(psIds, deviceType)
if sg.Error != nil {
break
@ -184,7 +184,7 @@ func (sg *SunGrow) PsPointsData(psIds []string, deviceType string, startDate str
}
_, _ = fmt.Fprintf(os.Stderr, "Found ps_keys: %s\n", pskeys)
var points []getDevicePointAttrs.Point
var points getDevicePointAttrs.Points
points, sg.Error = sg.DevicePointAttrs(psIds, deviceType)
if sg.Error != nil {
break

View File

@ -2,7 +2,6 @@ package mmHa
import (
"encoding/json"
"fmt"
"github.com/MickMake/GoUnify/Only"
"strings"
)
@ -93,9 +92,6 @@ 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,

View File

@ -90,9 +90,6 @@ func (m *Mqtt) SensorPublishValue(config EntityConfig) error {
break
}
if strings.Contains(tag, "GoSunGrow") {
fmt.Println("")
}
payload := MqttState {
LastReset: config.LastReset, // m.GetLastReset(config.FullId),
Value: config.Value,
@ -102,7 +99,6 @@ func (m *Mqtt) SensorPublishValue(config EntityConfig) error {
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()

View File

@ -48,6 +48,7 @@ type Mqtt struct {
err error
}
func New(req Mqtt) *Mqtt {
var ret Mqtt
@ -221,11 +222,6 @@ func (m *Mqtt) Disconnect() error {
return m.err
}
// const ServiceBaseName = "GoSungrow"
// const ServiceBaseUniqueId = ServiceBaseName + "_Service"
// const ServiceBaseTopic = "homeassistant/sensor/" + ServiceBaseName
// const SensorBaseTopic = "homeassistant/sensor/" + ServiceBaseName
func (m *Mqtt) createClientOptions() error {
for range Only.Once {
m.clientOptions = mqtt.NewClientOptions()
@ -268,25 +264,6 @@ func (m *Mqtt) Publish(topic string, qos byte, retained bool, payload interface{
return m.err
}
// func (m *Mqtt) PublishConfig(config EntityConfig) error {
// // func (m *Mqtt) PublishConfig(t string, id string, name string, subName string, units string, valueName string, class string) error {
// switch config.Type {
// // case "sensor":
// // m.err = m.PublishSensorConfig(id, name, subName, units, valueName, class)
// case "binary_sensor":
// m.err = m.PublishBinarySensorConfig(config) // (id, name, subName, units, valueName, class)
// // case "lights":
// // m.err = m.PublishLightConfig(id, name, subName, units, valueName, class)
// // case "switch":
// // m.err = m.PublishSwitchConfig(id, name, subName, units, valueName, class)
// // default:
// // m.err = m.PublishSensorConfig(config)
// }
//
// return m.err
// }
func (m *Mqtt) PublishState(Type string, subtopic string, payload interface{}) error {
for range Only.Once {
// topic = JoinStringsForId(m.EntityPrefix, m.Device.Name, topic)
@ -370,23 +347,6 @@ func (m *Mqtt) PublishValue(Type string, subtopic string, value string) error {
return m.err
}
// func (m *Mqtt) PublishValue(t string, topic string, value string) error {
// switch t {
// case "sensor":
// m.err = m.PublishSensorValue(topic, value)
// case "binary_sensor":
// m.err = m.PublishBinarySensorState(topic, value)
// case "lights":
// m.err = m.PublishLightState(topic, value)
// case "switch":
// m.err = m.PublishSwitchState(topic, value)
// default:
// m.err = m.PublishSensorState(topic, value)
// }
//
// return m.err
// }
func (m *Mqtt) SetDeviceConfig(swname string, parentId string, id string, name string, model string, vendor string, area string) error {
for range Only.Once {
// id = JoinStringsForId(m.EntityPrefix, id)
@ -415,6 +375,23 @@ func (m *Mqtt) SetDeviceConfig(swname string, parentId string, id string, name s
return m.err
}
func (m *Mqtt) GetLastReset(pointType string) string {
var ret string
for range Only.Once {
pt := api.GetDevicePoint(pointType)
if !pt.Valid {
break
}
if pt.UpdateFreq == "" {
break
}
ret = pt.WhenReset()
}
return ret
}
type MqttState struct {
LastReset string `json:"last_reset,omitempty"`
@ -444,24 +421,6 @@ type Availability struct {
type SensorState string
func (m *Mqtt) GetLastReset(pointType string) string {
var ret string
for range Only.Once {
pt := api.GetDevicePoint(pointType)
if !pt.Valid {
break
}
if pt.UpdateFreq == "" {
break
}
ret = pt.WhenReset()
}
return ret
}
type EntityConfig struct {
// Type string
Name string
@ -558,7 +517,6 @@ func (config *EntityConfig) IsLight() bool {
return ok
}
func (config *EntityConfig) FixConfig() {
for range Only.Once {