v2.3.1 - Bug fixes.

This commit is contained in:
MickMake 2022-10-11 17:26:26 +11:00
parent fa85548f5d
commit bc25920a27
21 changed files with 999 additions and 590 deletions

255
.idea/workspace.xml generated
View File

@ -6,62 +6,26 @@
<component name="ChangeListManager">
<list default="true" id="76adadc9-ae71-42a6-82a1-66dbc8ecb14c" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/findPsType/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/findPsType/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getAreaList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getAreaList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_info.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_info.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/cmd_mqtt.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/cmd_mqtt.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cmd/commands.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/commands.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getDeviceList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getDeviceList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getDeviceModelInfoList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getDeviceModelInfoList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getDeviceTypeInfoList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getDeviceTypeInfoList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getDeviceTypeList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getDeviceTypeList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getFaultMsgListWithYYYYMM/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getFaultMsgListWithYYYYMM/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getIncomeSettingInfos/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getIncomeSettingInfos/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getModuleLogTaskList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getModuleLogTaskList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getOSSConfig/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getOSSConfig/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getOrgListByName/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getOrgListByName/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getOrgListForUser/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getOrgListForUser/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerChargeSettingInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerChargeSettingInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationBasicInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationBasicInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationForHousehold/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationForHousehold/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStatistics/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStatistics/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationData/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationData/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/getPsHealthState/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsHealthState/data.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/AppService/getPsListByName/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsListByName/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsListStaticData/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsListStaticData/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsReport/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsReport/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsUser/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsUser/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsWeatherList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsWeatherList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getRegionalTree/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getRegionalTree/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getRemoteUpgradeDeviceList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getRemoteUpgradeDeviceList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getReportData/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getReportData/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getReportEmailConfigInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getReportEmailConfigInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getSerialNum/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getSerialNum/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getStationInfoSql/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getStationInfoSql/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getSysMsg/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getSysMsg/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getTemplateList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getTemplateList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getUpTimePoint/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getUpTimePoint/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getUserPsOrderList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getUserPsOrderList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/listOssFiles/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/listOssFiles/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/login/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/login/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/psForcastInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/psForcastInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceInfoForApp/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceInfoForApp/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/AppService/queryDeviceListForApp/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceListForApp/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryMutiPointDataList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryMutiPointDataList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryPowerStationInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryPowerStationInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryPsProfit/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryPsProfit/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryUnitList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryUnitList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/reportList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/reportList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/WebAppService/getDeviceUuid/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/WebAppService/getDeviceUuid/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/WebAppService/showPSView/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/WebAppService/showPSView/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/datetime.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/datetime.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/types.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/types.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/highlevel.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/highlevel.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/mmHa/binary_sensor.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/binary_sensor.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/mmHa/config.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/config.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/mmHa/const.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/const.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/mmHa/funcs.go" beforeDir="false" afterPath="$PROJECT_DIR$/mmHa/funcs.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" />
@ -132,6 +96,7 @@
<configuration name="GoSungrow" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="GoSungrow" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="data get stats" />
<kind value="PACKAGE" />
<package value="GoSungrow" />
<directory value="$PROJECT_DIR$" />
@ -177,7 +142,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go</url>
<line>209</line>
<line>210</line>
<option name="timeStamp" value="202" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -207,12 +172,12 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>311</line>
<line>312</line>
<option name="timeStamp" value="437" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>310</line>
<line>311</line>
<option name="timeStamp" value="446" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -220,41 +185,6 @@
<line>142</line>
<option name="timeStamp" value="479" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/mmHa/struct.go</url>
<line>395</line>
<option name="timeStamp" value="622" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>342</line>
<option name="timeStamp" value="623" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>347</line>
<option name="timeStamp" value="624" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>348</line>
<option name="timeStamp" value="625" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>343</line>
<option name="timeStamp" value="660" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>352</line>
<option name="timeStamp" value="668" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>448</line>
<option name="timeStamp" value="697" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/apiReflect/reflect.go</url>
<line>635</line>
@ -267,7 +197,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>538</line>
<line>569</line>
<option name="timeStamp" value="775" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -310,21 +240,11 @@
<line>95</line>
<option name="timeStamp" value="868" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>154</line>
<option name="timeStamp" value="873" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>190</line>
<option name="timeStamp" value="881" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>1039</line>
<option name="timeStamp" value="883" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>288</line>
@ -357,19 +277,9 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>1083</line>
<line>1081</line>
<option name="timeStamp" value="906" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>1100</line>
<option name="timeStamp" value="907" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>1129</line>
<option name="timeStamp" value="908" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>84</line>
@ -377,17 +287,17 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>707</line>
<line>708</line>
<option name="timeStamp" value="914" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>696</line>
<line>697</line>
<option name="timeStamp" value="915" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>731</line>
<line>729</line>
<option name="timeStamp" value="917" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -412,82 +322,67 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>959</line>
<line>957</line>
<option name="timeStamp" value="967" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>956</line>
<line>954</line>
<option name="timeStamp" value="970" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>766</line>
<line>799</line>
<option name="timeStamp" value="972" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>715</line>
<line>748</line>
<option name="timeStamp" value="1020" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>413</line>
<option name="timeStamp" value="1024" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>372</line>
<option name="timeStamp" value="1025" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>941</line>
<line>987</line>
<option name="timeStamp" value="1091" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>848</line>
<line>890</line>
<option name="timeStamp" value="1184" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>871</line>
<line>914</line>
<option name="timeStamp" value="1185" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>897</line>
<line>941</line>
<option name="timeStamp" value="1186" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>925</line>
<line>970</line>
<option name="timeStamp" value="1187" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>648</line>
<line>680</line>
<option name="timeStamp" value="1190" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>227</line>
<option name="timeStamp" value="1200" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>464</line>
<line>491</line>
<option name="timeStamp" value="1201" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>924</line>
<line>922</line>
<option name="timeStamp" value="1216" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/highlevel.go</url>
<line>905</line>
<line>903</line>
<option name="timeStamp" value="1237" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -520,56 +415,56 @@
<line>300</line>
<option name="timeStamp" value="1355" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go</url>
<line>247</line>
<option name="timeStamp" value="1371" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go</url>
<line>240</line>
<option name="timeStamp" value="1373" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go</url>
<line>339</line>
<option name="timeStamp" value="1379" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go</url>
<line>417</line>
<option name="timeStamp" value="1380" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>693</line>
<option name="timeStamp" value="1393" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go</url>
<line>527</line>
<option name="timeStamp" value="1394" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>797</line>
<option name="timeStamp" value="1395" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_api.go</url>
<line>411</line>
<option name="timeStamp" value="1401" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/struct.go</url>
<line>123</line>
<option name="timeStamp" value="1402" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go</url>
<line>374</line>
<option name="timeStamp" value="1411" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/mmHa/config.go</url>
<line>48</line>
<option name="timeStamp" value="1488" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>364</line>
<option name="timeStamp" value="1493" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>532</line>
<option name="timeStamp" value="1498" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>469</line>
<option name="timeStamp" value="1500" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>492</line>
<option name="timeStamp" value="1508" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/cmd/cmd_mqtt.go</url>
<line>528</line>
<option name="timeStamp" value="1509" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>98</line>
<option name="timeStamp" value="1543" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go</url>
<line>248</line>
<option name="timeStamp" value="1549" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<watches-manager>

View File

@ -364,7 +364,7 @@ func (c *CmdInfo) AttachCmdInfoDevices(cmd *cobra.Command) *cobra.Command {
if err != nil {
return err
}
return cmds.Api.SunGrow.GetDevices(pids...)
return cmds.Api.SunGrow.GetDeviceList(pids...)
},
Args: cobra.MinimumNArgs(0),
}
@ -397,7 +397,7 @@ func (c *CmdInfo) AttachCmdInfoDeviceModels(cmd *cobra.Command) *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
_ = cmds.SetOutputType(cmd)
return cmds.Api.SunGrow.GetDeviceModels()
return cmds.Api.SunGrow.GetDeviceModelInfoList()
},
Args: cobra.MinimumNArgs(0),
}

View File

@ -152,29 +152,10 @@ func (c *CmdMqtt) AttachFlags(cmd *cobra.Command, viper *viper.Viper) {
func (ca *Cmds) MqttArgs(cmd *cobra.Command, args []string) error {
for range Only.Once {
cmdLog.LogPrintDate("Connecting to SunGrow...\n")
var id api.Integer
id, ca.Error = ca.Api.SunGrow.GetPsId()
if ca.Error != nil {
break
}
var model []string
model, ca.Error = ca.Api.SunGrow.GetPsModel()
if ca.Error != nil {
break
}
var serial []string
serial, ca.Error = ca.Api.SunGrow.GetPsSerial()
if ca.Error != nil {
break
}
cmdLog.LogPrintDate("Found SunGrow device %s id:%d serial:%s\n", model, id, serial)
cmdLog.LogPrintDate("Connecting to MQTT HASSIO Service...\n")
ca.Mqtt.Mqtt = mmHa.New(mmHa.Mqtt {
ClientId: "GoSunGrow",
EntityPrefix: "GoSungrow",
Username: ca.Mqtt.MqttUsername,
Password: ca.Mqtt.MqttPassword,
Host: ca.Mqtt.MqttHost,
@ -185,11 +166,47 @@ func (ca *Cmds) MqttArgs(cmd *cobra.Command, args []string) error {
break
}
// ca.Error = ca.Mqtt.Mqtt.SetDeviceConfig("GoSunGrow", strconv.FormatInt(id, 10), "GoSungrow", model[0], "Sungrow", "Roof")
ca.Error = ca.Mqtt.Mqtt.SetDeviceConfig("GoSunGrow", id.String(), "GoSungrow", model[0], "Sungrow", "Roof")
cmdLog.LogPrintDate("Connecting to SunGrow...\n")
ca.Mqtt.Mqtt.SungrowDevices, ca.Error = ca.Api.SunGrow.GetDevices(true)
if ca.Error != nil {
break
}
cmdLog.LogPrintDate("Found SunGrow %d devices\n", len(ca.Mqtt.Mqtt.SungrowDevices))
ca.Mqtt.Mqtt.DeviceName = "GoSungrow"
ca.Error = ca.Mqtt.Mqtt.SetDeviceConfig(
ca.Mqtt.Mqtt.DeviceName,
ca.Mqtt.Mqtt.DeviceName,
"virtual",
"virtual",
"",
"",
"Roof",
)
if ca.Error != nil {
break
}
for _, psId := range ca.Mqtt.Mqtt.SungrowDevices {
// ca.Error = ca.Mqtt.Mqtt.SetDeviceConfig("GoSunGrow", strconv.FormatInt(id, 10), "GoSungrow", model[0], "Sungrow", "Roof")
parent := psId.PsId.String()
if parent == psId.PsKey.Value() {
parent = ca.Mqtt.Mqtt.DeviceName
}
ca.Error = ca.Mqtt.Mqtt.SetDeviceConfig(
"GoSungrow",
parent,
psId.PsKey.Value(),
psId.DeviceName.Value(),
psId.DeviceModel.Value(),
psId.Vendor.Value(),
"Roof",
)
if ca.Error != nil {
break
}
ca.Mqtt.Mqtt.SungrowPsIds[psId.PsId] = true
}
ca.Error = ca.Mqtt.Mqtt.Connect()
if ca.Error != nil {
@ -259,22 +276,6 @@ func (ca *Cmds) CmdMqttRun(_ *cobra.Command, _ []string) error {
if ca.Error != nil {
break
}
// ep = c.Api.SunGrow.QueryDevice(psId)
// if ep.IsError() {
// c.Error = ep.GetError()
// break
// }
//
// data = ep.GetData()
// for _, r := range data.Entries {
// // fmt.Printf("%s ", r.PointId)
// c.Error = foo.SensorPublishState(r.PointId, r.Value)
// if err != nil {
// break
// }
// }
// // fmt.Println()
}
}
@ -340,14 +341,19 @@ func (ca *Cmds) MqttCron() error {
newDay = true
}
ca.Error = ca.Update1(newDay)
if ca.Error != nil {
break
}
for psId, ok := range ca.Mqtt.Mqtt.SungrowPsIds {
if !ok {
continue
}
ca.Error = ca.Update1(psId, newDay)
if ca.Error != nil {
break
}
ca.Error = ca.Update2(newDay)
if ca.Error != nil {
break
ca.Error = ca.Update2(psId, newDay)
if ca.Error != nil {
break
}
}
ca.Mqtt.Mqtt.LastRefresh = time.Now()
@ -359,10 +365,10 @@ func (ca *Cmds) MqttCron() error {
return ca.Error
}
func (ca *Cmds) Update1(newDay bool) error {
func (ca *Cmds) Update1(psId api.Integer, newDay bool) error {
for range Only.Once {
// Also getPowerStatistics, getHouseholdStoragePsReport, getPsList, getUpTimePoint,
ep := ca.Api.SunGrow.QueryDevice(ca.Mqtt.Mqtt.PsId)
ep := ca.Api.SunGrow.QueryDevice(psId)
if ep.IsError() {
ca.Error = ep.GetError()
break
@ -372,14 +378,22 @@ func (ca *Cmds) Update1(newDay bool) error {
if newDay {
cmdLog.LogPrintDate("New day: Configuring %d entries in HASSIO.\n", len(data.DataPoints))
for _, o := range data.Order {
fmt.Printf("C")
entries := data.DataPoints[o]
r := entries.GetEntry(api.LastEntry) // Gets the last entry
re := mmHa.EntityConfig{
Name: string(r.Point.Id), // PointName,
// if !r.Point.Valid {
// fmt.Printf("\nInvalid: %v\n", r)
// continue
// }
if r.Point.Id == "device_status" {
fmt.Sprintf("")
}
fmt.Printf("C")
re := mmHa.EntityConfig {
Name: r.Point.Name, // PointName,
SubName: "",
ParentId: r.EndPoint,
ParentName: "",
ParentName: r.Parent.Key,
UniqueId: string(r.Point.Id),
FullId: string(r.FullId), // WAS r.Point.FullId
Units: r.Point.Unit,
@ -394,10 +408,6 @@ func (ca *Cmds) Update1(newDay bool) error {
// LastResetValueTemplate: "",
}
// if re.LastResetValueTemplate != "" {
// fmt.Printf("HEY\n")
// }
ca.Error = ca.Mqtt.Mqtt.BinarySensorPublishConfig(re)
if ca.Error != nil {
break
@ -415,9 +425,17 @@ func (ca *Cmds) Update1(newDay bool) error {
for _, o := range data.Order {
entries := data.DataPoints[o]
r := entries.GetEntry(api.LastEntry) // Gets the last entry
if r.Point.Id == "device_status" {
fmt.Sprintf("")
}
if !r.Point.Valid {
fmt.Printf("\nInvalid: %v\n", r)
continue
}
fmt.Printf("U")
re := mmHa.EntityConfig{
Name: string(r.Point.Id), // PointName,
Name: r.Point.Name, // PointName,
SubName: "",
ParentId: r.EndPoint,
ParentName: "",
@ -452,10 +470,10 @@ func (ca *Cmds) Update1(newDay bool) error {
return ca.Error
}
func (ca *Cmds) Update2(newDay bool) error {
func (ca *Cmds) Update2(psId api.Integer, newDay bool) error {
for range Only.Once {
// Also getPowerStatistics, getHouseholdStoragePsReport, getPsList, getUpTimePoint,
ep := ca.Api.SunGrow.QueryPs(ca.Mqtt.Mqtt.PsId)
ep := ca.Api.SunGrow.QueryPs(psId)
if ep.IsError() {
ca.Error = ep.GetError()
break
@ -467,19 +485,24 @@ func (ca *Cmds) Update2(newDay bool) error {
for _, o := range data.Order {
entries := data.DataPoints[o]
r := entries.GetEntry(api.LastEntry) // Gets the last entry
// if !r.Point.Valid {
// fmt.Printf("\nInvalid: %v\n", r)
// continue
// }
if r.Point.Id == "device_status" {
fmt.Sprintf("")
}
fmt.Printf("C")
re := mmHa.EntityConfig {
Name: string(r.Point.Id), // PointName,
Name: r.Point.Name, // PointName,
SubName: "",
ParentId: r.EndPoint,
ParentName: "",
ParentName: r.Parent.Key,
UniqueId: string(r.Point.Id),
// UniqueId: r.Id,
FullId: string(r.FullId), // WAS r.Point.FullId
// FullName: r.Point.Name,
Units: r.Point.Unit,
ValueName: r.Point.Name,
// ValueName: r.Id,
DeviceClass: "",
StateClass: r.Point.Type,
Value: r.Value,
@ -502,9 +525,17 @@ func (ca *Cmds) Update2(newDay bool) error {
for _, o := range data.Order {
entries := data.DataPoints[o]
r := entries.GetEntry(api.LastEntry) // Gets the last entry
if r.Point.Id == "device_status" {
fmt.Sprintf("")
}
if !r.Point.Valid {
fmt.Printf("\nInvalid: %v\n", r)
continue
}
fmt.Printf("U")
re := mmHa.EntityConfig {
Name: string(r.Point.Id), // PointName,
Name: r.Point.Name, // PointName,
SubName: "",
ParentId: r.EndPoint,
ParentName: "",

View File

@ -78,16 +78,7 @@ func init() {
cmds.Mqtt = NewCmdMqtt()
cmds.Mqtt.AttachCommand(cmdRoot)
// cmds.Git = cmdGit.NewCmdGit()
// cmds.Git.AttachCommands(cmdRoot)
// cmds.Git.AttachFlags(cmdRoot, cmds.Unify.GetViper())
// _ = cmds.Git.SetDefaultEntities(defaults.DefaultAreas...)
//
// cmds.Google = cmdGoogle.NewCmdGoogle()
// cmds.Google.AttachCommands(cmdRoot)
//
// cmds.AttachFlags(cmdRoot, cmds.Unify.GetViper())
cmds.Mqtt.AttachFlags(cmdRoot, cmds.Unify.GetViper())
}
}

View File

@ -105,14 +105,62 @@ func (e *ResultData) IsValid() error {
//}
func (e *EndPoint) GetDataTable() output.Table {
var table output.Table
for range Only.Once {
// table = output.NewTable()
// table.SetTitle("")
// table.SetJson([]byte(e.GetJsonData(false)))
// table.SetRaw([]byte(e.GetJsonData(true)))
//
// _ = table.SetHeader(
// "Ps Key",
// "Ps Id",
// "Type",
// "Code",
// "Id",
// "Type Name",
// "Serial Number",
// "Model",
// "Model Id",
// "Name",
// "State",
// "Status",
// // "Factory Date",
// )
// for _, d := range e.Response.ResultData.PageList {
// _ = table.AddRow(
// d.PsKey.Value(),
// d.PsID.Value(),
// d.DeviceType.Value(),
// d.DeviceCode.Value(),
// d.ChannelId.Value(),
// d.TypeName.Value(),
// d.DeviceProSn.Value(),
// d.DeviceModel.Value(),
// d.DeviceModelID.Value(),
// d.DeviceName.Value(),
// d.DeviceState,
// d.DevStatus,
// // d.DeviceFactoryDate,
// )
// }
data := e.GetDevices()
table = GetDataTable(data)
}
return table
}
func GetDataTable(data Devices) output.Table {
var table output.Table
for range Only.Once {
table = output.NewTable()
table.SetTitle("")
table.SetJson([]byte(e.GetJsonData(false)))
table.SetRaw([]byte(e.GetJsonData(true)))
// table.SetJson([]byte(e.GetJsonData(false)))
// table.SetRaw([]byte(e.GetJsonData(true)))
_ = table.SetHeader(
"Vendor",
"Ps Key",
"Ps Id",
"Type",
@ -125,25 +173,67 @@ func (e *EndPoint) GetDataTable() output.Table {
"Name",
"State",
"Status",
// "Factory Date",
"UUID",
)
for _, d := range e.Response.ResultData.PageList {
for _, d := range data {
_ = table.AddRow(
d.PsKey,
d.PsID,
d.DeviceType,
d.DeviceCode,
d.ChannelId,
d.TypeName,
d.DeviceProSn,
d.DeviceModel,
d.DeviceModelID,
d.DeviceName,
d.Vendor.Value(),
d.PsKey.Value(),
d.PsId.Value(),
d.DeviceType.Value(),
d.DeviceCode.Value(),
d.ChannelId.Value(),
d.TypeName.Value(),
d.DeviceProSn.Value(),
d.DeviceModel.Value(),
d.DeviceModelID.Value(),
d.DeviceName.Value(),
d.DeviceState,
d.DevStatus,
// d.DeviceFactoryDate,
d.Uuid.Value(),
)
}
}
return table
}
type Device struct {
Vendor api.String
PsId api.Integer
PsKey api.PsKey
DeviceName api.String
DeviceProSn api.String
DeviceModel api.String
DeviceType api.Integer
DeviceCode api.Integer
ChannelId api.Integer
DeviceModelID api.Integer
TypeName api.String
DeviceState string
DevStatus string
Uuid api.Integer
}
type Devices []Device
func (e *EndPoint) GetDevices() Devices {
var ret Devices
for _, d := range e.Response.ResultData.PageList {
ret = append(ret, Device{
Vendor: d.FactoryName,
PsKey: d.PsKey,
PsId: d.PsID,
DeviceType: d.DeviceType,
DeviceCode: d.DeviceCode,
ChannelId: d.ChannelId,
TypeName: d.TypeName,
DeviceProSn: d.DeviceProSn,
DeviceModel: d.DeviceModel,
DeviceModelID: d.DeviceModelID,
DeviceName: d.DeviceName,
DeviceState: d.DeviceState,
DevStatus: d.DevStatus,
Uuid: d.ModuleUUID,
})
}
return ret
}

View File

@ -373,21 +373,21 @@ func (e *EndPoint) GetData() api.DataMap {
// parent := api.ParentDevice{Key: e.Request.PsID}
uv := api.SetUnitValueFloat(d.P83076.Value(), d.P83076Unit.Value())
entries.AddUnitValue(name + ".p83076", e.Request.PsID.String(), "p83076", "", d.TimeStamp, uv)
entries.AddUnitValue(name + ".p83076", e.Request.PsID.String(), "p83076", "", "", d.TimeStamp, uv)
uv = api.SetUnitValueFloat(d.P83080.Value(), d.P83080Unit.Value())
entries.AddUnitValue(name + ".p83080", e.Request.PsID.String(), "p83080", "", d.TimeStamp, uv)
entries.AddUnitValue(name + ".p83080", e.Request.PsID.String(), "p83080", "", "", d.TimeStamp, uv)
uv = api.SetUnitValueFloat(d.P83086.Value(), d.P83086Unit.Value())
entries.AddUnitValue(name + ".p83086", e.Request.PsID.String(), "p83086", "", d.TimeStamp, uv)
entries.AddUnitValue(name + ".p83086", e.Request.PsID.String(), "p83086", "", "", d.TimeStamp, uv)
uv = api.SetUnitValueFloat(d.P83087.Value(), d.P83087Unit.Value())
entries.AddUnitValue(name + ".p83087", e.Request.PsID.String(), "p83087", "", d.TimeStamp, uv)
entries.AddUnitValue(name + ".p83087", e.Request.PsID.String(), "p83087", "", "", d.TimeStamp, uv)
uv = api.SetUnitValueFloat(d.P83096.Value(), d.P83096Unit.Value())
entries.AddUnitValue(name + ".p83096", e.Request.PsID.String(), "p83096", "", d.TimeStamp, uv)
entries.AddUnitValue(name + ".p83096", e.Request.PsID.String(), "p83096", "", "", d.TimeStamp, uv)
uv = api.SetUnitValueFloat(d.P83101.Value(), d.P83101Unit.Value())
entries.AddUnitValue(name + ".p83101", e.Request.PsID.String(), "p83101", "", d.TimeStamp, uv)
entries.AddUnitValue(name + ".p83101", e.Request.PsID.String(), "p83101", "", "", d.TimeStamp, uv)
uv = api.SetUnitValueFloat(d.P83106.Value(), d.P83106Unit.Value())
entries.AddUnitValue(name + ".p83106", e.Request.PsID.String(), "p83106", "", d.TimeStamp, uv)
entries.AddUnitValue(name + ".p83106", e.Request.PsID.String(), "p83106", "", "", d.TimeStamp, uv)
uv = api.SetUnitValueFloat(d.P83128.Value(), d.P83128Unit.Value())
entries.AddUnitValue(name + ".p83128", e.Request.PsID.String(), "p83128", "", d.TimeStamp, uv)
entries.AddUnitValue(name + ".p83128", e.Request.PsID.String(), "p83128", "", "", d.TimeStamp, uv)
}
}
}

View File

@ -78,39 +78,39 @@ func (e *EndPoint) GetData() api.DataMap {
// entries.StructToPoints(*e.Response.ResultData.DayData, name, e.Request.PsID, time.Time{})
uv := api.SetUnitValueString(e.Response.ResultData.DayPowerQuantityTotal.Value, e.Response.ResultData.DayPowerQuantityTotal.Unit)
entries.AddUnitValue(name + ".DayPowerQuantityTotal", e.Request.PsId.String(), "DayPowerQuantityTotal", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".DayPowerQuantityTotal", e.Request.PsId.String(), "DayPowerQuantityTotal", "", "", api.NewDateTime(""), uv)
uv = api.SetUnitValueString(e.Response.ResultData.DayTotalProfit.Value, e.Response.ResultData.DayTotalProfit.Unit)
entries.AddUnitValue(name + ".DayTotalProfit", e.Request.PsId.String(), "DayTotalProfit", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".DayTotalProfit", e.Request.PsId.String(), "DayTotalProfit", "", "", api.NewDateTime(""), uv)
for _, d := range e.Response.ResultData.P34048List {
uv = api.SetUnitValueString(d, e.Response.ResultData.P34048Unit)
entries.AddUnitValue(name + ".p34048", e.Request.PsId.String(), "p34048", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p34048", e.Request.PsId.String(), "p34048", "", "", api.NewDateTime(""), uv)
}
for _, d := range e.Response.ResultData.P83012List {
uv = api.SetUnitValueString(d, e.Response.ResultData.P83012Unit)
entries.AddUnitValue(name + ".p83012", e.Request.PsId.String(), "p83012", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83012", e.Request.PsId.String(), "p83012", "", "", api.NewDateTime(""), uv)
}
for _, d := range e.Response.ResultData.P83033List {
uv = api.SetUnitValueString(d, e.Response.ResultData.P83033Unit)
entries.AddUnitValue(name + ".p83033", e.Request.PsId.String(), "p83033", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83033", e.Request.PsId.String(), "p83033", "", "", api.NewDateTime(""), uv)
}
for _, d := range e.Response.ResultData.P83106List {
uv = api.SetUnitValueString(d, e.Response.ResultData.P83106Unit)
entries.AddUnitValue(name + ".p83106", e.Request.PsId.String(), "p83106", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83106", e.Request.PsId.String(), "p83106", "", "", api.NewDateTime(""), uv)
}
for _, d := range e.Response.ResultData.P83022List {
uv = api.SetUnitValueString(d, e.Response.ResultData.P83022Unit)
entries.AddUnitValue(name + ".p83022", e.Request.PsId.String(), "p83022", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83022", e.Request.PsId.String(), "p83022", "", "", api.NewDateTime(""), uv)
}
for _, d := range e.Response.ResultData.P83118List {
uv = api.SetUnitValueString(d, e.Response.ResultData.P83118Unit)
entries.AddUnitValue(name + ".p83118", e.Request.PsId.String(), "p83118", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83118", e.Request.PsId.String(), "p83118", "", "", api.NewDateTime(""), uv)
}
}

View File

@ -296,19 +296,19 @@ func (e *EndPoint) GetData() api.DataMap {
name := fmt.Sprintf("getPsDetail.%s", e.Request.PsId.String())
uv := api.SetUnitValueFloat(e.Response.ResultData.P83012Value.Value(), e.Response.ResultData.P83012Unit.Value())
entries.AddUnitValue(name + ".p83012", e.Request.PsId.String(), "p83012", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83012", e.Request.PsId.String(), "p83012", "", "", api.NewDateTime(""), uv)
uv = api.SetUnitValueFloat(e.Response.ResultData.P83013Value.Value(), e.Response.ResultData.P83013Unit.Value())
entries.AddUnitValue(name + ".p83013", e.Request.PsId.String(), "p83013", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83013", e.Request.PsId.String(), "p83013", "", "", api.NewDateTime(""), uv)
uv = api.SetUnitValueFloat(e.Response.ResultData.P83036Value.Value(), e.Response.ResultData.P83036Unit.Value())
entries.AddUnitValue(name + ".p83036", e.Request.PsId.String(), "p83036", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83036", e.Request.PsId.String(), "p83036", "", "", api.NewDateTime(""), uv)
uv = api.SetUnitValueFloat(e.Response.ResultData.P83016.Value(), e.Response.ResultData.P83016Unit.Value())
entries.AddUnitValue(name + ".p83016", e.Request.PsId.String(), "p83016", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83016", e.Request.PsId.String(), "p83016", "", "", api.NewDateTime(""), uv)
uv = api.SetUnitValueFloat(e.Response.ResultData.P83017.Value(), e.Response.ResultData.P83017Unit.Value())
entries.AddUnitValue(name + ".p83017", e.Request.PsId.String(), "p83017", "", api.NewDateTime(""), uv)
entries.AddUnitValue(name + ".p83017", e.Request.PsId.String(), "p83017", "", "", api.NewDateTime(""), uv)
entries.StructToPoints(e.Response.ResultData, name, e.Request.PsId.String(), time.Time{})

View File

@ -31,15 +31,15 @@ type ResultData struct {
AreaID interface{} `json:"area_id" PointId:"area_id" PointType:""`
AreaType interface{} `json:"area_type" PointId:"area_type" PointType:""`
ArrearsStatus api.Integer `json:"arrears_status" PointId:"arrears_status" PointType:""`
BuildDate api.DateTime `json:"build_date" PointId:"build_date" PointType:""`
BuildDate api.DateTime `json:"build_date" PointId:"build_date" PointType:""`
BuildStatus api.Integer `json:"build_status" PointId:"build_status" PointType:""`
Co2Reduce api.UnitValue `json:"co2_reduce" PointId:"co2_reduce" PointType:""`
Co2ReduceTotal api.UnitValue `json:"co2_reduce_total" PointId:"co2_reduce_total" PointType:"PointTypeTotal"`
CurrPower api.UnitValue `json:"curr_power" PointId:"curr_power" PointType:""`
DailyIrradiation api.UnitValue `json:"daily_irradiation" PointId:"daily_irradiation" PointType:"PointTypeDaily"`
DailyIrradiationVirgin api.Float `json:"daily_irradiation_virgin" PointId:"daily_irradiation_virgin" PointType:"PointTypeDaily"`
DesignCapacity api.Float `json:"design_capacity" PointId:"design_capacity" PointType:""`
DesignCapacityUnit api.String `json:"design_capacity_unit" PointId:"design_capacity_unit" PointType:""`
DailyIrradiationVirgin api.Float `json:"daily_irradiation_virgin" PointId:"daily_irradiation_virgin" PointType:"PointTypeDaily"`
DesignCapacity api.Float `json:"design_capacity" PointId:"design_capacity" PointType:""`
DesignCapacityUnit api.String `json:"design_capacity_unit" PointId:"design_capacity_unit" PointType:""`
DesignCapacityVirgin api.Float `json:"design_capacity_virgin" PointId:"design_capacity_virgin" PointType:""`
EquivalentHour api.UnitValue `json:"equivalent_hour" PointId:"equivalent_hour" PointType:"PointTypeDaily"`
EsDisenergy api.UnitValue `json:"es_disenergy" PointId:"es_discharge_energy" PointAlias:"p83089" PointType:""`
@ -47,7 +47,7 @@ type ResultData struct {
EsPower api.UnitValue `json:"es_power" PointId:"es_power" PointAlias:"p83081" PointType:""`
EsTotalDisenergy api.UnitValue `json:"es_total_disenergy" PointId:"es_total_discharge_energy" PointAlias:"p83095" PointType:"PointTypeTotal"`
EsTotalEnergy api.UnitValue `json:"es_total_energy" PointId:"es_total_energy" PointAlias:"p83127" PointType:"PointTypeTotal"`
ExpectInstallDate api.DateTime `json:"expect_install_date" PointId:"expect_install_date" PointType:""`
ExpectInstallDate api.DateTime `json:"expect_install_date" PointId:"expect_install_date" PointType:""`
FaultAlarmOfflineDevCount api.Integer `json:"fault_alarm_offline_dev_count" PointId:"fault_alarm_offline_dev_count" PointType:""`
FaultCount api.Integer `json:"fault_count" PointId:"fault_count" PointType:""`
FaultDevCount api.Integer `json:"fault_dev_count" PointId:"fault_dev_count" PointType:""`
@ -60,12 +60,12 @@ type ResultData struct {
ID api.Integer `json:"id"`
PicLanguage api.Integer `json:"pic_language"`
PicType api.Integer `json:"pic_type"`
PictureName api.String `json:"picture_name"`
PictureURL api.String `json:"picture_url"`
PictureName api.String `json:"picture_name"`
PictureURL api.String `json:"picture_url"`
PsID api.Integer `json:"ps_id"`
PsUnitUUID interface{} `json:"ps_unit_uuid"`
} `json:"images"`
InstallDate api.DateTime `json:"install_date" PointId:"install_date" PointType:""`
InstallDate api.DateTime `json:"install_date" PointId:"install_date" PointType:""`
InstalledPowerMap api.UnitValue `json:"installed_power_map" PointId:"installed_power_map" PointType:""`
InstalledPowerVirgin api.Float `json:"installed_power_virgin" PointId:"installed_power_virgin" PointType:""`
InstallerAlarmCount api.Integer `json:"installer_alarm_count" PointId:"installer_alarm_count" PointType:""`
@ -75,36 +75,36 @@ type ResultData struct {
IsTuv api.Bool `json:"is_tuv" PointId:"is_tuv" PointType:""`
JoinYearInitElec api.Float `json:"join_year_init_elec" PointId:"join_year_init_elec" PointType:""`
Latitude api.Float `json:"latitude" PointId:"latitude" PointType:""`
Location api.String `json:"location" PointId:"location" PointType:""`
Location api.String `json:"location" PointId:"location" PointType:""`
Longitude api.Float `json:"longitude" PointId:"longitude" PointType:""`
MapLatitude api.Float `json:"map_latitude" PointId:"map_latitude" PointType:""`
MapLongitude api.Float `json:"map_longitude" PointId:"map_longitude" PointType:""`
MlpeFlag api.Integer `json:"mlpe_flag" PointId:"mlpe_flag" PointType:""`
Nmi api.String `json:"nmi" PointId:"nmi" PointType:""`
Nmi api.String `json:"nmi" PointId:"nmi" PointType:""`
OfflineDevCount api.Integer `json:"offline_dev_count" PointId:"offline_dev_count" PointType:""`
OperateYear interface{} `json:"operate_year" PointId:"operate_year" PointType:""`
OperationBusName api.String `json:"operation_bus_name" PointId:"operation_bus_name" PointType:""`
OperationBusName api.String `json:"operation_bus_name" PointId:"operation_bus_name" PointType:""`
OwnerAlarmCount api.Integer `json:"owner_alarm_count" PointId:"owner_alarm_count" PointType:""`
OwnerFaultCount api.Integer `json:"owner_fault_count" PointId:"owner_fault_count" PointType:""`
OwnerPsFaultStatus api.Integer `json:"owner_ps_fault_status" PointId:"owner_ps_fault_status" PointType:""`
P83022y api.String `json:"p83022y" PointId:"P83022" PointType:""`
P83046 api.Float `json:"p83046" PointId:"p83046" PointType:""`
P83048 api.Float `json:"p83048" PointId:"p83048" PointType:""`
P83049 api.Float `json:"p83049" PointId:"p83049" PointType:""`
P83050 api.Float `json:"p83050" PointId:"p83050" PointType:""`
P83051 api.Float `json:"p83051" PointId:"p83051" PointType:""`
P83054 api.Float `json:"p83054" PointId:"p83054" PointType:""`
P83055 api.Float `json:"p83055" PointId:"p83055" PointType:""`
P83067 api.Float `json:"p83067" PointId:"p83067" PointType:""`
P83070 api.Float `json:"p83070" PointId:"p83070" PointType:""`
P83076 api.Float `json:"p83076" PointId:"p83076" PointIgnore:"true"` // Dupe of PvPower
P83022y api.String `json:"p83022y" PointId:"P83022" PointType:""`
P83046 api.Float `json:"p83046" PointId:"p83046" PointType:""`
P83048 api.Float `json:"p83048" PointId:"p83048" PointType:""`
P83049 api.Float `json:"p83049" PointId:"p83049" PointType:""`
P83050 api.Float `json:"p83050" PointId:"p83050" PointType:""`
P83051 api.Float `json:"p83051" PointId:"p83051" PointType:""`
P83054 api.Float `json:"p83054" PointId:"p83054" PointType:""`
P83055 api.Float `json:"p83055" PointId:"p83055" PointType:""`
P83067 api.Float `json:"p83067" PointId:"p83067" PointType:""`
P83070 api.Float `json:"p83070" PointId:"p83070" PointType:""`
P83076 api.Float `json:"p83076" PointId:"p83076" PointIgnore:"true"` // Dupe of PvPower
P83077 api.Float `json:"p83077" PointId:"p83077" PointType:""`
P83081 api.Float `json:"p83081" PointId:"p83081" PointIgnore:"true"` // Dupe of EsPower
P83089 api.Float `json:"p83089" PointId:"p83089" PointIgnore:"true"` // Dupe of EsDisenergy
P83095 api.Float `json:"p83095" PointId:"p83095" PointIgnore:"true"` // Dupe of EsTotalDisenergy
P83118 api.Float `json:"p83118" PointId:"p83118" ` // Dupe of UseEnergy
P83120 api.Float `json:"p83120" PointId:"p83120" PointIgnore:"true"` // Dupe of EsEnergy
P83127 api.Float `json:"p83127" PointId:"p83127" PointIgnore:"true"` // Dupe of EsTotalEnergy
P83081 api.Float `json:"p83081" PointId:"p83081" PointIgnore:"true"` // Dupe of EsPower
P83089 api.Float `json:"p83089" PointId:"p83089" PointIgnore:"true"` // Dupe of EsDisenergy
P83095 api.Float `json:"p83095" PointId:"p83095" PointIgnore:"true"` // Dupe of EsTotalDisenergy
P83118 api.Float `json:"p83118" PointId:"p83118" ` // Dupe of UseEnergy
P83120 api.Float `json:"p83120" PointId:"p83120" PointIgnore:"true"` // Dupe of EsEnergy
P83127 api.Float `json:"p83127" PointId:"p83127" PointIgnore:"true"` // Dupe of EsTotalEnergy
ParamCo2 api.Float `json:"param_co2" PointId:"param_co2" PointType:""`
ParamCoal api.Float `json:"param_coal" PointId:"param_coal" PointType:""`
ParamIncome api.Float `json:"param_income" PointId:"param_income" PointType:""`
@ -119,26 +119,26 @@ type ResultData struct {
PsCountryID api.Integer `json:"ps_country_id" PointId:"ps_country_id" PointType:""`
PsFaultStatus api.Integer `json:"ps_fault_status" PointId:"ps_fault_status" PointType:""`
PsHealthStatus string `json:"ps_health_status" PointId:"ps_health_status" PointType:""`
PsHolder api.String `json:"ps_holder" PointId:"ps_holder" PointType:""`
PsHolder api.String `json:"ps_holder" PointId:"ps_holder" PointType:""`
PsID api.Integer `json:"ps_id" PointId:"ps_id" PointType:""`
PsIsNotInit api.Bool `json:"ps_is_not_init" PointId:"ps_is_not_init" PointType:""`
PsName api.String `json:"ps_name" PointId:"ps_name" PointType:""`
PsShortName api.String `json:"ps_short_name" PointId:"ps_short_name" PointType:""`
PsStatus api.Integer `json:"ps_status" PointId:"ps_status" PointType:""`
PsTimezone api.String `json:"ps_timezone" PointId:"ps_timezone" PointType:""`
PsIsNotInit api.Bool `json:"ps_is_not_init" PointId:"ps_is_not_init" PointType:""`
PsName api.String `json:"ps_name" PointId:"ps_name" PointType:""`
PsShortName api.String `json:"ps_short_name" PointId:"ps_short_name" PointType:""`
PsStatus api.Bool `json:"ps_status" PointId:"ps_status" PointType:""`
PsTimezone api.String `json:"ps_timezone" PointId:"ps_timezone" PointType:""`
PsType api.Integer `json:"ps_type" PointId:"ps_type" PointType:""`
PvEnergy api.UnitValue `json:"pv_energy" PointId:"pv_energy" PointAlias:"p83077" PointType:""`
PvPower api.UnitValue `json:"pv_power" PointId:"pv_power" PointAlias:"p83076" PointType:""`
Radiation api.UnitValue `json:"radiation" PointId:"radiation" PointType:""`
RadiationVirgin api.Float `json:"radiation_virgin" PointId:"radiation_virgin" PointType:""`
RecordCreateTime api.DateTime `json:"recore_create_time" PointId:"recore_create_time" PointType:""`
SafeStartDate api.DateTime `json:"safe_start_date" PointId:"safe_start_date" PointType:""`
RadiationVirgin api.Float `json:"radiation_virgin" PointId:"radiation_virgin" PointType:""`
RecordCreateTime api.DateTime `json:"recore_create_time" PointId:"recore_create_time" PointType:""`
SafeStartDate api.DateTime `json:"safe_start_date" PointId:"safe_start_date" PointType:""`
ShareType string `json:"share_type" PointId:"share_type" PointType:""`
ShippingAddress api.String `json:"shipping_address" PointId:"shipping_address" PointType:""`
ShippingZipCode api.String `json:"shipping_zip_code" PointId:"shipping_zip_code" PointType:""`
ShippingAddress api.String `json:"shipping_address" PointId:"shipping_address" PointType:""`
ShippingZipCode api.String `json:"shipping_zip_code" PointId:"shipping_zip_code" PointType:""`
TodayEnergy api.UnitValue `json:"today_energy" PointId:"today_energy" PointType:"PointTypeDaily"`
TodayIncome api.UnitValue `json:"today_income" PointId:"today_income" PointType:"PointTypeDaily"`
TotalCapacity api.UnitValue `json:"total_capcity" PointId:"total_capacity" PointType:"PointTypeTotal"`
TotalCapacity api.UnitValue `json:"total_capcity" PointId:"total_capacity" PointType:"PointTypeTotal"`
TotalEnergy api.UnitValue `json:"total_energy" PointId:"total_energy" PointType:"PointTypeTotal"`
TotalIncome api.UnitValue `json:"total_income" PointId:"total_income" PointType:"PointTypeTotal"`
TotalInitCo2Accelerate api.Float `json:"total_init_co2_accelerate" PointId:"total_init_co2_accelerate" PointType:"PointTypeTotal"`
@ -148,7 +148,7 @@ type ResultData struct {
ValidFlag api.Integer `json:"valid_flag" PointId:"valid_flag" PointType:""`
WgsLatitude api.Float `json:"wgs_latitude" PointId:"wgs_latitude" PointType:""`
WgsLongitude api.Float `json:"wgs_longitude" PointId:"wgs_longitude" PointType:""`
ZipCode api.String `json:"zip_code" PointId:"zip_code" PointType:""`
ZipCode api.String `json:"zip_code" PointId:"zip_code" PointType:""`
} `json:"pageList"`
RowCount api.Integer `json:"rowCount"`
}
@ -183,6 +183,35 @@ func (e *ResultData) IsValid() error {
// return err
// }
type Device struct {
PsFaultStatus api.Integer
PsHealthStatus string
PsHolder api.String
PsID api.Integer
PsName api.String
PsShortName api.String
PsStatus api.Bool
PsType api.Integer
}
type Devices []Device
func (e *ResultData) GetPsDevices() Devices {
var ret Devices
for _, d := range e.PageList {
ret = append(ret, Device{
PsFaultStatus: d.PsFaultStatus,
PsHealthStatus: d.PsHealthStatus,
PsHolder: d.PsHolder,
PsID: d.PsID,
PsName: d.PsName,
PsShortName: d.PsShortName,
PsStatus: d.PsStatus,
PsType: d.PsType,
})
}
return ret
}
func (e *ResultData) GetPsIds() []api.Integer {
var ret []api.Integer
for range Only.Once {

View File

@ -6,6 +6,7 @@ import (
"GoSungrow/iSolarCloud/api/apiReflect"
"GoSungrow/iSolarCloud/api/output"
"fmt"
"sort"
"time"
)
@ -37,7 +38,7 @@ type ResultData struct {
// One4 api.Integer `json:"14"`
// Two2 api.Integer `json:"22"`
// } `json:"dev_count_by_type_map"`
DevTypeDefinition map[string]string `json:"dev_type_definition"`
DevTypeDefinition map[string]api.String `json:"dev_type_definition"`
// DevTypeDefinition struct {
// One string `json:"1"`
// One0 string `json:"10"`
@ -95,18 +96,18 @@ type ResultData struct {
ComponentAmount api.Integer `json:"component_amount" PointId:"component_amount" PointType:""`
DataFlag api.Integer `json:"data_flag" PointId:"data_flag" PointType:""`
DataFlagDetail api.Integer `json:"data_flag_detail" PointId:"data_flag_detail" PointType:""`
DeviceArea string `json:"device_area" PointId:"device_area" PointType:""`
DeviceAreaName string `json:"device_area_name" PointId:"device_area_name" PointType:""`
DeviceArea api.Integer `json:"device_area" PointId:"device_area" PointType:""`
DeviceAreaName api.String `json:"device_area_name" PointId:"device_area_name" PointType:""`
DeviceCode api.Integer `json:"device_code" PointId:"device_code" PointType:""`
DeviceID api.Integer `json:"device_id" PointId:"device_id" PointType:""`
DeviceModelCode string `json:"device_model_code" PointId:"device_model_code" PointType:""`
DeviceModelID string `json:"device_model_id" PointId:"device_model_id" PointType:""`
DeviceName string `json:"device_name" PointId:"device_name" PointType:""`
DeviceStatus api.Integer `json:"device_status" PointId:"device_status" PointType:""`
DeviceModelCode api.String `json:"device_model_code" PointId:"device_model_code" PointType:""`
DeviceModelID api.Integer `json:"device_model_id" PointId:"device_model_id" PointType:""`
DeviceName api.String `json:"device_name" PointId:"device_name" PointType:""`
DeviceStatus api.Bool `json:"device_status" PointId:"device_status" PointType:""`
DeviceType api.Integer `json:"device_type" PointId:"device_type" PointType:""`
FaultCount api.Integer `json:"fault_count" PointId:"fault_count" PointType:""`
FaultStatus string `json:"fault_status" PointId:"fault_status" PointType:""`
FunctionEnum string `json:"function_enum" PointId:"function_enum" PointType:""`
FunctionEnum api.String `json:"function_enum" PointId:"function_enum" PointType:""`
InstallerAlarmCount api.Integer `json:"installer_alarm_count" PointId:"installer_alarm_count" PointType:""`
InstallerDevFaultStatus api.Integer `json:"installer_dev_fault_status" PointId:"installer_dev_fault_status" PointType:""`
InstallerFaultCount api.Integer `json:"installer_fault_count" PointId:"installer_fault_count" PointType:""`
@ -123,45 +124,45 @@ type ResultData struct {
PointData PointData `json:"point_data"`
Points interface{} `json:"points" PointId:"points" PointType:""`
PsTimezoneInfo struct {
IsDst api.Bool `json:"is_dst"`
TimeZone string `json:"time_zone"`
IsDst api.Bool `json:"is_dst"`
TimeZone api.String `json:"time_zone"`
} `json:"psTimezoneInfo"`
PsID api.Integer `json:"ps_id" PointId:"ps_id" PointType:""`
PsKey api.PsKey `json:"ps_key" PointId:"ps_key" PointType:""`
RelState api.Integer `json:"rel_state" PointId:"rel_state" PointType:""`
Sn string `json:"sn" PointId:"sn" PointType:""`
StringAmount api.Integer `json:"string_amount" PointId:"string_amount" PointType:""`
TypeName string `json:"type_name" PointId:"type_name" PointType:""`
UnitName interface{} `json:"unit_name" PointId:"unit_name" PointType:""`
UUID string `json:"uuid" PointId:"uuid" PointType:""`
UUIDIndexCode string `json:"uuid_index_code" PointId:"uuid_index_code" PointType:""`
PsID api.Integer `json:"ps_id" PointId:"ps_id" PointType:""`
PsKey api.PsKey `json:"ps_key" PointId:"ps_key" PointType:""`
RelState api.Integer `json:"rel_state" PointId:"rel_state" PointType:""`
Sn api.String `json:"sn" PointId:"sn" PointType:""`
StringAmount api.Integer `json:"string_amount" PointId:"string_amount" PointType:""`
TypeName api.String `json:"type_name" PointId:"type_name" PointType:""`
UnitName api.String `json:"unit_name" PointId:"unit_name" PointType:""`
UUID api.Integer `json:"uuid" PointId:"uuid" PointType:""`
UUIDIndexCode api.String `json:"uuid_index_code" PointId:"uuid_index_code" PointType:""`
} `json:"pageList"`
RowCount api.Integer `json:"rowCount"`
}
type PointData []PointStruct
type PointStruct struct {
CodeID api.Integer `json:"code_id"`
CodeIDOrderID string `json:"code_id_order_id"`
CodeName string `json:"code_name"`
DevPointLastUpdateTime string `json:"dev_point_last_update_time"`
IsPlatformDefaultUnit api.Bool `json:"is_platform_default_unit"`
IsShow api.Bool `json:"is_show"`
OrderID api.Integer `json:"order_id"`
OrderNum api.Integer `json:"order_num"`
PointGroupID api.Integer `json:"point_group_id"`
PointGroupIDOrderID string `json:"point_group_id_order_id"`
PointGroupName string `json:"point_group_name"`
PointID api.Integer `json:"point_id"`
PointName string `json:"point_name"`
PointSign string `json:"point_sign"`
Relate api.Integer `json:"relate"`
TimeStamp string `json:"time_stamp"`
Unit string `json:"unit"`
ValIsFixd string `json:"val_is_fixd"`
ValidSize api.Integer `json:"valid_size"`
Value api.Float `json:"value"`
ValueDescription string `json:"value_description"`
CodeID api.Integer `json:"code_id"`
CodeIDOrderID api.String `json:"code_id_order_id"`
CodeName api.String `json:"code_name"`
DevPointLastUpdateTime api.DateTime `json:"dev_point_last_update_time"`
IsPlatformDefaultUnit api.Bool `json:"is_platform_default_unit"`
IsShow api.Bool `json:"is_show"`
OrderID api.Integer `json:"order_id"`
OrderNum api.Integer `json:"order_num"`
PointGroupID api.Integer `json:"point_group_id"`
PointGroupIDOrderID string `json:"point_group_id_order_id"`
PointGroupName api.String `json:"point_group_name"`
PointID api.Integer `json:"point_id"`
PointName api.String `json:"point_name"`
PointSign api.String `json:"point_sign"`
Relate api.Integer `json:"relate"`
TimeStamp api.DateTime `json:"time_stamp"`
Unit api.String `json:"unit"`
ValIsFixd string `json:"val_is_fixd"`
ValidSize api.Integer `json:"valid_size"`
Value api.Float `json:"value"`
ValueDescription api.String `json:"value_description"`
}
// type VirtualPointStruct struct {
@ -208,7 +209,7 @@ func (e *ResultData) GetDataByName(name string) PointData {
break
}
for _, p := range e.PageList {
if p.DeviceName != name {
if p.DeviceName.Value() != name {
continue
}
ret = p.PointData
@ -237,16 +238,15 @@ func (e *EndPoint) GetDataTable() output.Table {
)
data := e.GetData()
var sorted []string
for p := range data.DataPoints {
sorted = append(sorted, string(p))
}
sort.Strings(sorted)
for _, p := range data.Order {
entries := data.DataPoints[p]
for _, p := range sorted {
entries := data.DataPoints[api.PointId(p)]
for _, de := range entries {
if (de.Parent.Key == "virtual1") ||
(de.Point.GroupName == "virtual1") ||
(de.Parent.PsId == "virtual1") ||
(de.Point.Unit == "binary") {
fmt.Sprintf("")
}
_ = table.AddRow(
de.Date.Format(api.DtLayout),
// api.NameDevicePointInt(de.Point.Parents, p.PointID.Value()),
@ -337,18 +337,19 @@ func (e *EndPoint) GetData() api.DataMap {
//
// var TotalEnergyConsumption VirtualPointStruct
entries.StructToPoints(e.Response.ResultData.DevCountByStatusMap, "queryDeviceList." + e.Request.PsId.String() + ".status", e.Request.PsId.String(), time.Time{})
name1 := "queryDeviceList." + e.Request.PsId.String()
entries.StructToPoints(e.Response.ResultData.DevCountByStatusMap, name1 + ".status", e.Request.PsId.String(), time.Time{})
for _, d := range e.Response.ResultData.PageList {
name := fmt.Sprintf("queryDeviceList.%s", d.PsKey)
entries.StructToPoints(d, name, d.PsKey.Value(), time.Time{})
name2 := fmt.Sprintf("queryDeviceList.%s", d.PsKey.Value())
entries.StructToPoints(d, name2, d.PsKey.Value(), time.Time{})
for _, p := range d.PointData {
pid := api.SetPointInt(p.PointID.Value())
uv := api.SetUnitValueFloat(p.Value.Value(), p.Unit)
uv := api.SetUnitValueFloat(p.Value.Value(), p.Unit.Value())
// name2 := fmt.Sprintf("%s.PointData.%s", name, pid)
name2 := fmt.Sprintf("%s.PointData", name)
entries.AddUnitValue(name2, d.PsKey.Value(), pid, p.PointName, api.NewDateTime(p.TimeStamp), uv)
name3 := fmt.Sprintf("%s.PointData", name2)
entries.AddUnitValue(name3, d.PsKey.Value(), pid, p.PointName.Value(), p.PointGroupName.Value(), p.TimeStamp, uv)
// Handle virtual results.
// switch pid {
@ -415,25 +416,25 @@ func (e *EndPoint) GetData() api.DataMap {
}
// TotalDcPower
entries.FromRefAddAlias("p13003", api.VirtualPsId, "pv_power", "")
entries.FromRefAddAlias("p13003", api.VirtualPsId, "power_pv", "")
// BatteryChargingPower
entries.FromRefAddAlias("p13126", api.VirtualPsId, "pv_power_to_battery", "")
entries.FromRefAddAlias("p13126", api.VirtualPsId, "battery_charge_power", "")
// BatteryDischargingPower
entries.FromRefAddAlias("p13150", api.VirtualPsId, "battery_power_to_load", "")
entries.FromRefAddAlias("p13150", api.VirtualPsId, "battery_discharge_power", "")
// TotalExportActivePower
entries.FromRefAddAlias("p13121", api.VirtualPsId, "pv_power_to_grid", "")
entries.FromRefAddAlias("p13121", api.VirtualPsId, "power_pv_to_grid", "")
// TotalLoadActivePower
entries.FromRefAddAlias("p13119", api.VirtualPsId, "load_power", "")
entries.FromRefAddAlias("p13119", api.VirtualPsId, "power_load", "")
// PurchasedPower
entries.FromRefAddAlias("p13149", api.VirtualPsId, "grid_power_to_load", "")
entries.FromRefAddAlias("p13149", api.VirtualPsId, "power_grid_to_load", "")
// Daily PV Yield
entries.FromRefAddAlias("p13112", api.VirtualPsId, "daily_pv_energy", "")
// DailyPvEnergy := entries.getFloatValue("DailyTotalLoad") - entries.getFloatValue("DailyPurchasedEnergy")
// DailyBatteryChargingEnergyFromPv
entries.FromRefAddAlias("p13174", api.VirtualPsId, "pv_battery_charge", "")
entries.FromRefAddAlias("p13174", api.VirtualPsId, "pv_battery_charge_energy", "")
// DailyBatteryDischargingEnergy
entries.FromRefAddAlias("p13029", api.VirtualPsId, "battery_discharge", "")
@ -482,14 +483,14 @@ func (e *EndPoint) GetData() api.DataMap {
entries.FromRefAddFloat("pv_self_consumption",
api.VirtualPsId,"pv_daily_yield", "",
entries.GetFloatValue("pv_self_consumption", api.LastEntry) + entries.GetFloatValue("pv_battery_charge", api.LastEntry) + entries.GetFloatValue("pv_feed_in", api.LastEntry))
entries.GetFloatValue("pv_self_consumption", api.LastEntry) + entries.GetFloatValue("pv_battery_charge_energy", api.LastEntry) + entries.GetFloatValue("pv_feed_in", api.LastEntry))
entries.FromRefAddFloat("daily_pv_energy",
api.VirtualPsId,"pv_self_consumption_percent", "",
entries.GetPercent("pv_self_consumption", "daily_pv_energy", api.LastEntry))
entries.FromRefAddFloat("daily_pv_energy",
api.VirtualPsId,"pv_battery_charge_percent", "",
entries.GetPercent("pv_battery_charge", "daily_pv_energy", api.LastEntry))
entries.GetPercent("pv_battery_charge_energy", "daily_pv_energy", api.LastEntry))
entries.FromRefAddFloat("daily_pv_energy",
api.VirtualPsId,"pv_feed_in_percent", "",
entries.GetPercent("pv_feed_in", "daily_pv_energy", api.LastEntry))
@ -504,56 +505,56 @@ func (e *EndPoint) GetData() api.DataMap {
api.VirtualPsId,"daily_purchased_energy_percent", "",
entries.GetPercent("daily_purchased_energy", "daily_total_energy", api.LastEntry))
entries.FromRefAddFloat("pv_power",
api.VirtualPsId,"pv_power_to_load", "",
entries.GetFloatValue("pv_power", api.LastEntry) - entries.GetFloatValue("pv_power_to_battery", api.LastEntry) - entries.GetFloatValue("pv_power_to_grid", api.LastEntry))
entries.FromRefAddFloat("power_pv",
api.VirtualPsId,"power_pv_to_load", "",
entries.GetFloatValue("power_pv", api.LastEntry) - entries.GetFloatValue("battery_charge_power", api.LastEntry) - entries.GetFloatValue("power_pv_to_grid", api.LastEntry))
// Battery
entries.FromRefAddFloat("pv_power_to_battery",
api.VirtualPsId,"battery_power", "",
entries.LowerUpper("pv_power_to_battery", "battery_power_to_load", api.LastEntry))
entries.FromRefAddFloat("pv_power_to_battery",
api.VirtualPsId,"battery_power_to_grid", "",
entries.FromRefAddFloat("battery_charge_power",
api.VirtualPsId,"power_battery", "",
entries.LowerUpper("battery_discharge_power", "battery_charge_power", api.LastEntry))
entries.FromRefAddFloat("battery_charge_power",
api.VirtualPsId,"power_pv_to_battery", "",
entries.GetFloatValue("battery_charge_power", api.LastEntry))
entries.FromRefAddFloat("battery_discharge_power",
api.VirtualPsId,"power_battery_to_load", "",
entries.GetFloatValue("battery_charge_power", api.LastEntry))
entries.FromRefAddFloat("battery_charge_power",
api.VirtualPsId,"power_battery_to_grid", "",
0.0)
// Grid
entries.FromRefAddFloat("grid_power_to_load",
api.VirtualPsId,"grid_power", "",
entries.LowerUpper("pv_power_to_grid", "grid_power_to_load", api.LastEntry))
entries.FromRefAddFloat("grid_power_to_load",
api.VirtualPsId,"grid_power_to_battery", "",
entries.FromRefAddFloat("power_grid_to_load",
api.VirtualPsId,"power_grid", "",
entries.LowerUpper("power_pv_to_grid", "power_grid_to_load", api.LastEntry))
entries.FromRefAddFloat("power_grid_to_load",
api.VirtualPsId,"power_grid_to_battery", "",
0.0)
entries.FromRefAddState("pv_power", api.VirtualPsId,"pv_power_active", "")
entries.FromRefAddState("battery_power", api.VirtualPsId,"battery_power_active", "")
entries.FromRefAddState("grid_power", api.VirtualPsId,"grid_power_active", "")
entries.FromRefAddState("load_power", api.VirtualPsId,"load_power_active", "")
entries.FromRefAddState("power_pv", api.VirtualPsId,"power_pv_active", "")
entries.FromRefAddState("power_battery", api.VirtualPsId,"power_battery_active", "")
entries.FromRefAddState("power_grid", api.VirtualPsId,"power_grid_active", "")
entries.FromRefAddState("power_load", api.VirtualPsId,"power_load_active", "")
entries.FromRefAddState("pv_power_to_battery", api.VirtualPsId,"pv_power_to_battery_active", "")
entries.FromRefAddState("pv_power_to_load", api.VirtualPsId,"pv_power_to_load_active", "")
entries.FromRefAddState("pv_power_to_grid", api.VirtualPsId,"pv_power_to_grid_active", "")
entries.FromRefAddState("power_pv_to_battery", api.VirtualPsId,"power_pv_to_battery_active", "")
entries.FromRefAddState("power_pv_to_load", api.VirtualPsId,"power_pv_to_load_active", "")
entries.FromRefAddState("power_pv_to_grid", api.VirtualPsId,"power_pv_to_grid_active", "")
entries.FromRefAddState("battery_power_to_load", api.VirtualPsId,"battery_power_to_load_active", "")
entries.FromRefAddState("battery_power_to_grid", api.VirtualPsId,"battery_power_to_grid_active", "")
entries.FromRefAddState("power_battery_to_load", api.VirtualPsId,"power_battery_to_load_active", "")
entries.FromRefAddState("power_battery_to_grid", api.VirtualPsId,"power_battery_to_grid_active", "")
entries.FromRefAddState("grid_power_to_load", api.VirtualPsId,"grid_power_to_load_active", "")
entries.FromRefAddState("grid_power_to_battery", api.VirtualPsId,"grid_power_to_battery_active", "")
entries.FromRefAddState("power_grid_to_load", api.VirtualPsId,"power_grid_to_load_active", "")
entries.FromRefAddState("power_grid_to_battery", api.VirtualPsId,"power_grid_to_battery_active", "")
entries.FromRefAddFloat("pv_battery_charge",
entries.FromRefAddFloat("pv_battery_charge_energy",
api.VirtualPsId, "battery_energy", "",
entries.LowerUpper("pv_battery_charge", "battery_discharge", api.LastEntry))
entries.LowerUpper("pv_battery_charge_energy", "battery_discharge", api.LastEntry))
entries.FromRefAddFloat("pv_feed_in",
api.VirtualPsId,"grid_energy", "",
entries.LowerUpper("pv_feed_in", "daily_purchased_energy", api.LastEntry))
// for _, pid := range entries.Order {
// // entries[pid].Index = i
// ret.Entries = append(ret.Entries, entries.Entries[pid])
// }
}
return entries

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
datatable "go.pennock.tech/tabular/auto"
"log"
"reflect"
"strings"
"time"
@ -43,6 +42,7 @@ type DataEntry struct {
ValueFloat float64 `json:"value_float"`
ValueBool bool `json:"value_bool"`
Index int `json:"index"`
Valid bool `json:"valid"`
}
func (de *DataEntry) IsValid() bool {
@ -95,6 +95,9 @@ func (dm *DataMap) StructToPoints(ref interface{}, endpoint string, parentId str
j := fieldTo.Tag.Get("json")
pid := fieldTo.Tag.Get("PointId")
if j == "" {
fmt.Sprintf("")
}
switch {
case pid != "":
j = pid
@ -159,7 +162,7 @@ func (dm *DataMap) StructToPoints(ref interface{}, endpoint string, parentId str
fallthrough
case "api.UnitValue":
uv = valueTo.(UnitValue)
uv = uv.UnitValueFix()
// uv = uv.UnitValueFix()
case "Float":
fallthrough
@ -173,8 +176,34 @@ func (dm *DataMap) StructToPoints(ref interface{}, endpoint string, parentId str
v := valueTo.(Integer)
uv = SetUnitValueInteger(v.Value(), "")
case "Bool":
fallthrough
case "api.Bool":
v := valueTo.(Bool)
uv = SetUnitValueString(v.String(), "binary")
case "String":
fallthrough
case "api.String":
v := valueTo.(String)
uv = SetUnitValueString(v.String(), "")
case "PsKey":
fallthrough
case "api.PsKey":
v := valueTo.(PsKey)
uv = SetUnitValueString(v.Value(), "")
case "DateTime":
fallthrough
case "api.DateTime":
v := valueTo.(DateTime)
uv = SetUnitValueString(v.String(), "")
case "bool":
log.Fatalln("INVALID BOOL TYPE")
v := valueTo.(bool)
uv = SetUnitValueString(fmt.Sprintf("%v", v), "")
// log.Fatalln("INVALID BOOL TYPE")
// uv.Unit = "" // "binary"
// uv.Value = fmt.Sprintf("%v", valueTo)
@ -224,9 +253,6 @@ func (dm *DataMap) StructToPoints(ref interface{}, endpoint string, parentId str
now = NewDateTime(timestamp.String())
}
if parentId == "virtual" {
fmt.Sprintf("")
}
dm.AddEntry(endpoint, device, p, now, uv.String())
alias := fieldTo.Tag.Get("PointAlias")
@ -339,6 +365,7 @@ func (dm *DataMap) LowerUpper(lower string, upper string, index int) float64 {
if l.ValueFloat > 0 {
ret = 0 - l.ValueFloat
break
}
ret = u.ValueFloat
}
@ -487,7 +514,8 @@ func (dm *DataMap) AddEntry(endpoint string, parentId string, point Point, date
dm.Add(JoinDevicePoint(endpoint, point.Id), DataEntry {
EndPoint: endpoint,
FullId: JoinDevicePoint(parent.Key, point.Id),
FullId: JoinDevicePoint(endpoint, point.Id),
// FullId: JoinDevicePoint(parent.Key, point.Id),
Parent: parent,
Point: &point,
@ -582,7 +610,7 @@ func JoinDevicePoint(device string, pid PointId) PointId {
return ret
}
func (dm *DataMap) AddUnitValue(endpoint string, parentId string, pid PointId, name string, date DateTime, ref UnitValue) {
func (dm *DataMap) AddUnitValue(endpoint string, parentId string, pid PointId, name string, groupName string, date DateTime, ref UnitValue) {
for range Only.Once {
if endpoint == "" {
endpoint = apiReflect.GetCallerPackage(2)
@ -614,10 +642,14 @@ func (dm *DataMap) AddUnitValue(endpoint string, parentId string, pid PointId, n
if point.Name == "" {
point.Name = PointToName(pid)
}
if point.GroupName == "" {
point.GroupName = groupName
}
dm.Add(NameDevicePoint(endpoint, pid), DataEntry {
EndPoint: endpoint,
FullId: JoinDevicePoint(parent.Key, pid),
FullId: JoinDevicePoint(endpoint, point.Id),
// FullId: JoinDevicePoint(parent.Key, point.Id),
Parent: parent,
Point: point,
@ -650,7 +682,8 @@ func (dm *DataMap) AddFloat(endpoint string, parentId string, pid PointId, name
dm.Add(pid, DataEntry {
EndPoint: endpoint,
FullId: JoinDevicePoint(parent.Key, pid),
FullId: JoinDevicePoint(endpoint, point.Id),
// FullId: JoinDevicePoint(parent.Key, point.Id),
Parent: parent,
Date: date,
@ -787,18 +820,20 @@ func (de *DataEntry) CreateAlias(endpoint string, parentId string, pid PointId,
},
Date: de.Date,
EndPoint: endpoint,
FullId: "",
Parent: ParentDevice{},
Value: "",
ValueFloat: 0,
ValueBool: false,
Index: 0,
FullId: JoinDevicePoint(endpoint, pid),
// FullId: JoinDevicePoint(parentId, pid),
Parent: de.Parent, // ParentDevice{},
Value: de.Value,
ValueFloat: de.ValueFloat,
ValueBool: de.ValueBool,
Index: de.Index,
}
ret.Parent.Set(parentId)
de.Point.Parents.Add(ret.Parent)
de.FullId = NameDevicePoint(ret.Parent.Key, pid)
// de.FullId = JoinDevicePoint(endpoint, pid)
// de.FullId = NameDevicePoint(ret.Parent.Key, pid)
// de.Point.Id = pid
// de.Point.Name = name
// de.Point.GroupName = parentId
@ -828,34 +863,42 @@ func (de *DataEntry) CreateState(endpoint string, parentId string, pid PointId,
}
de2 := de.CreateAlias(endpoint, parentId, pid, name)
de2.Value = fmt.Sprintf("%v", IsActive(de.ValueFloat))
// de2.ValueFloat = 0
if de2.ValueFloat == 0 {
de2.Value = "false"
de2.ValueBool = false
de2.ValueFloat = 0
} else {
de2.Value = "true"
de2.ValueBool = true
de2.ValueFloat = 1
}
de2.Point.Unit = "binary"
return de2
}
func (de *DataEntry) UpdateMeta(date *DateTime, parentId string, pid PointId, name string) {
if date != nil {
de.Date = *date
}
if name == "" {
name = PointToName(pid)
}
var parent ParentDevice
parent.Set(parentId)
de.Point.Parents.Add(parent)
de.FullId = NameDevicePoint(parentId, pid)
de.Parent.Key = parentId
de.Parent = parent
de.Point.Id = pid
de.Point.Name = name
de.Point.GroupName = parentId
de.Index = 0
}
// func (de *DataEntry) UpdateMeta(date *DateTime, endpoint string, parentId string, pid PointId, name string) {
//
// if date != nil {
// de.Date = *date
// }
// if name == "" {
// name = PointToName(pid)
// }
//
// var parent ParentDevice
// parent.Set(parentId)
// de.Point.Parents.Add(parent)
//
// de.FullId = JoinDevicePoint(endpoint, pid)
// // de.FullId = NameDevicePoint(parentId, pid)
// de.Parent.Key = parentId
// de.Parent = parent
// de.Point.Id = pid
// de.Point.Name = name
// de.Point.GroupName = parentId
// de.Index = 0
// }
func CreateDataEntryActive(date DateTime, endpoint string, parentId string, pid PointId, name string, value float64) DataEntry {
@ -873,7 +916,8 @@ func CreateDataEntryActive(date DateTime, endpoint string, parentId string, pid
return DataEntry {
EndPoint: endpoint,
FullId: JoinDevicePoint(parent.Key, pid),
FullId: JoinDevicePoint(endpoint, point.Id),
// FullId: JoinDevicePoint(parent.Key, point.Id),
Parent: parent,
Point: point,
@ -899,7 +943,8 @@ func CreateDataEntryString(date DateTime, endpoint string, parentId string, pid
return DataEntry {
EndPoint: endpoint,
FullId: JoinDevicePoint(parent.Key, pid),
FullId: JoinDevicePoint(endpoint, pid),
// FullId: JoinDevicePoint(parent.Key, pid),
Parent: parent,
Point: point,
@ -927,7 +972,8 @@ func CreateDataEntryUnitValue(date DateTime, endpoint string, parentId string, p
return DataEntry {
EndPoint: endpoint,
FullId: JoinDevicePoint(parent.Key, pid),
FullId: JoinDevicePoint(endpoint, pid),
// FullId: JoinDevicePoint(parent.Key, pid),
Parent: parent,
Point: point,

View File

@ -15,6 +15,7 @@ type UnitValue struct {
float64 `json:"value_float,omitempty"`
int64 `json:"value_int,omitempty"`
isFloat bool
Valid bool `json:"valid"`
}
func (t *UnitValue) UnitValueFix() UnitValue {
@ -75,6 +76,8 @@ func (t *UnitValue) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
t.Valid = false
if len(data) == 0 {
break
}
@ -128,6 +131,8 @@ func (t UnitValue) MarshalJSON() ([]byte, error) {
var err error
for range Only.Once {
t.Valid = false
if t.isFloat {
// Store result to JSON string
data, err = json.Marshal(&struct {
@ -137,6 +142,11 @@ func (t UnitValue) MarshalJSON() ([]byte, error) {
Unit: t.unit,
Value: t.float64,
})
if err != nil {
break
}
t.Valid = true
break
}
@ -148,6 +158,11 @@ func (t UnitValue) MarshalJSON() ([]byte, error) {
Unit: t.unit,
Value: t.int64,
})
if err != nil {
break
}
t.Valid = true
}
return data, err
@ -180,13 +195,14 @@ func (t *UnitValue) SetString(value string) UnitValue {
for range Only.Once {
t.string = value
t.int64 = 0
t.Valid = false
if value == "" {
break
}
if value == "--" {
value = ""
// value = ""
break
}
@ -215,6 +231,7 @@ func (t *UnitValue) SetInteger(value int64) UnitValue {
t.int64 = value
t.float64 = float64(value)
t.isFloat = false
t.Valid = true
if value == 0 {
break
@ -232,6 +249,7 @@ func (t *UnitValue) SetFloat(value float64) UnitValue {
t.int64 = int64(value)
t.float64 = value
t.isFloat = true
t.Valid = true
if value == 0 {
break
@ -248,6 +266,7 @@ func (t *UnitValue) SetFloat(value float64) UnitValue {
func (t *UnitValue) SetUnit(unit string) UnitValue {
for range Only.Once {
t.unit = unit
// t.Valid = true
}
return *t
@ -291,6 +310,7 @@ func (u *UnitValueMap) Sort() []string {
type Integer struct {
string `json:"string,omitempty"`
int64 `json:"integer,omitempty"`
Valid bool `json:"valid"`
}
// UnmarshalJSON - Convert JSON to value
@ -298,6 +318,8 @@ func (t *Integer) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
t.Valid = false
if len(data) == 0 {
break
}
@ -326,10 +348,13 @@ func (t Integer) MarshalJSON() ([]byte, error) {
var err error
for range Only.Once {
t.Valid = false
data, err = json.Marshal(t.int64)
if err != nil {
break
}
t.Valid = true
// t.string = strconv.FormatInt(t.int64, 10)
}
@ -348,13 +373,14 @@ func (t *Integer) SetString(value string) Integer {
for range Only.Once {
t.string = value
t.int64 = 0
t.Valid = false
if value == "" {
break
}
if value == "--" {
value = ""
// value = ""
break
}
@ -365,6 +391,7 @@ func (t *Integer) SetString(value string) Integer {
break
}
t.int64 = int64(v)
t.Valid = true
}
return *t
@ -374,6 +401,7 @@ func (t *Integer) SetValue(value int64) Integer {
for range Only.Once {
t.string = ""
t.int64 = value
t.Valid = true
if value == 0 {
break
@ -399,6 +427,7 @@ func SetIntegerValue(value int64) Integer {
type Float struct {
string `json:"string,omitempty"`
float64 `json:"float,omitempty"`
Valid bool `json:"valid"`
}
// UnmarshalJSON - Convert JSON to value
@ -406,6 +435,8 @@ func (t *Float) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
t.Valid = false
if len(data) == 0 {
break
}
@ -434,10 +465,13 @@ func (t Float) MarshalJSON() ([]byte, error) {
var err error
for range Only.Once {
t.Valid = false
data, err = json.Marshal(t.float64)
if err != nil {
break
}
t.Valid = true
// t.string = strconv.FormatFloat(t.float64, 'f', 12, 64)
}
@ -456,13 +490,14 @@ func (t *Float) SetString(value string) Float {
for range Only.Once {
t.string = value
t.float64 = 0
t.Valid = false
if value == "" {
break
}
if value == "--" {
value = ""
// value = ""
break
}
@ -471,6 +506,7 @@ func (t *Float) SetString(value string) Float {
if err == nil {
break
}
t.Valid = true
}
return *t
@ -480,6 +516,7 @@ func (t *Float) SetValue(value float64) Float {
for range Only.Once {
t.string = ""
t.float64 = value
t.Valid = true
if value == 0 {
break
@ -505,6 +542,7 @@ func SetFloatValue(value float64) Float {
type Bool struct {
string `json:"string,omitempty"`
bool `json:"bool,omitempty"`
Valid bool `json:"valid"`
}
// UnmarshalJSON - Convert JSON to value
@ -512,6 +550,8 @@ func (t *Bool) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
t.Valid = false
if len(data) == 0 {
break
}
@ -550,10 +590,13 @@ func (t Bool) MarshalJSON() ([]byte, error) {
var err error
for range Only.Once {
t.Valid = false
data, err = json.Marshal(t.bool)
if err != nil {
break
}
t.Valid = true
// t.string = strconv.FormatFloat(t.bool, 'f', 12, 64)
}
@ -571,6 +614,7 @@ func (t Bool) String() string {
func (t *Bool) SetString(value string) Bool {
for range Only.Once {
t.string = value
t.Valid = false
switch strings.ToLower(t.string) {
case "false":
@ -582,10 +626,11 @@ func (t *Bool) SetString(value string) Bool {
case "0":
fallthrough
case "":
fallthrough
case "--":
// fallthrough
// case "--":
t.bool = false
t.string = "false"
t.Valid = true
case "true":
fallthrough
@ -596,6 +641,7 @@ func (t *Bool) SetString(value string) Bool {
case "1":
t.bool = true
t.string = "true"
t.Valid = true
}
}
@ -605,6 +651,7 @@ func (t *Bool) SetString(value string) Bool {
func (t *Bool) SetValue(value bool) Bool {
for range Only.Once {
t.bool = value
t.Valid = true
if t.bool {
t.string = "true"
@ -619,6 +666,8 @@ func (t *Bool) SetValue(value bool) Bool {
func (t *Bool) SetInteger(value int64) Bool {
for range Only.Once {
t.Valid = true
if value == 0 {
t.bool = false
t.string = "false"
@ -645,6 +694,7 @@ func SetBoolValue(value bool) Bool {
type String struct {
string `json:"string,omitempty"`
Valid bool `json:"valid"`
}
// UnmarshalJSON - Convert JSON to value
@ -652,16 +702,18 @@ func (t *String) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
t.Valid = false
if len(data) == 0 {
break
}
// Store result from string
err = json.Unmarshal(data, &t.string)
if err == nil {
t.SetString(t.string)
if err != nil {
break
}
t.SetString(t.string)
}
return err
@ -673,10 +725,13 @@ func (t String) MarshalJSON() ([]byte, error) {
var err error
for range Only.Once {
t.Valid = false
data, err = json.Marshal(t.string)
if err != nil {
break
}
t.Valid = true
}
return data, err
@ -693,6 +748,7 @@ func (t String) String() string {
func (t *String) SetString(value string) String {
for range Only.Once {
t.string = value
t.Valid = true
}
return *t
@ -701,6 +757,7 @@ func (t *String) SetString(value string) String {
func (t *String) SetValue(value string) String {
for range Only.Once {
t.string = value
t.Valid = true
}
return *t
@ -714,6 +771,7 @@ func SetStringValue(value string) String {
type PsKey struct {
string `json:"string,omitempty"`
Valid bool `json:"valid"`
}
// UnmarshalJSON - Convert JSON to value
@ -721,16 +779,18 @@ func (t *PsKey) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
t.Valid = false
if len(data) == 0 {
break
}
// Store result from string
err = json.Unmarshal(data, &t.string)
if err == nil {
t.SetPsKey(t.string)
if err != nil {
break
}
t.SetPsKey(t.string)
}
return err
@ -742,10 +802,13 @@ func (t PsKey) MarshalJSON() ([]byte, error) {
var err error
for range Only.Once {
t.Valid = false
data, err = json.Marshal(t.string)
if err != nil {
break
}
t.Valid = true
}
return data, err
@ -762,6 +825,7 @@ func (t PsKey) PsKey() string {
func (t *PsKey) SetPsKey(value string) PsKey {
for range Only.Once {
t.string = value
t.Valid = true
}
return *t
@ -770,6 +834,7 @@ func (t *PsKey) SetPsKey(value string) PsKey {
func (t *PsKey) SetValue(value string) PsKey {
for range Only.Once {
t.string = value
t.Valid = true
}
return *t

View File

@ -685,7 +685,7 @@ func (sg *SunGrow) SearchPointNames(pns ...string) error {
return sg.Error
}
func (sg *SunGrow) GetDevices(psIds ...api.Integer) error {
func (sg *SunGrow) GetDeviceList(psIds ...api.Integer) error {
for range Only.Once {
if len(psIds) == 0 {
psIds, sg.Error = sg.GetPsIds()
@ -694,6 +694,7 @@ func (sg *SunGrow) GetDevices(psIds ...api.Integer) error {
}
}
var ret getDeviceList.Devices
for _, psId := range psIds {
ep := sg.GetByStruct(
"AppService.getDeviceList",
@ -706,28 +707,25 @@ func (sg *SunGrow) GetDevices(psIds ...api.Integer) error {
}
data := getDeviceList.Assert(ep)
table := data.GetDataTable()
if table.Error != nil {
sg.Error = table.Error
break
}
ret = append(ret, data.GetDevices()...)
}
table.SetTitle("Device Info %s", psId)
table.SetFilePrefix(data.SetFilenamePrefix("%d", psId))
table.SetGraphFilter("")
table.SetSaveFile(sg.SaveAsFile)
table.OutputType = sg.OutputType
sg.Error = table.Output()
if sg.Error != nil {
break
}
table := getDeviceList.GetDataTable(ret)
table.SetTitle("All Devices")
table.SetFilePrefix("")
table.SetGraphFilter("")
table.SetSaveFile(sg.SaveAsFile)
table.OutputType = sg.OutputType
sg.Error = table.Output()
if sg.Error != nil {
break
}
}
return sg.Error
}
func (sg *SunGrow) GetDeviceModels() error {
func (sg *SunGrow) GetDeviceModelInfoList() error {
for range Only.Once {
ep := sg.GetByStruct(
"AppService.getDeviceModelInfoList",
@ -1078,7 +1076,7 @@ func (sg *SunGrow) StringToPids(pids ...string) ([]api.Integer, error) {
return psIds, sg.Error
}
func (sg *SunGrow) GetPsName() ([]string, error) {
func (sg *SunGrow) GetPsNames() ([]string, error) {
var ret []string
for range Only.Once {
@ -1095,7 +1093,80 @@ func (sg *SunGrow) GetPsName() ([]string, error) {
return ret, sg.Error
}
func (sg *SunGrow) GetPsModel() ([]string, error) {
func (sg *SunGrow) GetDevices(print bool) (getDeviceList.Devices, error) {
var ret getDeviceList.Devices
for range Only.Once {
ep := sg.GetByStruct("AppService.getPsList", nil, DefaultCacheTimeout)
if ep.IsError() {
sg.Error = ep.GetError()
break
}
_getPsList := getPsList.AssertResultData(ep)
psIds := _getPsList.GetPsDevices()
for _, psId := range psIds {
ret = append(ret, getDeviceList.Device{
Vendor: api.SetStringValue(""),
PsId: psId.PsID,
PsKey: api.SetPsKeyValue(psId.PsID.String()),
DeviceName: psId.PsName,
DeviceProSn: psId.PsShortName,
DeviceModel: api.SetStringValue(""),
DeviceType: psId.PsType,
DeviceCode: api.SetIntegerValue(0),
ChannelId: api.SetIntegerValue(0),
DeviceModelID: api.SetIntegerValue(0),
TypeName: api.SetStringValue("Ps Id"),
DeviceState: psId.PsHealthStatus,
DevStatus: psId.PsStatus.String(),
Uuid: api.SetIntegerValue(0),
// PsFaultStatus: d.PsFaultStatus,
// PsHealthStatus: d.PsHealthStatus,
// PsHolder: d.PsHolder,
// PsID: d.PsID,
// PsName: d.PsName,
// PsShortName: d.PsShortName,
// PsStatus: d.PsStatus,
// PsType: d.PsType,
})
ep = sg.GetByStruct(
"AppService.getDeviceList",
// getDeviceList.RequestData{PsId: strconv.FormatInt(psId, 10)},
getDeviceList.RequestData{PsId: psId.PsID},
DefaultCacheTimeout,
)
if sg.Error != nil {
break
}
data := getDeviceList.Assert(ep)
ret = append(ret, data.GetDevices()...)
}
if !print {
break
}
table := getDeviceList.GetDataTable(ret)
table.SetTitle("All Devices")
table.SetFilePrefix("")
table.SetGraphFilter("")
table.SetSaveFile(sg.SaveAsFile)
table.OutputType = sg.OutputType
sg.Error = table.Output()
if sg.Error != nil {
break
}
}
return ret, sg.Error
}
func (sg *SunGrow) GetPsModels() ([]string, error) {
var ret []string
for range Only.Once {
@ -1124,7 +1195,7 @@ func (sg *SunGrow) GetPsModel() ([]string, error) {
return ret, sg.Error
}
func (sg *SunGrow) GetPsSerial() ([]string, error) {
func (sg *SunGrow) GetPsSerials() ([]string, error) {
var ret []string
for range Only.Once {

View File

@ -20,21 +20,31 @@ func (m *Mqtt) BinarySensorPublishConfig(config EntityConfig) error {
// LastResetValueTemplate = "{{ value_json.last_reset | as_datetime() }}"
// }
device := m.Device
device.Name = JoinStrings(m.Device.Name, config.ParentId)
device.Connections = [][]string{
{ m.Device.Name, JoinStringsForId(m.Device.Name, config.ParentId) },
{ JoinStringsForId(m.Device.Name, config.ParentId), JoinStringsForId(m.Device.Name, config.ParentId, config.Name) },
// 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
}
device.Identifiers = []string{ JoinStringsForId(m.Device.Name, config.ParentId) }
st := JoinStringsForId(m.Device.Name, config.ParentId, config.Name)
id := JoinStringsForId(m.DeviceName, config.FullId)
// id := JoinStringsForId(m.Device.Name, config.ParentName, config.Name, config.UniqueId),
payload := BinarySensor {
Device: device,
Name: JoinStrings(m.Device.Name, config.ParentName, config.FullId),
StateTopic: JoinStringsForTopic(m.binarySensorPrefix, st, "state"),
Device: newDevice,
Name: JoinStrings(m.DeviceName, config.FullId),
StateTopic: JoinStringsForTopic(m.binarySensorPrefix, id, "state"),
StateClass: config.StateClass,
UniqueId: st,
UniqueId: id,
UnitOfMeasurement: config.Units,
DeviceClass: config.DeviceClass,
Qos: 0,
@ -66,8 +76,8 @@ func (m *Mqtt) BinarySensorPublishConfig(config EntityConfig) error {
// OffDelay: 0,
}
ct := JoinStringsForTopic(m.binarySensorPrefix, st, "config")
t := m.client.Publish(ct, 0, true, payload.Json())
tag := JoinStringsForTopic(m.binarySensorPrefix, id, "config")
t := m.client.Publish(tag, 0, true, payload.Json())
if !t.WaitTimeout(m.Timeout) {
m.err = t.Error()
}
@ -79,17 +89,20 @@ func (m *Mqtt) BinarySensorPublishConfig(config EntityConfig) error {
func (m *Mqtt) BinarySensorPublishValue(config EntityConfig) error {
for range Only.Once {
if config.Units != LabelBinarySensor {
// if config.Units != LabelBinarySensor {
if !config.IsBinarySensor() {
break
}
st := JoinStringsForId(m.Device.Name, config.ParentId, config.Name)
id := JoinStringsForId(m.DeviceName, config.FullId)
// tagId := JoinStringsForId(m.Device.Name, config.ParentName, config.Name, config.UniqueId),
payload := MqttState {
LastReset: m.GetLastReset(config.UniqueId),
Value: config.Value,
}
st = JoinStringsForTopic(m.binarySensorPrefix, st, "state")
t := m.client.Publish(st, 0, true, payload.Json())
tag := JoinStringsForTopic(m.binarySensorPrefix, id, "state")
t := m.client.Publish(tag, 0, true, payload.Json())
if !t.WaitTimeout(m.Timeout) {
m.err = t.Error()
}

View File

@ -1,6 +1,9 @@
package mmHa
import "encoding/json"
import (
"encoding/json"
"github.com/MickMake/GoUnify/Only"
)
type Config struct {
@ -36,6 +39,70 @@ type Device struct {
ViaDevice string `json:"via_device,omitempty" required:"false"`
}
func (m *Mqtt) NewDevice(config EntityConfig) (bool, Device) {
var ok bool
var ret Device
for range Only.Once {
var parent Device
if parent, ok = m.MqttDevices[config.ParentName]; !ok {
break
}
ret = Device {
ConfigurationUrl: parent.ConfigurationUrl,
Connections: [][]string {
{ m.EntityPrefix, JoinStringsForId(m.EntityPrefix, config.ParentName) },
{ JoinStringsForId(m.EntityPrefix, config.ParentName), JoinStringsForId(m.EntityPrefix, config.ParentId) },
},
Identifiers: []string{ JoinStringsForId(m.EntityPrefix, config.ParentId) },
Manufacturer: parent.Manufacturer,
Model: parent.Model,
Name: JoinStrings(parent.Name, config.ParentName),
SuggestedArea: parent.SuggestedArea,
SwVersion: parent.SwVersion,
ViaDevice: parent.ViaDevice,
}
ok = true
}
return ok, ret
}
// func (d *Device) NewDevice(config EntityConfig) Device {
// var ret Device
//
// for range Only.Once {
// ret = Device{
// ConfigurationUrl: d.ConfigurationUrl,
// Connections: [][]string {
// { d.Name, JoinStringsForId(d.Name, config.ParentName) },
// { JoinStringsForId(d.Name, config.ParentName), JoinStringsForId(d.Name, config.ParentId) },
// },
// Identifiers: []string{ JoinStringsForId(d.Name, config.ParentId) },
// Manufacturer: d.Manufacturer,
// Model: d.Model,
// Name: JoinStrings(d.Name, config.ParentName),
// SuggestedArea: d.SuggestedArea,
// SwVersion: d.SwVersion,
// ViaDevice: d.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) }
// }
//
// return ret
// }
// {
// "device": {
// "identifiers": [

View File

@ -3,4 +3,5 @@ package mmHa
const (
LabelSwitch = "switch"
LabelBinarySensor = "binary"
LabelLight = "light"
)

View File

@ -18,7 +18,7 @@ func JoinStringsForId(args ...string) string {
continue
}
a = strings.TrimSpace(a)
a = re.ReplaceAllString(a, `_`)
a = re.ReplaceAllString(a, `-`)
newargs = append(newargs, a)
}
// return strings.ReplaceAll(strings.TrimSpace(strings.Join(args, ".")), ".", "_")

View File

@ -6,14 +6,42 @@ import (
)
func (m *Mqtt) PublishLightConfig(id string, name string, subName string, units string, valueName string, class string) error {
func (m *Mqtt) PublishLightConfig(config EntityConfig) error {
// func (m *Mqtt) PublishLightConfig(id string, name string, subName string, units string, valueName string, class string) error {
for range Only.Once {
id = JoinStringsForId(m.EntityPrefix, m.Device.Name, id)
config.FixConfig()
if !config.IsLight() {
break
}
ok, newDevice := m.NewDevice(config)
if !ok {
break
}
id := JoinStringsForId(m.DeviceName, config.FullId)
payload := Light {
Device: m.Device,
Name: JoinStrings(m.Device.ViaDevice, name),
Device: newDevice,
// Name: JoinStrings(newDevice.ViaDevice, config.Name),
Name: JoinStrings(m.DeviceName, config.FullId),
StateTopic: JoinStringsForTopic(m.switchPrefix, id, "state"),
// StateClass: config.StateClass,
// UniqueId: id,
// UnitOfMeasurement: config.Units,
// DeviceClass: config.DeviceClass,
// Qos: 0,
// ForceUpdate: true,
// ExpireAfter: 0,
// Encoding: "utf-8",
// EnabledByDefault: true,
PayloadOn: "true",
PayloadOff: "false",
// LastResetValueTemplate: config.LastResetValueTemplate,
ValueTemplate: config.ValueTemplate,
// Icon: config.Icon,
// StateClass: "measurement",
// UniqueId: id,
// UnitOfMeasurement: units,
@ -31,14 +59,9 @@ func (m *Mqtt) PublishLightConfig(id string, name string, subName string, units
// LastResetValueTemplate: "{{ (as_datetime((value_json.last_reset | int | timestamp_utc)|string+'Z')).isoformat() }}",
}
m.client.Publish(JoinStringsForTopic(m.lightPrefix, id, "config"), 0, true, payload.Json())
}
return m.err
}
func (m *Mqtt) PublishLight(subtopic string, payload interface{}) error {
for range Only.Once {
t := m.client.Publish(JoinStringsForTopic(m.lightPrefix, subtopic), 0, true, payload)
// m.client.Publish(JoinStringsForTopic(m.lightPrefix, id, "config"), 0, true, payload.Json())
tag := JoinStringsForTopic(m.lightPrefix, id, "config")
t := m.client.Publish(tag, 0, true, payload.Json())
if !t.WaitTimeout(m.Timeout) {
m.err = t.Error()
}
@ -46,17 +69,52 @@ func (m *Mqtt) PublishLight(subtopic string, payload interface{}) error {
return m.err
}
func (m *Mqtt) PublishLightState(topic string, payload interface{}) error {
func (m *Mqtt) LightPublishValue(config EntityConfig) error {
for range Only.Once {
topic = JoinStringsForId(m.EntityPrefix, m.Device.Name, topic)
t := m.client.Publish(JoinStringsForTopic(m.lightPrefix, topic, "state"), 0, true, payload)
// if config.Units != LabelBinarySensor {
if !config.IsLight() {
break
}
id := JoinStringsForId(m.DeviceName, config.FullId)
// tagId := JoinStringsForId(m.Device.Name, config.ParentName, config.Name, config.UniqueId),
payload := MqttState {
LastReset: m.GetLastReset(config.UniqueId),
Value: config.Value,
}
tag := JoinStringsForTopic(m.lightPrefix, id, "state")
t := m.client.Publish(tag, 0, true, payload.Json())
if !t.WaitTimeout(m.Timeout) {
m.err = t.Error()
}
}
return m.err
}
// func (m *Mqtt) PublishLight(subtopic string, payload interface{}) error {
// for range Only.Once {
// t := m.client.Publish(JoinStringsForTopic(m.lightPrefix, subtopic), 0, true, payload)
// if !t.WaitTimeout(m.Timeout) {
// m.err = t.Error()
// }
// }
// return m.err
// }
//
// func (m *Mqtt) PublishLightState(topic string, payload interface{}) error {
// for range Only.Once {
// topic = JoinStringsForId(m.EntityPrefix, m.DeviceName, topic)
// t := m.client.Publish(JoinStringsForTopic(m.lightPrefix, topic, "state"), 0, true, payload)
// if !t.WaitTimeout(m.Timeout) {
// m.err = t.Error()
// }
// }
// return m.err
// }
type Light struct {
AvailabilityTopic string `json:"availability_topic,omitempty"`

View File

@ -67,23 +67,51 @@ func (m *Mqtt) SensorPublishConfig(config EntityConfig) error {
// ValueTemplate = "{{ value_json.value }}"
// }
device := m.Device
device.Name = JoinStrings(m.Device.Name, config.ParentId)
device.Connections = [][]string {
{ m.Device.Name, JoinStringsForId(m.Device.Name, config.ParentId) },
{ JoinStringsForId(m.Device.Name, config.ParentId), JoinStringsForId(m.Device.Name, config.ParentId, config.Name) },
// 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
}
device.Identifiers = []string{ JoinStringsForId(m.Device.Name, config.ParentId) }
st := JoinStringsForId(m.Device.Name, config.ParentId, config.Name)
// st := JoinStringsForId(m.Device.Name, config.ParentName, config.Name, config.UniqueId),
id := JoinStringsForId(m.DeviceName, config.FullId)
// id := JoinStringsForId(m.Device.Name, config.ParentName, config.Name, config.UniqueId),
payload := Sensor {
Device: device,
Name: JoinStrings(m.Device.Name, config.ParentName, config.FullId),
StateTopic: JoinStringsForTopic(m.sensorPrefix, st, "state"),
// StateTopic: m.GetSensorStateTopic(name, config.SubName),m.EntityPrefix, m.Device.FullName, config.SubName
Device: newDevice,
Name: JoinStrings(m.DeviceName, config.FullId),
StateTopic: JoinStringsForTopic(m.sensorPrefix, id, "state"),
StateClass: config.StateClass,
UniqueId: st,
UniqueId: id,
UnitOfMeasurement: config.Units,
DeviceClass: config.DeviceClass,
Qos: 0,
@ -113,8 +141,8 @@ func (m *Mqtt) SensorPublishConfig(config EntityConfig) error {
// PayloadNotAvailable: "",
}
ct := JoinStringsForTopic(m.sensorPrefix, st, "config")
t := m.client.Publish(ct, 0, true, payload.Json())
tag := JoinStringsForTopic(m.sensorPrefix, id, "config")
t := m.client.Publish(tag, 0, true, payload.Json())
if !t.WaitTimeout(m.Timeout) {
m.err = t.Error()
}
@ -126,17 +154,18 @@ func (m *Mqtt) SensorPublishConfig(config EntityConfig) error {
func (m *Mqtt) SensorPublishValue(config EntityConfig) error {
for range Only.Once {
if config.Units == LabelBinarySensor {
// if config.Units == LabelBinarySensor {
if !config.IsSensor() {
break
}
st := JoinStringsForId(m.Device.Name, config.ParentId, config.Name)
id := JoinStringsForId(m.DeviceName, config.FullId)
payload := MqttState {
LastReset: m.GetLastReset(config.FullId),
Value: config.Value,
}
st = JoinStringsForTopic(m.sensorPrefix, st, "state")
t := m.client.Publish(st, 0, true, payload.Json())
tag := JoinStringsForTopic(m.sensorPrefix, id, "state")
t := m.client.Publish(tag, 0, true, payload.Json())
if !t.WaitTimeout(m.Timeout) {
m.err = t.Error()
}
@ -193,7 +222,7 @@ func (m *Mqtt) PublishSensorValues(configs []EntityConfig) error {
topic := ""
for _, oid := range configs {
if topic == "" {
topic = JoinStringsForId(m.Device.Name, oid.ParentName, oid.Name)
topic = JoinStringsForId(m.DeviceName, oid.ParentName, oid.Name)
}
if _, ok := cs[oid.StateClass]; !ok {
cs[oid.StateClass] = make(Fields)
@ -212,7 +241,7 @@ func (m *Mqtt) PublishSensorValues(configs []EntityConfig) error {
}
func (m *Mqtt) GetSensorStateTopic(config EntityConfig) string {
st := JoinStringsForId(m.Device.Name, config.ParentId, config.Name)
st := JoinStringsForId(m.DeviceName, config.FullId)
st = JoinStringsForTopic(m.sensorPrefix, st, "state") // m.GetSensorStateTopic(name, config.SubName),m.EntityPrefix, m.Device.FullName, config.SubName
return st
}

View File

@ -2,6 +2,7 @@ package mmHa
import (
"GoSungrow/Only"
"GoSungrow/iSolarCloud/AppService/getDeviceList"
"GoSungrow/iSolarCloud/api"
"encoding/json"
"errors"
@ -18,22 +19,24 @@ type Mqtt struct {
Password string `json:"password"`
Host string `json:"host"`
Port string `json:"port"`
Timeout time.Duration `json:"timeout"`
EntityPrefix string `json:"entity_prefix"`
Timeout time.Duration `json:"timeout"`
EntityPrefix string `json:"entity_prefix"`
url *url.URL
client mqtt.Client
pubClient mqtt.Client
clientOptions *mqtt.ClientOptions
LastRefresh time.Time `json:"-"`
PsId api.Integer `json:"-"`
LastRefresh time.Time `json:"-"`
SungrowDevices getDeviceList.Devices `json:"-"`
SungrowPsIds map[api.Integer]bool
Device Device
DeviceName string
MqttDevices map[string]Device
servicePrefix string
sensorPrefix string
lightPrefix string
switchPrefix string
servicePrefix string
sensorPrefix string
lightPrefix string
switchPrefix string
binarySensorPrefix string
token mqtt.Token
@ -57,6 +60,9 @@ func New(req Mqtt) *Mqtt {
ret.lightPrefix = "homeassistant/light/" + req.ClientId
ret.switchPrefix = "homeassistant/switch/" + req.ClientId
ret.binarySensorPrefix = "homeassistant/binary_sensor/" + req.ClientId
ret.MqttDevices = make(map[string]Device)
ret.SungrowPsIds = make(map[api.Integer]bool)
}
return &ret
@ -377,15 +383,23 @@ func (m *Mqtt) PublishValue(Type string, subtopic string, value string) error {
// return m.err
// }
func (m *Mqtt) SetDeviceConfig(swname string, id string, name string, model string, vendor string, area string) error {
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)
// id = JoinStringsForId(m.EntityPrefix, id)
m.Device = Device {
Connections: [][]string{
{swname, id},
},
Identifiers: []string{id},
c := [][]string{
{swname, JoinStringsForId(m.EntityPrefix, parentId)},
{JoinStringsForId(m.EntityPrefix, parentId), JoinStringsForId(m.EntityPrefix, id)},
}
if swname == parentId {
c = [][]string{
{parentId, JoinStringsForId(m.EntityPrefix, id)},
}
}
m.MqttDevices[id] = Device {
Connections: c,
Identifiers: []string{JoinStringsForId(m.EntityPrefix, id)},
Manufacturer: vendor,
Model: model,
Name: name,
@ -526,7 +540,7 @@ func (config *EntityConfig) IsLight() bool {
var ok bool
for range Only.Once {
if config.Units == LabelBinarySensor {
if config.Units == LabelLight {
ok = true
break
}

View File

@ -14,21 +14,28 @@ func (m *Mqtt) SwitchPublishConfig(config EntityConfig) error {
break
}
device := m.Device
device.Name = JoinStrings(m.Device.Name, config.ParentId)
device.Connections = [][]string{
{ m.Device.Name, JoinStringsForId(m.Device.Name, config.ParentId) },
{ JoinStringsForId(m.Device.Name, config.ParentId), JoinStringsForId(m.Device.Name, config.ParentId, config.Name) },
// device := m.Device
// device.Name = JoinStrings(m.Device.Name, config.ParentId)
// device.Connections = [][]string{
// { m.Device.Name, 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) }
// st := JoinStringsForId(m.Device.Name, config.ParentId, config.Name)
ok, newDevice := m.NewDevice(config)
if !ok {
break
}
device.Identifiers = []string{ JoinStringsForId(m.Device.Name, config.ParentId) }
st := JoinStringsForId(m.Device.Name, config.ParentId, config.Name)
id := JoinStringsForId(m.DeviceName, config.FullId)
payload := Switch {
Device: device,
Name: JoinStrings(m.Device.Name, config.ParentName, config.FullId),
StateTopic: JoinStringsForTopic(m.binarySensorPrefix, st, "state"),
CommandTopic: JoinStringsForTopic(m.binarySensorPrefix, st, "cmd"),
UniqueId: st,
Device: newDevice,
Name: JoinStrings(m.DeviceName, config.FullId),
StateTopic: JoinStringsForTopic(m.switchPrefix, id, "state"),
CommandTopic: JoinStringsForTopic(m.switchPrefix, id, "cmd"),
UniqueId: id,
Qos: 0,
Retain: true,
@ -56,8 +63,8 @@ func (m *Mqtt) SwitchPublishConfig(config EntityConfig) error {
// PayloadNotAvailable: "",
}
ct := JoinStringsForTopic(m.binarySensorPrefix, st, "config")
t := m.client.Publish(ct, 0, true, payload.Json())
tag := JoinStringsForTopic(m.switchPrefix, id, "config")
t := m.client.Publish(tag, 0, true, payload.Json())
if !t.WaitTimeout(m.Timeout) {
m.err = t.Error()
}
@ -69,17 +76,18 @@ func (m *Mqtt) SwitchPublishConfig(config EntityConfig) error {
func (m *Mqtt) SwitchPublishValue(config EntityConfig) error {
for range Only.Once {
if config.Units != LabelSwitch {
// if config.Units != LabelSwitch {
if !config.IsSwitch() {
break
}
st := JoinStringsForId(m.Device.Name, config.ParentId, config.Name)
id := JoinStringsForId(m.DeviceName, config.FullId)
payload := MqttState {
LastReset: m.GetLastReset(config.UniqueId),
Value: config.Value,
}
st = JoinStringsForTopic(m.binarySensorPrefix, st, "state")
t := m.client.Publish(st, 0, true, payload.Json())
tag := JoinStringsForTopic(m.switchPrefix, id, "state")
t := m.client.Publish(tag, 0, true, payload.Json())
if !t.WaitTimeout(m.Timeout) {
m.err = t.Error()
}