diff --git a/.idea/workspace.xml b/.idea/workspace.xml index cf8d0f35a..73416b3cf 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,9 +5,12 @@ - - + + + + + @@ -15,32 +18,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -118,7 +100,7 @@ - + @@ -224,7 +206,7 @@ file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go - 67 + 68 @@ -507,11 +489,6 @@ 18 - - file://$PROJECT_DIR$/iSolarCloud/highlevel_template.go - 147 - file://$PROJECT_DIR$/iSolarCloud/data_request.go 817 @@ -539,7 +516,7 @@ file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go - 107 + 108 @@ -567,11 +544,6 @@ 594 - - file://$PROJECT_DIR$/cmd/cmd_show_point.go - 74 - file://$PROJECT_DIR$/iSolarCloud/WebIscmAppService/queryDeviceListForBackSys/data.go 55 @@ -584,12 +556,12 @@ file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go - 665 + 547 file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go - 643 + 525 @@ -672,24 +644,19 @@ 261 - - file://$PROJECT_DIR$/iSolarCloud/highlevel_point.go - 318 - file://$PROJECT_DIR$/cmd/cmd_show_device.go - 90 + 96 file://$PROJECT_DIR$/cmd/cmd_show_device.go - 91 + 101 file://$PROJECT_DIR$/cmd/cmd_show_device.go - 59 + 61 @@ -728,24 +695,24 @@ - file://$PROJECT_DIR$/iSolarCloud/highlevel_device.go - 206 - - file://$PROJECT_DIR$/iSolarCloud/highlevel_device.go - 249 - - file://$PROJECT_DIR$/iSolarCloud/highlevel_device.go - 163 - - file://$PROJECT_DIR$/iSolarCloud/highlevel_device.go - 157 - diff --git a/AppService.queryMutiPointDataList.ResultData.Data-Points_p58603.png b/AppService.queryMutiPointDataList.ResultData.Data-Points_p58603.png deleted file mode 100644 index a0546966c..000000000 Binary files a/AppService.queryMutiPointDataList.ResultData.Data-Points_p58603.png and /dev/null differ diff --git a/AppService.queryMutiPointDataList.ResultData.Data-Points_p58604.png b/AppService.queryMutiPointDataList.ResultData.Data-Points_p58604.png deleted file mode 100644 index 56c97819b..000000000 Binary files a/AppService.queryMutiPointDataList.ResultData.Data-Points_p58604.png and /dev/null differ diff --git a/AppService.queryMutiPointDataList.ResultData.Data-Points_p58605.png b/AppService.queryMutiPointDataList.ResultData.Data-Points_p58605.png deleted file mode 100644 index 881d999f0..000000000 Binary files a/AppService.queryMutiPointDataList.ResultData.Data-Points_p58605.png and /dev/null differ diff --git a/AppService.queryMutiPointDataList.ResultData.Data-Points_p58606.png b/AppService.queryMutiPointDataList.ResultData.Data-Points_p58606.png deleted file mode 100644 index 8030d11e7..000000000 Binary files a/AppService.queryMutiPointDataList.ResultData.Data-Points_p58606.png and /dev/null differ diff --git a/README.md b/README.md index 65c0a2976..d95371b88 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,6 @@ # GoSungrow - iSolarCloud API written in GoLang. -Note: I'm currently going through a big refactor. The next major release, (v3.0.0), will: -- support better api changes. This allows a much quicker change in my code when the api changes. -- support multiple devices. Previous versions only allowed query of one device. -- improve cli for queries. Now can fetch endpoints in either "list" or "table" formats, the latter showing point data in a similar fashion to pivot tables in spreadsheets. -- multiple output formats supported - not only csv, png and ascii, but markdown, xml, HTML, sql and plain MQTT. -- lots of bug fixes. :-). +Note: I'm currently going through a big refactor. The next major release, (v3.0.0). [Latest releases here](https://github.com/MickMake/GoSungrow/releases) @@ -14,13 +9,14 @@ Note: I'm currently going through a big refactor. The next major release, (v3.0. ## What is it? -This GoLang package has a complete, (almost complete), implementation of the iSolarCloud API. +This GoLang package has a complete implementation of the iSolarCloud API. There's been no published specs on this, so I've had to figure it all out based on the [Android app](https://play.google.com/store/apps/details?id=com.isolarcloud.manager), using javascript IDEs and various other means. Note: - [iSolarCloud](https://isolarcloud.com) has no interest in developing a public API. - Their "API" implementation is so broken with security and coding issues, I'm surprised it hasn't been exploited yet. - iSolarCloud reached out to me, (based off this GitHub page), to see what can be done about these security issues. So that's a very good thing. +- As of 1st August 2022 I discovered a number of security holes. At which point I notified AusCert, the vendor and a number of other security companies - hopefully they will get patched because my tool makes it very easy. ![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/iSolarCloudLogin.png?raw=true) @@ -50,25 +46,35 @@ I'm currently using it in my [HomeAssistant](https://www.home-assistant.io/) ins ## What state is it in? -This is currently usable for my needs, (seeing all data in [HomeAssistant](https://www.home-assistant.io/)), but there's quite a few API endpoints that need to be implemented for completeness. +It was originally intended for my needs, (seeing all data in [HomeAssistant](https://www.home-assistant.io/)), but there seems to be a big interest in this tool. +So I've spent some time working on the v3.0.0 release. -So far I have mapped out all the API calls. It's tricky as their "API" changes regularly. +v3.0.0 changelog: +- Support better api changes. This allows a much quicker change in my code when the api changes. +- Support multiple devices. Previous versions only allowed query of one device. +- Improve cli for queries. Now can fetch endpoints in either "list" or "table" formats, the latter showing point data in a similar fashion to pivot tables in spreadsheets. +- Multiple output formats supported - not only csv, png and ascii, but markdown, xml, HTML, sql and plain MQTT. +- Lots of bug fixes. :-). + +I have now mapped out all the API calls. All the read-only endpoints are mapped out and fully tested. The write-only calls haven't been tested fully. +It's tricky as their "API" changes regularly; however I've accommodated for quick changes in the v3.0.0 release. + +Most endpoints contain repeated data. The main endpoints that house most of the data I've provided easy commands to access. +Of course, all endpoints are accessible. So go for your life. -I've currently mapped out these API EndPoints. All of the critical read only endpoints are mapped out, with none of the write endpoints. -Most endpoints are a repeat and a lot of the data contained is repeated. -So, in reality 50% of all endpoints are implemented. ``` +-------------------+-------------------+--------------------+------------+ | AREAS | ENABLED ENDPOINTS | DISABLED ENDPOINTS | COVERAGE % | +-------------------+-------------------+--------------------+------------+ -| AliSmsService | 0 | 1 | 0.0 % | -| AppService | 52 | 522 | 10.0 % | -| MttvScreenService | 0 | 30 | 0.0 % | -| PowerPointService | 0 | 1 | 0.0 % | -| WebAppService | 4 | 186 | 2.2 % | -| WebIscmAppService | 0 | 184 | 0.0 % | +| AliSmsService | 1 | 0 | 100 % | +| AppService | 574 | 0 | 100 % | +| MttvScreenService | 30 | 0 | 100 % | +| NullArea | 1 | 0 | 100 % | +| PowerPointService | 1 | 0 | 100 % | +| WebAppService | 190 | 0 | 100 % | +| WebIscmAppService | 184 | 0 | 100 % | | ---------------- | ---------------- | ----------------- | --------- | -| Total | 56 | 924 | 6.1 % | +| Total | 981 | 0 | 100 % | +-------------------+-------------------+--------------------+------------+ ``` @@ -78,9 +84,8 @@ So, in reality 50% of all endpoints are implemented. This GoLang package does several things: 1. Provides ready access to all API calls via a simple get/put framework. 2. MQTT client to push to [HomeAssistant](https://www.home-assistant.io/). -3. Graphing any points data, (over daily, monthly and yearly). -4. Update a GitHub repo with SunGrow PV data, (provide full revision history for any changes made to the SunGrow PV). -5. Update a Google sheet with SunGrow PV data. +3. Graphing any data points, over daily, monthly and yearly with 5 to hour time granularity. +4. Output data to various formats - JSON, CSV, raw, Graphing, XML, XLSX, Markdown, and GoLang structures. ## What is the roadmap? @@ -88,12 +93,15 @@ This GoLang package does several things: I've implemented most of the features I've wanted to, except for... 1. IFTTT support. +The most recent version has changed the code-base substantially, making it a lot more robust to changes in the API JSON schema. + ## Using GoSungrow: ### Config and login. Add your username and password to the config. (See [the website](https://portalau.isolarcloud.com/)) +Once done, it's a case of set and forget. GoSungrow will handle the re-authentication for you. ``` $ ./bin/GoSungrow config write --user=USERNAME --password=PASSWORD Using config file '/Users/mick/.GoSungrow/config.json' @@ -117,204 +125,305 @@ Token File: /Users/mick/.GoSungrow/AppService_login.json ### High level reporting examples. -Produce point-in-time statistics +Show all devices on your iSolarCloud account. ``` -$ ./bin/GoSungrow data get stats -+---------------------+-----------+---------------------------+---------+------+ -| Date | Point Id | Point Name | Value | Unit | -+---------------------+-----------+---------------------------+---------+------+ -| 2022-02-28 11:05:00 | 1129147.0 | Co2 Reduce | 3.589 | kg | -| 2022-02-28 11:05:00 | 1129147.0 | Co2 Reduce Total | 1047 | kg | -| 2022-02-28 11:05:00 | 1129147.0 | Curr Power | 641 | W | -| 2022-02-28 11:05:00 | 1129147.0 | Daily Irradiation | -- | | -| 2022-02-28 11:05:00 | 1129147.0 | Equivalent Hour | 0.36 | Hour | -| 2022-02-28 11:05:00 | 1129147.0 | Es Discharge Energy | 4.8 | kWh | -| 2022-02-28 11:05:00 | 1129147.0 | Es Energy | 1.6 | kWh | -| 2022-02-28 11:05:00 | 1129147.0 | Es Power | 641 | W | -| 2022-02-28 11:05:00 | 1129147.0 | Es Total Discharge Energy | 109.9 | kWh | -| 2022-02-28 11:05:00 | 1129147.0 | Es Total Energy | 106.2 | kWh | -| 2022-02-28 11:05:00 | 1129147.0 | Installed Power Map | 10 | kWp | -| 2022-02-28 11:05:00 | 1129147.0 | Pv Energy | 3.6 | kWh | -| 2022-02-28 11:05:00 | 1129147.0 | Pv Power | 2.291 | kW | -| 2022-02-28 11:05:00 | 1129147.0 | Radiation | -- | | -| 2022-02-28 11:05:00 | 1129147.0 | Today Energy | 3.6 | kWh | -| 2022-02-28 11:05:00 | 1129147.0 | Today Income | 1.346 | AUD | -| 2022-02-28 11:05:00 | 1129147.0 | Total Capacity | 10 | kWp | -| 2022-02-28 11:05:00 | 1129147.0 | Total Energy | 1.05 | MWh | -| 2022-02-28 11:05:00 | 1129147.0 | Total Income | 302.074 | AUD | -| 2022-02-28 11:05:00 | 1129147.0 | Use Energy | 7.6 | kWh | -+---------------------+-----------+---------------------------+---------+------+ +./bin/GoSungrow show ps list +┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓ +┃ Ps Key ┃ Ps Id ┃ Device Type ┃ Device Code ┃ Channel Id ┃ Serial # ┃ Factory Name ┃ Device Model ┃ +┣━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┫ +┃ 1129147_14_1_1 │ 1129147 │ 14 │ 1 │ 1 │ B2192301528 │ SUNGROW │ SH10RT ┃ +┃ 1129147_22_247_1 │ 1129147 │ 22 │ 247 │ 1 │ B2192301528 │ SUNGROW │ WiNet-S ┃ +┃ 1129147_43_2_1 │ 1129147 │ 43 │ 2 │ 1 │ B2192301528 │ SUNGROW │ SBR096 ┃ +┃ 1171348_14_1_2 │ 1171348 │ 14 │ 1 │ 2 │ B2281302388 │ SUNGROW │ SH10RT-V112 ┃ +┃ 1171348_22_247_2 │ 1171348 │ 22 │ 247 │ 2 │ B2281302388 │ SUNGROW │ WiNet-S ┃ +┃ 1171348_43_2_2 │ 1171348 │ 43 │ 2 │ 2 │ B2281302388 │ SUNGROW │ SBR096 ┃ +┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛ ``` +Show the device tree on your iSolarCloud account. +``` +./bin/GoSungrow show ps tree ++ PsId:1129147 PsName:MickMake PsKey:1129147_11_0_0 DeviceName:MickMake Uuid:844763 ++ PsId:1129147 PsName:MickMake PsKey:1129147_11_0_0 DeviceName:MickMake Uuid:844763 ++-- PsId:1129147 PsName:MickMake PsKey:1129147_14_1_1 DeviceName:SH10RT Uuid:844775 ++---- PsId:1129147 PsName:MickMake PsKey:1129147_43_2_1 DeviceName:Battery_001_002 Uuid:1155386 ++ PsId:1129147 PsName:MickMake PsKey:1129147_11_0_0 DeviceName:MickMake Uuid:844763 ++-- PsId:1129147 PsName:MickMake PsKey:1129147_14_1_1 DeviceName:SH10RT Uuid:844775 ++---- PsId:1129147 PsName:MickMake PsKey:1129147_43_2_1 DeviceName:Battery_001_002 Uuid:1155386 ++-- PsId:1129147 PsName:MickMake PsKey:1129147_22_247_1 DeviceName:WiNet-S Uuid:844774 ++ PsId:1171348 PsName:MickMake42 PsKey:1171348_11_0_0 DeviceName:MickMake42 Uuid:1179860 ++-- PsId:1171348 PsName:MickMake42 PsKey:1171348_22_247_2 DeviceName:Communication Module 02_247 Uuid:1179877 ++-- PsId:1171348 PsName:MickMake42 PsKey:1171348_14_1_2 DeviceName:Energy Storage System 02_01 Uuid:1179878 ++---- PsId:1171348 PsName:MickMake42 PsKey:1171348_43_2_2 DeviceName:Battery 02_02 Uuid:1179879 +``` + +List all known data points for all PS on your account. +``` +./bin/GoSungrow show ps points +# Available points: +# Available points: +┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ Id ┃ Name ┃ Unit ┃ Unit Type ┃ Ps Id ┃ Device Type ┃ Device Name ┃ +┣━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +┃ p83001 │ Inverter AC Power Normalization │ kW/kWp │ 43 │ 1129147 │ 11 │ MickMake ┃ +┃ p83002 │ Inverter AC Power │ kW │ 3 │ 1129147 │ 11 │ MickMake ┃ +┃ p83004 │ Inverter Total Yield │ kWh │ 7 │ 1129147 │ 11 │ MickMake ┃ +┃ p83005 │ Daily Equivalent Hours of Meter │ h │ 15 │ 1129147 │ 11 │ MickMake ┃ +┃ p83006 │ Meter Daily Yield │ kWh │ 7 │ 1129147 │ 11 │ MickMake ┃ +┃ p83007 │ Meter PR │ % │ 10 │ 1129147 │ 11 │ MickMake ┃ +┃ p83008 │ Daily Equivalent Hours of Inverter │ h │ 15 │ 1129147 │ 11 │ MickMake ┃ +┃ p83009 │ Daily Yield by Inverter │ kWh │ 7 │ 1129147 │ 11 │ MickMake ┃ +┃ p83010 │ Inverter PR │ % │ 10 │ 1129147 │ 11 │ MickMake ┃ +┃ p83011 │ Meter E-daily Consumption │ kWh │ 7 │ 1129147 │ 11 │ MickMake ┃ + +... + +┃ p58630 │ Min. Cell Voltage of Module 5 │ mV │ 31 │ 1171348 │ 43 │ Battery 02_02 ┃ +┃ p58631 │ Min. Cell Voltage of Module 6 │ mV │ 31 │ 1171348 │ 43 │ Battery 02_02 ┃ +┃ p58632 │ Min. Cell Voltage of Module 7 │ mV │ 31 │ 1171348 │ 43 │ Battery 02_02 ┃ +┃ p58633 │ Min. Cell Voltage of Module 8 │ mV │ 31 │ 1171348 │ 43 │ Battery 02_02 ┃ +┃ p58635 │ DC Contactor State │ │ 999 │ 1171348 │ 43 │ Battery 02_02 ┃ +┃ p58636 │ Fault Module ID │ │ 999 │ 1171348 │ 43 │ Battery 02_02 ┃ +┗━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ +``` + +Produce data table of device_type 22 on ps_id 1171348 between 20221001 and 20221002 at 60 minute increments. +``` +./bin/GoSungrow show ps data 11713482 22 20221001 20221002 60 +------------------------ --------------------- ---------------------------- + Timestamp Ps Key 1171348_22_247_2.p23014 +------------------------ --------------------- ---------------------------- + 2022-10-01 00:00:00 1171348_22_247_2 -- + 2022-10-01 01:00:00 1171348_22_247_2 -- + 2022-10-01 02:00:00 1171348_22_247_2 -- + 2022-10-01 03:00:00 1171348_22_247_2 -- + 2022-10-01 04:00:00 1171348_22_247_2 -- + 2022-10-01 05:00:00 1171348_22_247_2 -- + 2022-10-01 06:00:00 1171348_22_247_2 -- + 2022-10-01 07:00:00 1171348_22_247_2 -- + 2022-10-01 08:00:00 1171348_22_247_2 -- + 2022-10-01 09:00:00 1171348_22_247_2 -- + 2022-10-01 10:00:00 1171348_22_247_2 -- + 2022-10-01 11:00:00 1171348_22_247_2 -- + 2022-10-01 12:00:00 1171348_22_247_2 -- + 2022-10-01 13:00:00 1171348_22_247_2 -- + 2022-10-01 14:00:00 1171348_22_247_2 -68 + 2022-10-01 15:00:00 1171348_22_247_2 -82 + 2022-10-01 16:00:00 1171348_22_247_2 -81 + 2022-10-01 17:00:00 1171348_22_247_2 -81 + 2022-10-01 18:00:00 1171348_22_247_2 -86 + 2022-10-01 19:00:00 1171348_22_247_2 -82 + 2022-10-01 20:00:00 1171348_22_247_2 -90 + 2022-10-01 21:00:00 1171348_22_247_2 -89 + 2022-10-01 22:00:00 1171348_22_247_2 -88 + 2022-10-01 23:00:00 1171348_22_247_2 -86 + 2022-10-02 00:00:00 1171348_22_247_2 -83 +------------------------ --------------------- ---------------------------- +``` + +Do the same, but with a graph! +``` +./bin/GoSungrow show ps graph 1171348 22 20221001 20221002 60 +Found ps_keys: 1129147_14_1_1,1129147_22_247_1,1129147_43_2_1,1171348_14_1_2,1171348_22_247_2,1171348_43_2_2 +Finding points to graph... +Table Headers: Timestamp, Ps Key, 1171348_22_247_2.p23014 +Table rows: 25 +Found 1 points. +Creating graph file 'AppService.queryMutiPointDataList.ResultData.Data-1171348-1171348_22_247_2.p23014.png' +``` +![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService.queryMutiPointDataList.ResultData.Data-1171348-1171348_22_247_2.p23014.png?raw=true) + + Get all defined report templates. ``` -./bin/GoSungrow data get templates -+-------------+---------------+---------------------+ -| Template Id | Template Name | Update On | -+-------------+---------------+---------------------+ -| 8042 | Critical | 2022-02-15 13:00:28 | -| 8041 | extras | 2022-02-15 09:40:04 | -| 8036 | C | 2022-02-15 09:31:35 | -| 8039 | v | 2022-02-15 09:31:10 | -| 8040 | A | 2022-02-15 09:30:56 | -| 8034 | Percent | 2022-02-15 09:30:41 | -| 8038 | MWh | 2022-02-15 09:09:22 | -| 8037 | MW | 2022-02-15 09:03:22 | -| 8033 | kW | 2022-02-15 09:01:19 | -| 8035 | Hours | 2022-02-15 08:55:56 | -| 8031 | kWh | 2022-02-15 07:57:36 | -| 7981 | Power | 2022-02-09 10:03:40 | -+-------------+---------------+---------------------+ +./bin/GoSungrow show template list + +# DataTable AppService.getTemplateList.ResultData.PageList - DataTable AppService.getTemplateList.ResultData.PageList +---------------- ------------------ ------------------------ + Template Id Template Name Update Time +---------------- ------------------ ------------------------ + 7981 Power 2022-02-09 10:03:40 + 8031 kWh 2022-02-15 07:57:36 + 8035 Hours 2022-02-15 08:55:56 + 8033 kW 2022-02-15 09:01:19 + 8037 MW 2022-02-15 09:03:22 + 8038 MWh 2022-02-15 09:09:22 + 8034 Percent 2022-02-15 09:30:41 + 8040 A 2022-02-15 09:30:56 + 8039 v 2022-02-15 09:31:10 + 8036 C 2022-02-15 09:31:35 + 8041 extras 2022-02-15 09:40:04 + 8042 Critical 2022-02-15 13:00:28 + 8092 ALL1 2022-03-09 17:18:21 + 8093 ALL2 2022-03-09 17:20:42 + 8094 ALL3 2022-03-09 17:36:20 + 8095 ALL4 2022-03-09 17:37:56 + 8652 NewAll1 2022-10-04 12:27:00 + 8653 NewAll2 2022-10-04 12:28:58 + 8654 NewAll03 2022-10-04 12:31:39 + 8655 NewAll04 2022-10-04 12:34:51 + 8656 NewAll05 2022-10-04 12:37:34 + 8657 NewAll06 2022-10-04 12:38:27 +---------------- ------------------ ------------------------ ``` + Show all data points used in a report template. ``` -$ ./bin/GoSungrow data get template-points 8040 -+---------+----------------------------+------+ -| PointId | Description | Unit | -+---------+----------------------------+------+ -| p83106 | Load Power | kW | -| p13003 | Total DC Power | kW | -| p13019 | Internal Air Temperature | ℃ | -| p13142 | Battery Health (SOH) | % | -| p13149 | Purchased Power | kW | -| p13150 | Battery Discharging Power | kW | -| p13121 | Total Export Active Power | kW | -| p13126 | Battery Charging Power | kW | -| p13141 | Battery Level (SOC) | % | -| p13143 | Battery Temperature | ℃ | -+---------+----------------------------+------+ +./bin/GoSungrow show template points 8040 + +# DataTable WebAppService.queryUserCurveTemplateData.8040.ResultData.PointsData.Devices.[1129147_14_1_1].Points - TemplateId:8040 +------------- ----------------------------------- ------------ ------------------- ------------ -------------- ------------- --------------- ---------- --------- -------------- + Point Id Point Name Ps Id Ps Key Color Detail Id Ps Name Statistics Style Unit Data List +------------- ----------------------------------- ------------ ------------------- ------------ -------------- ------------- --------------- ---------- --------- -------------- + p13002 MPPT1 Current 1129147 1129147_14_1_1 #FFFF00 123808 MickMake 5 1 A + p13008 Phase A Current 1129147 1129147_14_1_1 #FF0000 123814 MickMake 5 1 A + p13009 Phase B Current 1129147 1129147_14_1_1 #00FF00 123813 MickMake 5 1 A + p13010 Phase C Current 1129147 1129147_14_1_1 #0000FF 123812 MickMake 5 1 A + p13106 MPPT2 Current 1129147 1129147_14_1_1 #70DB93 123807 MickMake 5 1 A + p13139 Battery Current 1129147 1129147_14_1_1 #CD7F32 123806 MickMake 5 1 A + p13162 Max. Charging Current (BMS) 1129147 1129147_14_1_1 #C0C0C0 123805 MickMake 5 1 A + p13163 Max. Discharging Current (BMS) 1129147 1129147_14_1_1 #9F9F9F 123804 MickMake 5 1 A + p18062 Phase A Backup Current 1129147 1129147_14_1_1 #FF00FF 123811 MickMake 5 1 A + p18063 Phase B Backup Current 1129147 1129147_14_1_1 #00FFFF 123810 MickMake 5 1 A + p18064 Phase C Backup Current 1129147 1129147_14_1_1 #000000 123809 MickMake 5 1 A +------------- ----------------------------------- ------------ ------------------- ------------ -------------- ------------- --------------- ---------- --------- -------------- ``` Produce daily report for template 8040 for date 2022/02/24 display on STDOUT. ``` -$ ./bin/GoSungrow data get template 8040 20220224 -+---------------------+-----------------------+----------------------------+-------------+-------+ -| Date/Time | Point Id | Point Name | Value | Units | -+---------------------+-----------------------+----------------------------+-------------+-------+ -| 2022-02-24 00:00:00 | 1129147_11_0_0.p83106 | Load Power | 818.0 | kW | -| 2022-02-24 00:05:00 | 1129147_11_0_0.p83106 | Load Power | 756.0 | kW | -| 2022-02-24 00:10:00 | 1129147_11_0_0.p83106 | Load Power | 571.0 | kW | -| 2022-02-24 00:15:00 | 1129147_11_0_0.p83106 | Load Power | 557.0 | kW | -| 2022-02-24 00:20:00 | 1129147_11_0_0.p83106 | Load Power | 553.0 | kW | -| 2022-02-24 00:25:00 | 1129147_11_0_0.p83106 | Load Power | 558.0 | kW | -| 2022-02-24 00:30:00 | 1129147_11_0_0.p83106 | Load Power | 562.0 | kW | +./bin/GoSungrow show template data 8040 20220204 20220205 120 -... - -+---------------------+-----------------------+----------------------------+-------------+-------+ +# DataTable AppService.queryMutiPointDataList.ResultData.Data - PsId:1129147 StartTimeStamp:20220204000000 EndTimeStamp:20220205000000 MinuteInterval:120 PsKeys:1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1 Points:p13002,p13008,p13162,p18062,p18064,p13009,p13010,p13106,p13139,p13163,p18063 +------------------------ ------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- + Timestamp Ps Key 1129147_14_1_1.p13002 1129147_14_1_1.p13008 1129147_14_1_1.p13009 1129147_14_1_1.p13010 1129147_14_1_1.p13106 1129147_14_1_1.p13139 1129147_14_1_1.p13162 1129147_14_1_1.p13163 1129147_14_1_1.p18062 1129147_14_1_1.p18063 1129147_14_1_1.p18064 +------------------------ ------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- + 2022-02-04 00:00:00 1129147_14_1_1 0 0 0 0 0 0 30 30 0 0.1 0 + 2022-02-04 02:00:00 1129147_14_1_1 0 0 0 0 0 0 30 30 0 0.1 0 + 2022-02-04 04:00:00 1129147_14_1_1 0 0 0 0 0 0 30 30 0 0.1 0 + 2022-02-04 06:00:00 1129147_14_1_1 0 1.38 1.38 1.29 0 4.6 30 28 0 0.1 0 + 2022-02-04 08:00:00 1129147_14_1_1 2.39 3.31 3.31 3.31 6.1 0 30 29 0 0.1 0 + 2022-02-04 10:00:00 1129147_14_1_1 6.35 1.75 1.75 1.75 15.4 24.5 30 30 0 0.1 0 + 2022-02-04 12:00:00 1129147_14_1_1 6.99 9.84 9.94 9.84 19.5 0 0 30 0 0.2 0 + 2022-02-04 14:00:00 1129147_14_1_1 0.64 0.83 0.83 0.83 1.4 0 0 30 0 0.1 0 + 2022-02-04 16:00:00 1129147_14_1_1 0.37 3.13 3.13 3.13 0.8 10.1 20 30 0 0.1 0 + 2022-02-04 18:00:00 1129147_14_1_1 0 1.01 0.92 1.01 0 3.8 30 30 0 0.1 0 + 2022-02-04 20:00:00 1129147_14_1_1 0 1.38 1.47 1.47 0 5.5 30 30 0 0.1 0 + 2022-02-04 22:00:00 1129147_14_1_1 0 0 0 0 0 0 30 30 0 0.1 0 + 2022-02-05 00:00:00 1129147_14_1_1 0 0 0 0 0 0 30 30 0 0.1 0 +------------------------ ------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- -------------------------- ``` -Produce daily report for template 8042 for date 2022/02/24 and save as a JSON file. +And now graph it! ``` -$ ./bin/GoSungrow data save template 8042 20220224 +./bin/GoSungrow show template graph 8040 20220204 20220205 120 +Finding points to graph... +Table Headers: Timestamp, Ps Key, 1129147_14_1_1.p13002, 1129147_14_1_1.p13008, 1129147_14_1_1.p13009, 1129147_14_1_1.p13010, 1129147_14_1_1.p13106, 1129147_14_1_1.p13139, 1129147_14_1_1.p13162, 1129147_14_1_1.p13163, 1129147_14_1_1.p18062, 1129147_14_1_1.p18063, 1129147_14_1_1.p18064 +Table rows: 13 +Found 11 points. +Creating graph file 'AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13002.png' +Creating graph file 'AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13008.png' +Creating graph file 'AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13009.png' +Creating graph file 'AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13010.png' +Creating graph file 'AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13106.png' ``` +![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService.queryMutiPointDataList.ResultData.Data-1171348-1171348_22_247_2.p23014.png?raw=true) +![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13002.png?raw=true) +![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13008.png?raw=true) +![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13139.png?raw=true) +![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13162.png?raw=true) -Produce graph of daily report for template 8040 for date 2022/02/24 and point_id P13019. + +List all possible devices ``` -$ ./bin/GoSungrow data get template-points 8040 -+---------+----------------------------+------+ -| PointId | Description | Unit | -+---------+----------------------------+------+ -| p83106 | Load Power | kW | -| p13003 | Total DC Power | kW | -| p13121 | Total Export Active Power | kW | -| p13142 | Battery Health (SOH) | % | -| p13150 | Battery Discharging Power | kW | -| p13019 | Internal Air Temperature | ℃ | -| p13126 | Battery Charging Power | kW | -| p13141 | Battery Level (SOC) | % | -| p13143 | Battery Temperature | ℃ | -| p13149 | Purchased Power | kW | -+---------+----------------------------+------+ - -$ ./bin/GoSungrow data graph template 8042 20220224 '{"search_string":"p13019"}' -``` -![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService_queryMutiPointDataList-20220224-8042-InternalAirTemperature.png?raw=true) - -Produce graphs of all points from template 8042 for date 2022/02/28 with a different width and height. -``` -$ ./bin/GoSungrow data graph template 8042 20220228 '{"width":2400,"height":500}' -``` -![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService_queryMutiPointDataList-20220228-8042-PurchasedPower.png?raw=true) -![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService_queryMutiPointDataList-20220228-8042-LoadPower.png?raw=true) -![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService_queryMutiPointDataList-20220228-8042-BatteryTemperature.png?raw=true) -![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService_queryMutiPointDataList-20220228-8042-InternalAirTemperature.png?raw=true) -![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService_queryMutiPointDataList-20220228-8042-BatteryChargingPower.png?raw=true) -![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService_queryMutiPointDataList-20220228-8042-BatteryDischargingPower.png?raw=true) - -Produce daily report for point_id p83106 for date 2022/02/24. -``` -$ ./bin/GoSungrow data get points 20220224 1129147_11_0_0.p83106 -+---------------------+-----------------------+------------+--------+-------+ -| Date/Time | Point Id | Point Name | Value | Units | -+---------------------+-----------------------+------------+--------+-------+ -| 2022-02-24 00:00:00 | 1129147_11_0_0.p83106 | | 818.0 | | -| 2022-02-24 00:05:00 | 1129147_11_0_0.p83106 | | 756.0 | | -| 2022-02-24 00:10:00 | 1129147_11_0_0.p83106 | | 571.0 | | -| 2022-02-24 00:15:00 | 1129147_11_0_0.p83106 | | 557.0 | | -| 2022-02-24 00:20:00 | 1129147_11_0_0.p83106 | | 553.0 | | -| 2022-02-24 00:25:00 | 1129147_11_0_0.p83106 | | 558.0 | | -| 2022-02-24 00:30:00 | 1129147_11_0_0.p83106 | | 562.0 | | -| 2022-02-24 00:35:00 | 1129147_11_0_0.p83106 | | 561.0 | | - -... - -+---------------------+-----------------------+------------+--------+-------+ -``` - -Get all point ids by device_type. -``` -+-------------+------------+----------+----------------------------------------+ -| Device Type | Point Type | Point Id | Point Name | -+-------------+------------+----------+----------------------------------------+ -| 1 | 2 | 1 | Daily Yield | -| 1 | 1 | 24 | Total Active Power | -| 1 | 1 | 2 | Total Yield | -| 1 | 1 | 14 | Total DC Power | -| 1 | 1 | 18 | Phase A Voltage | -| 1 | 1 | 19 | Phase B Voltage | -| 1 | 1 | 20 | Phase C Voltage | -| 1 | 1 | 21 | Phase A Current | -| 1 | 1 | 22 | Phase B Current | -| 1 | 1 | 23 | Phase C Current | -| 1 | 1 | 25 | Total Reactive Power | -| 1 | 1 | 27 | Grid Frequency | -| 1 | 1 | 15 | A-B Line Voltage | -| 1 | 1 | 16 | B-C Line Voltage | -| 1 | 1 | 17 | C-A Line Voltage | -| 1 | 1 | 4 | Internal Air Temperature | -| 1 | 1 | 26 | Total Power Factor | -| 1 | 1 | 90 | Negative Voltage to Ground | -| 1 | 1 | 43 | Total Apparent Power | -| 1 | 1 | 33 | Module 1 Temperature | -| 1 | 1 | 34 | Module 2 Temperature | -| 1 | 1 | 39 | Positive Impedance to Ground | -| 1 | 1 | 40 | Negative Impedance to Ground | -| 1 | 1 | 41 | P-limit-actual | -| 1 | 1 | 42 | Reactive Power Regulation Actual Value | -| 1 | 2 | 67 | Daily Yield (Theoretical) | -| 1 | 1 | 5 | MPPT1 Voltage | -| 1 | 1 | 6 | MPPT1 Current | -| 1 | 1 | 7 | MPPT2 Voltage | -| 1 | 1 | 8 | MPPT2 Current | -| 1 | 1 | 70 | String 1 Current | -| 1 | 1 | 71 | String 2 Current | -| 1 | 1 | 72 | String 3 Current | -| 1 | 1 | 73 | String 4 Current | -| 1 | 1 | 74 | String 5 Current | -| 1 | 1 | 75 | String 6 Current | -| 1 | 1 | 76 | String 7 Current | - -... - -+-------------+------------+----------+----------------------------------------+ +./bin/GoSungrow show device list +# Available points: +┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +┃ Device Type ┃ Name ┃ +┣━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +┃ 1 │ Inverter ┃ +┃ 10 │ String ┃ +┃ 11 │ Plant ┃ +┃ 12 │ Circuit Protection ┃ +┃ 13 │ Splitting Device ┃ +┃ 14 │ Energy Storage System ┃ +┃ 15 │ Sampling Device ┃ +┃ 16 │ EMU ┃ +┃ 17 │ Unit ┃ +┃ 18 │ Temperature and Humidity Sensor ┃ +┃ 19 │ Intelligent Power Distribution Cabinet ┃ +┃ 20 │ Display Device ┃ +┃ 21 │ AC Power Distributed Cabinet ┃ +┃ 22 │ Communication Module ┃ +┃ 23 │ System-BMS ┃ +┃ 24 │ RackBMS ┃ +┃ 25 │ DC-DC ┃ +┃ 26 │ Energy Management System ┃ +┃ 28 │ Wind Energy Converter ┃ +┃ 29 │ SVG ┃ +┃ 3 │ Grid-connection Point ┃ +┃ 30 │ PT Cabinet ┃ +┃ 31 │ Bus Protection ┃ +┃ 32 │ Cleaning Robot ┃ +┃ 33 │ Direct Current Cabinet ┃ +┃ 34 │ Public Measurement and Control ┃ +┃ 35 │ Anti-islanding Protection Device ┃ +┃ 36 │ Frequency and Voltage Emergency Control Device ┃ +┃ 37 │ PCS ┃ +┃ 38 │ Cell BMS ┃ +┃ 39 │ Power Quality ┃ +┃ 4 │ Combiner Box ┃ +┃ 40 │ Shuttle ┃ +┃ 41 │ Optimizer ┃ +┃ 42 │ Tracking axis communication box ┃ +┃ 43 │ Battery ┃ +┃ 44 │ Battery Cluster Management Unit ┃ +┃ 45 │ Local Controller ┃ +┃ 46 │ Networking Devices ┃ +┃ 47 │ Energy Storage Unit ┃ +┃ 48 │ DC Container ┃ +┃ 5 │ Meteo Station ┃ +┃ 50 │ IO Module ┃ +┃ 51 │ Charger ┃ +┃ 52 │ Battery System Controller ┃ +┃ 6 │ Transformer ┃ +┃ 7 │ Meter ┃ +┃ 8 │ UPS ┃ +┃ 9 │ Data Logger ┃ +┃ 99 │ Others ┃ +┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ``` Get mains power frequency variation graph from template id 8041 on date 2022/02/28 ``` -./bin/GoSungrow data graph template 8041 20220228 '{"search_string":"p13007","min_left_axis":49,"max_left_axis":51}' +./bin/GoSungrow show point data 20220301 20220302 120 1129147_14_1_1.p13007 + +# DataTable AppService.queryMutiPointDataList.ResultData.Data - PsKeys:1129147_14_1_1 Points:p13007 PsId:1129147 StartTimeStamp:20220301000000 EndTimeStamp:20220302000000 MinuteInterval:120 +------------------------ ------------------- -------------------------- + Timestamp Ps Key 1129147_14_1_1.p13007 +------------------------ ------------------- -------------------------- + 2022-03-01 00:00:00 1129147_14_1_1 49.969997 + 2022-03-01 02:00:00 1129147_14_1_1 49.98 + 2022-03-01 04:00:00 1129147_14_1_1 50.01 + 2022-03-01 06:00:00 1129147_14_1_1 49.98 + 2022-03-01 08:00:00 1129147_14_1_1 49.98 + 2022-03-01 10:00:00 1129147_14_1_1 50.01 + 2022-03-01 12:00:00 1129147_14_1_1 50 + 2022-03-01 14:00:00 1129147_14_1_1 50.02 + 2022-03-01 16:00:00 1129147_14_1_1 49.96 + 2022-03-01 18:00:00 1129147_14_1_1 50.01 + 2022-03-01 20:00:00 1129147_14_1_1 50 + 2022-03-01 22:00:00 1129147_14_1_1 49.969997 + 2022-03-02 00:00:00 1129147_14_1_1 50.01 +------------------------ ------------------- -------------------------- + +./bin/GoSungrow show point graph 20220301 20220302 120 1129147_14_1_1.p13007 +Finding points to graph... +Table Headers: Timestamp, Ps Key, 1129147_14_1_1.p13007 +Table rows: 13 +Found 1 points. +Creating graph file 'AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13007.png' ``` -![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService_queryMutiPointDataList-20220228-8041-GridFrequency.png?raw=true) +![alt text](https://github.com/MickMake/GoSungrow/blob/master/docs/AppService.queryMutiPointDataList.ResultData.Data-1129147-1129147_14_1_1.p13007.png?raw=true) ### Using the API instead. diff --git a/cmd/cmd_data.go b/cmd/cmd_data.go index 325389c99..ff0ae95d3 100644 --- a/cmd/cmd_data.go +++ b/cmd/cmd_data.go @@ -180,6 +180,22 @@ func (c *CmdData) AttachCommand(cmd *cobra.Command) *cobra.Command { c.SelfCmd.AddCommand(cmdApiXLSX) cmdApiXLSX.Example = cmdHelp.PrintExamples(cmdApiXLSX, "queryDeviceList", "WebAppService.showPSView") + // ******************************************************************************** // + var cmdApiMarkDown = &cobra.Command{ + Use: output.StringTypeMarkDown + " <[area.]endpoint> [endpoint args ...]", + Aliases: []string{}, + Annotations: map[string]string{"group": "Data"}, + Short: fmt.Sprintf("Get data from the Sungrow api (MarkDown)"), + Long: fmt.Sprintf("Get data from the Sungrow api (MarkDown)"), + DisableFlagParsing: false, + DisableFlagsInUseLine: false, + PreRunE: cmds.SunGrowArgs, + RunE: c.GetEndpoints, + Args: cobra.MinimumNArgs(0), + } + c.SelfCmd.AddCommand(cmdApiMarkDown) + cmdApiMarkDown.Example = cmdHelp.PrintExamples(cmdApiMarkDown, "queryDeviceList", "WebAppService.showPSView") + // ******************************************************************************** // var cmdApiStruct = &cobra.Command{ Use: output.StringTypeStruct + " <[area.]endpoint> [endpoint args ...]", @@ -207,6 +223,9 @@ func (c *CmdData) GetEndpoints(cmd *cobra.Command, args []string) error { if cmd.Name() == output.StringTypeXLSX { cmds.Api.SaveFile = true } + if cmd.Name() == output.StringTypeGraph { + cmds.Api.SaveFile = true + } args = MinimumArraySize(2, args) eps := iSolarCloud.SplitArg(args[0]) diff --git a/cmd/cmd_info.go b/cmd/cmd_info.go index 4e2ca98e4..fb330051c 100644 --- a/cmd/cmd_info.go +++ b/cmd/cmd_info.go @@ -127,6 +127,25 @@ func (c *CmdInfo) AttachCommand(cmd *cobra.Command) *cobra.Command { cmdInfoCsv.Example = cmdHelp.PrintExamples(cmdInfoCsv, "[area.]") c.AttachCmdInfo(cmdInfoCsv) + // ******************************************************************************** + var cmdInfoMarkDown = &cobra.Command{ + Use: output.StringTypeMarkDown, + Aliases: []string{}, + Annotations: map[string]string{"group": "Info"}, + Short: fmt.Sprintf("Get info from iSolarCloud (MarkDown)"), + Long: fmt.Sprintf("Get info from iSolarCloud (MarkDown)"), + DisableFlagParsing: false, + DisableFlagsInUseLine: false, + PreRunE: cmds.SunGrowArgs, + RunE: func(cmd *cobra.Command, args []string) error { + return cmd.Help() + }, + Args: cobra.MinimumNArgs(1), + } + c.SelfCmd.AddCommand(cmdInfoMarkDown) + cmdInfoMarkDown.Example = cmdHelp.PrintExamples(cmdInfoMarkDown, "[area.]") + c.AttachCmdInfo(cmdInfoMarkDown) + // // ******************************************************************************** // var cmdInfoPut = &cobra.Command{ // Use: "put", diff --git a/cmd/cmd_show.go b/cmd/cmd_show.go index 1e41ed02f..9200c5612 100644 --- a/cmd/cmd_show.go +++ b/cmd/cmd_show.go @@ -26,13 +26,12 @@ func (c *CmdShow) AttachCommand(cmd *cobra.Command) *cobra.Command { } c.cmd = cmd - // ******************************************************************************** // c.SelfCmd = &cobra.Command{ Use: "show", Aliases: []string{}, Annotations: map[string]string{"group": "Show"}, - Short: fmt.Sprintf("Helpful Sungrow functions."), - Long: fmt.Sprintf("Helpful Sungrow functions."), + Short: fmt.Sprintf("High-level Sungrow commands."), + Long: fmt.Sprintf("High-level Sungrow commands."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: func(cmd *cobra.Command, args []string) error { @@ -56,8 +55,8 @@ func (c *CmdShow) AttachCommand(cmd *cobra.Command) *cobra.Command { c.AttachPsId(c.SelfCmd) c.AttachDevice(c.SelfCmd) - c.AttachPoint(c.SelfCmd) c.AttachTemplate(c.SelfCmd) + c.AttachPoint(c.SelfCmd) } return c.SelfCmd } diff --git a/cmd/cmd_show_device.go b/cmd/cmd_show_device.go index 0d6cd4175..8cd4184f5 100644 --- a/cmd/cmd_show_device.go +++ b/cmd/cmd_show_device.go @@ -14,8 +14,8 @@ func (c *CmdShow) AttachDevice(cmd *cobra.Command) *cobra.Command { Use: "device", Aliases: []string{}, Annotations: map[string]string{"group": "Device"}, - Short: fmt.Sprintf("Sungrow devices."), - Long: fmt.Sprintf("Sungrow devices."), + Short: fmt.Sprintf("Device related Sungrow commands."), + Long: fmt.Sprintf("Device related Sungrow commands."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, @@ -29,6 +29,8 @@ func (c *CmdShow) AttachDevice(cmd *cobra.Command) *cobra.Command { c.AttachDeviceList(self) c.AttachDevicePoints(self) + c.AttachDeviceData(self) + c.AttachDeviceGraph(self) c.AttachDeviceModels(self) } return c.SelfCmd @@ -36,8 +38,7 @@ func (c *CmdShow) AttachDevice(cmd *cobra.Command) *cobra.Command { func (c *CmdShow) AttachDeviceList(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** - var c2 = &cobra.Command{ + var self = &cobra.Command{ Use: "list", Aliases: []string{"ls"}, Annotations: map[string]string{"group": "Device"}, @@ -49,36 +50,40 @@ func (c *CmdShow) AttachDeviceList(cmd *cobra.Command) *cobra.Command { RunE: c.funcDeviceTypeList, Args: cobra.MinimumNArgs(0), } - cmd.AddCommand(c2) - c2.Example = cmdHelp.PrintExamples(c2, "") + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, "") return cmd } func (c *CmdShow) funcDeviceTypeList(_ *cobra.Command, args []string) error { for range Only.Once { cmds.Api.SunGrow.OutputType.SetTable() - ret := cmds.Api.SunGrow.DeviceTypeList() + var ret string + ret, c.Error = cmds.Api.SunGrow.DeviceTypeList() + if c.Error != nil { + break + } + fmt.Println(ret) } return c.Error } func (c *CmdShow) AttachDevicePoints(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** - var c2 = &cobra.Command{ + var self = &cobra.Command{ Use: "points ", Aliases: []string{"point"}, Annotations: map[string]string{"group": "Device"}, - Short: fmt.Sprintf("List data points used by a device."), - Long: fmt.Sprintf("List data points used by a device."), + Short: fmt.Sprintf("List points used for a given device_type."), + Long: fmt.Sprintf("List points used for a given device_type."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, RunE: c.funcDevicePoints, Args: cobra.MinimumNArgs(1), } - cmd.AddCommand(c2) - c2.Example = cmdHelp.PrintExamples(c2, + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, "1", "11", ) @@ -88,19 +93,24 @@ func (c *CmdShow) AttachDevicePoints(cmd *cobra.Command) *cobra.Command { func (c *CmdShow) funcDevicePoints(_ *cobra.Command, args []string) error { for range Only.Once { cmds.Api.SunGrow.OutputType.SetTable() - ret := cmds.Api.SunGrow.DevicePoints(args...) + var ret string + ret, c.Error = cmds.Api.SunGrow.DeviceTypePoints(args...) + if c.Error != nil { + break + } + fmt.Println(ret) } return c.Error } func (c *CmdShow) AttachDeviceData(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** var self = &cobra.Command{ Use: "data [start date] [end date] [interval]", + Aliases: []string{}, Annotations: map[string]string{"group": "Device"}, - Short: fmt.Sprintf("Get data from report template."), - Long: fmt.Sprintf("Get data from report template."), + Short: fmt.Sprintf("Generate points table for a given device_type."), + Long: fmt.Sprintf("Generate points table for a given device_type."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, @@ -122,22 +132,22 @@ func (c *CmdShow) funcDeviceData(_ *cobra.Command, args []string) error { for range Only.Once { cmds.Api.SunGrow.OutputType.SetTable() args = MinimumArraySize(4, args) - c.Error = cmds.Api.SunGrow.DeviceData(args[0], args[1], args[2], args[3]) + c.Error = cmds.Api.SunGrow.DeviceTypeData(args[0], args[1], args[2], args[3]) } return c.Error } -func (c *CmdShow) AttachDeviceDataGraph(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** +func (c *CmdShow) AttachDeviceGraph(cmd *cobra.Command) *cobra.Command { var self = &cobra.Command{ - Use: "data-graph [start date] [end date] [interval]", + Use: "graph [start date] [end date] [interval]", + Aliases: []string{}, Annotations: map[string]string{"group": "Device"}, - Short: fmt.Sprintf("Get data from report template."), - Long: fmt.Sprintf("Get data from report template."), + Short: fmt.Sprintf("Generate graphs of points for a given device_type."), + Long: fmt.Sprintf("Generate graphs of points for a given device_type."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, - RunE: c.funcDeviceDataGraph, + RunE: c.funcDeviceGraph, Args: cobra.MinimumNArgs(1), } cmd.AddCommand(self) @@ -151,18 +161,17 @@ func (c *CmdShow) AttachDeviceDataGraph(cmd *cobra.Command) *cobra.Command { return cmd } -func (c *CmdShow) funcDeviceDataGraph(_ *cobra.Command, args []string) error { +func (c *CmdShow) funcDeviceGraph(_ *cobra.Command, args []string) error { for range Only.Once { cmds.Api.SunGrow.OutputType.SetGraph() args = MinimumArraySize(4, args) - c.Error = cmds.Api.SunGrow.DeviceData(args[0], args[1], args[2], args[3]) + c.Error = cmds.Api.SunGrow.DeviceTypeData(args[0], args[1], args[2], args[3]) } return c.Error } func (c *CmdShow) AttachDeviceModels(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** - var c2 = &cobra.Command{ + var self = &cobra.Command{ Use: "models", Aliases: []string{"model"}, Annotations: map[string]string{"group": "Device"}, @@ -174,14 +183,14 @@ func (c *CmdShow) AttachDeviceModels(cmd *cobra.Command) *cobra.Command { RunE: c.funcDeviceModels, Args: cobra.MinimumNArgs(0), } - cmd.AddCommand(c2) - c2.Example = cmdHelp.PrintExamples(c2, "") + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, "") return cmd } func (c *CmdShow) funcDeviceModels(_ *cobra.Command, _ []string) error { for range Only.Once { - // _ = cmds.SetOutputType(cmd) + cmds.Api.SunGrow.OutputType.SetTable() c.Error = cmds.Api.SunGrow.DeviceModelInfoList() } return c.Error diff --git a/cmd/cmd_show_point.go b/cmd/cmd_show_point.go index 46f1e3e6c..e2b1f4c4a 100644 --- a/cmd/cmd_show_point.go +++ b/cmd/cmd_show_point.go @@ -5,7 +5,6 @@ import ( "github.com/MickMake/GoUnify/Only" "github.com/MickMake/GoUnify/cmdHelp" "github.com/spf13/cobra" - "strings" ) @@ -15,8 +14,8 @@ func (c *CmdShow) AttachPoint(cmd *cobra.Command) *cobra.Command { Use: "point", Aliases: []string{}, Annotations: map[string]string{"group": "Point"}, - Short: fmt.Sprintf("General iSolarCloud functions."), - Long: fmt.Sprintf("General iSolarCloud functions."), + Short: fmt.Sprintf("Point related Sungrow commands."), + Long: fmt.Sprintf("Point related Sungrow commands."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, @@ -41,7 +40,7 @@ func (c *CmdShow) AttachPoint(cmd *cobra.Command) *cobra.Command { c.AttachPointTemplateGraph(self) c.AttachPointData(self) - c.AttachPointDataGraph(self) + c.AttachPointGraph(self) c.AttachPointScan(self) } @@ -59,7 +58,7 @@ func (c *CmdShow) AttachPointPs(cmd *cobra.Command) *cobra.Command { DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, - RunE: c.funcPointPs, + RunE: c.funcAttachPsPoints, Args: cobra.MinimumNArgs(0), } cmd.AddCommand(self) @@ -67,22 +66,10 @@ func (c *CmdShow) AttachPointPs(cmd *cobra.Command) *cobra.Command { return cmd } -func (c *CmdShow) funcPointPs(_ *cobra.Command, args []string) error { - for range Only.Once { - cmds.Api.SunGrow.OutputType.SetTable() - args = MinimumArraySize(2, args) - points := cmds.Api.SunGrow.PointNames(strings.Split(args[0], ","), args[1]) - if c.Error != nil { - break - } - fmt.Printf("%s\n", points) - } - return c.Error -} func (c *CmdShow) AttachPointPsTable(cmd *cobra.Command) *cobra.Command { var self = &cobra.Command{ - Use: "ps-table (start) (end) ", + Use: "ps-data (start) (end) ", Aliases: []string{}, Annotations: map[string]string{"group": "Point"}, Short: fmt.Sprintf("Generate points table for a given ps_id."), @@ -90,7 +77,7 @@ func (c *CmdShow) AttachPointPsTable(cmd *cobra.Command) *cobra.Command { DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, - RunE: c.funcPointPsTable, + RunE: c.funcAttachPsData, Args: cobra.MinimumNArgs(0), } cmd.AddCommand(self) @@ -103,17 +90,6 @@ func (c *CmdShow) AttachPointPsTable(cmd *cobra.Command) *cobra.Command { return cmd } -func (c *CmdShow) funcPointPsTable(_ *cobra.Command, args []string) error { - for range Only.Once { - cmds.Api.SunGrow.OutputType.SetTable() - args = MinimumArraySize(5, args) - _ = cmds.Api.SunGrow.PointNamesData(strings.Split(args[0], ","), args[1], args[2], args[3], args[4]) - if c.Error != nil { - break - } - } - return c.Error -} func (c *CmdShow) AttachPointPsGraph(cmd *cobra.Command) *cobra.Command { var self = &cobra.Command{ @@ -125,7 +101,7 @@ func (c *CmdShow) AttachPointPsGraph(cmd *cobra.Command) *cobra.Command { DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, - RunE: c.funcPointPsGraph, + RunE: c.funcAttachPsGraph, Args: cobra.MinimumNArgs(0), } cmd.AddCommand(self) @@ -138,96 +114,10 @@ func (c *CmdShow) AttachPointPsGraph(cmd *cobra.Command) *cobra.Command { return cmd } -func (c *CmdShow) funcPointPsGraph(_ *cobra.Command, args []string) error { - for range Only.Once { - cmds.Api.SunGrow.OutputType.SetGraph() - args = MinimumArraySize(5, args) - _ = cmds.Api.SunGrow.PointNamesData(strings.Split(args[0], ","), args[1], args[2], args[3], args[4]) - if c.Error != nil { - break - } - } - return c.Error -} - - -func (c *CmdShow) AttachPointTemplate(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** - var c2 = &cobra.Command{ - Use: "template ", - Aliases: []string{}, - Annotations: map[string]string{"group": "Point"}, - Short: fmt.Sprintf("List data points used by a report template."), - Long: fmt.Sprintf("List data points used by a report template."), - DisableFlagParsing: false, - DisableFlagsInUseLine: false, - PreRunE: cmds.SunGrowArgs, - RunE: c.funcTemplatePoints, - Args: cobra.ExactArgs(1), - } - cmd.AddCommand(c2) - c2.Example = cmdHelp.PrintExamples(c2, - "8042", - "8040", - ) - - return cmd -} - -func (c *CmdShow) AttachPointTemplateTable(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** - var self = &cobra.Command{ - Use: "template-data [start date] [end date] [interval]", - Annotations: map[string]string{"group": "Template"}, - Short: fmt.Sprintf("Generate points table for a given report template."), - Long: fmt.Sprintf("Generate points table for a given report template."), - DisableFlagParsing: false, - DisableFlagsInUseLine: false, - PreRunE: cmds.SunGrowArgs, - RunE: c.funcTemplateData, - Args: cobra.MinimumNArgs(1), - } - cmd.AddCommand(self) - self.Example = cmdHelp.PrintExamples(self, - "8092 20221201 20221202 30", - "8092 20221201 20221202 5", - "8092 20221201 20221202", - "8092 20221201", - "8092", - ) - - return cmd -} - -func (c *CmdShow) AttachPointTemplateGraph(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** - var self = &cobra.Command{ - Use: "template-graph [start date] [end date] [interval]", - Annotations: map[string]string{"group": "Template"}, - Short: fmt.Sprintf("Generate graphs of points for a given report template."), - Long: fmt.Sprintf("Generate graphs of points for a given report template."), - DisableFlagParsing: false, - DisableFlagsInUseLine: false, - PreRunE: cmds.SunGrowArgs, - RunE: c.funcTemplateData, - Args: cobra.MinimumNArgs(1), - } - cmd.AddCommand(self) - self.Example = cmdHelp.PrintExamples(self, - "8092 20221201 20221202 30", - "8092 20221201 20221202 5", - "8092 20221201 20221202", - "8092 20221201", - "8092", - ) - - return cmd -} func (c *CmdShow) AttachPointDevice(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** - var c2 = &cobra.Command{ + var self = &cobra.Command{ Use: "device ", Aliases: []string{"devices"}, Annotations: map[string]string{"group": "Point"}, @@ -239,8 +129,8 @@ func (c *CmdShow) AttachPointDevice(cmd *cobra.Command) *cobra.Command { RunE: c.funcDevicePoints, Args: cobra.ExactArgs(1), } - cmd.AddCommand(c2) - c2.Example = cmdHelp.PrintExamples(c2, + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, "1", "11", ) @@ -249,10 +139,9 @@ func (c *CmdShow) AttachPointDevice(cmd *cobra.Command) *cobra.Command { } func (c *CmdShow) AttachPointDeviceTable(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** var self = &cobra.Command{ Use: "device-data [start date] [end date] [interval]", - Annotations: map[string]string{"group": "Template"}, + Annotations: map[string]string{"group": "Point"}, Short: fmt.Sprintf("Generate points table for a given device."), Long: fmt.Sprintf("Generate points table for a given device."), DisableFlagParsing: false, @@ -274,10 +163,9 @@ func (c *CmdShow) AttachPointDeviceTable(cmd *cobra.Command) *cobra.Command { } func (c *CmdShow) AttachPointDeviceGraph(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** var self = &cobra.Command{ Use: "device-graph [start date] [end date] [interval]", - Annotations: map[string]string{"group": "Template"}, + Annotations: map[string]string{"group": "Point"}, Short: fmt.Sprintf("Generate graphs of points for a given device."), Long: fmt.Sprintf("Generate graphs of points for a given device."), DisableFlagParsing: false, @@ -299,37 +187,74 @@ func (c *CmdShow) AttachPointDeviceGraph(cmd *cobra.Command) *cobra.Command { } -func (c *CmdShow) AttachPointScan(cmd *cobra.Command) *cobra.Command { +func (c *CmdShow) AttachPointTemplate(cmd *cobra.Command) *cobra.Command { var self = &cobra.Command{ - Use: "scan [min] [max]", + Use: "template ", Aliases: []string{}, Annotations: map[string]string{"group": "Point"}, - Short: fmt.Sprintf("Scan full list of points."), - Long: fmt.Sprintf("Scan full list of points."), + Short: fmt.Sprintf("List data points used by a report template."), + Long: fmt.Sprintf("List data points used by a report template."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, - RunE: c.funcPointScan, - Args: cobra.MinimumNArgs(2), + RunE: c.funcTemplatePoints, + Args: cobra.ExactArgs(1), } cmd.AddCommand(self) self.Example = cmdHelp.PrintExamples(self, - "1 1000", - ) + "8042", + "8040", + ) return cmd } -func (c *CmdShow) funcPointScan(_ *cobra.Command, args []string) error { - for range Only.Once { - cmds.Api.SunGrow.OutputType.SetTable() - args = MinimumArraySize(2, args) - points := cmds.Api.SunGrow.PointScan(args[0], args[1]) - if c.Error != nil { - break - } - fmt.Printf("%s\n", points) + +func (c *CmdShow) AttachPointTemplateTable(cmd *cobra.Command) *cobra.Command { + var self = &cobra.Command{ + Use: "template-data [start date] [end date] [interval]", + Annotations: map[string]string{"group": "Point"}, + Short: fmt.Sprintf("Generate points table for a given report template."), + Long: fmt.Sprintf("Generate points table for a given report template."), + DisableFlagParsing: false, + DisableFlagsInUseLine: false, + PreRunE: cmds.SunGrowArgs, + RunE: c.funcTemplateData, + Args: cobra.MinimumNArgs(1), } - return c.Error + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, + "8092 20221201 20221202 30", + "8092 20221201 20221202 5", + "8092 20221201 20221202", + "8092 20221201", + "8092", + ) + + return cmd +} + +func (c *CmdShow) AttachPointTemplateGraph(cmd *cobra.Command) *cobra.Command { + var self = &cobra.Command{ + Use: "template-graph [start date] [end date] [interval]", + Annotations: map[string]string{"group": "Point"}, + Short: fmt.Sprintf("Generate graphs of points for a given report template."), + Long: fmt.Sprintf("Generate graphs of points for a given report template."), + DisableFlagParsing: false, + DisableFlagsInUseLine: false, + PreRunE: cmds.SunGrowArgs, + RunE: c.funcTemplateData, + Args: cobra.MinimumNArgs(1), + } + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, + "8092 20221201 20221202 30", + "8092 20221201 20221202 5", + "8092 20221201 20221202", + "8092 20221201", + "8092", + ) + + return cmd } @@ -358,7 +283,7 @@ func (c *CmdShow) funcPointData(_ *cobra.Command, args []string) error { for range Only.Once { cmds.Api.SunGrow.OutputType.SetTable() args = MinimumArraySize(4, args) - cmds.Api.SunGrow.PointData(args[0], args[1], args[2], args[3:]...) + c.Error = cmds.Api.SunGrow.PointData(args[0], args[1], args[2], args[3:]...) if c.Error != nil { break } @@ -366,17 +291,17 @@ func (c *CmdShow) funcPointData(_ *cobra.Command, args []string) error { return c.Error } -func (c *CmdShow) AttachPointDataGraph(cmd *cobra.Command) *cobra.Command { +func (c *CmdShow) AttachPointGraph(cmd *cobra.Command) *cobra.Command { var self = &cobra.Command{ - Use: "data-graph (start) (end) ", + Use: "graph (start) (end) ", Aliases: []string{}, Annotations: map[string]string{"group": "Point"}, - Short: fmt.Sprintf("Get data points."), - Long: fmt.Sprintf("Get data points."), + Short: fmt.Sprintf("Graph data points."), + Long: fmt.Sprintf("Graph data points."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, - RunE: c.funcPointDataGraph, + RunE: c.funcPointGraph, Args: cobra.MinimumNArgs(4), } cmd.AddCommand(self) @@ -387,14 +312,50 @@ func (c *CmdShow) AttachPointDataGraph(cmd *cobra.Command) *cobra.Command { return cmd } -func (c *CmdShow) funcPointDataGraph(_ *cobra.Command, args []string) error { +func (c *CmdShow) funcPointGraph(_ *cobra.Command, args []string) error { for range Only.Once { cmds.Api.SunGrow.OutputType.SetGraph() args = MinimumArraySize(4, args) - cmds.Api.SunGrow.PointData(args[0], args[1], args[2], args[3:]...) + c.Error = cmds.Api.SunGrow.PointData(args[0], args[1], args[2], args[3:]...) if c.Error != nil { break } } return c.Error } + + +func (c *CmdShow) AttachPointScan(cmd *cobra.Command) *cobra.Command { + var self = &cobra.Command{ + Use: "scan [min] [max]", + Aliases: []string{}, + Annotations: map[string]string{"group": "Point"}, + Short: fmt.Sprintf("Scan full list of points."), + Long: fmt.Sprintf("Scan full list of points."), + DisableFlagParsing: false, + DisableFlagsInUseLine: false, + PreRunE: cmds.SunGrowArgs, + RunE: c.funcPointScan, + Args: cobra.MinimumNArgs(2), + } + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, + "1 1000", + ) + + return cmd +} +func (c *CmdShow) funcPointScan(_ *cobra.Command, args []string) error { + for range Only.Once { + cmds.Api.SunGrow.OutputType.SetTable() + args = MinimumArraySize(2, args) + var points string + points, c.Error = cmds.Api.SunGrow.PointScan(args[0], args[1]) + if c.Error != nil { + break + } + + fmt.Printf("%s\n", points) + } + return c.Error +} diff --git a/cmd/cmd_show_psid.go b/cmd/cmd_show_psid.go index e033edf79..b43fff2d8 100644 --- a/cmd/cmd_show_psid.go +++ b/cmd/cmd_show_psid.go @@ -16,8 +16,8 @@ func (c *CmdShow) AttachPsId(cmd *cobra.Command) *cobra.Command { Use: "ps", Aliases: []string{}, Annotations: map[string]string{"group": "PsId"}, - Short: fmt.Sprintf("General iSolarCloud functions."), - Long: fmt.Sprintf("General iSolarCloud functions."), + Short: fmt.Sprintf("Ps related Sungrow commands."), + Long: fmt.Sprintf("Ps related Sungrow commands."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, @@ -29,24 +29,27 @@ func (c *CmdShow) AttachPsId(cmd *cobra.Command) *cobra.Command { cmd.AddCommand(self) self.Example = cmdHelp.PrintExamples(self, "") - c.AttachPsIdList(self) + c.AttachPsList(self) c.AttachPsTree(self) c.AttachPsPoints(self) + c.AttachPsData(self) + c.AttachPsGraph(self) } return c.SelfCmd } -func (c *CmdShow) AttachPsIdList(cmd *cobra.Command) *cobra.Command { + +func (c *CmdShow) AttachPsList(cmd *cobra.Command) *cobra.Command { var self = &cobra.Command{ Use: "list", Aliases: []string{"ls"}, - Annotations: map[string]string{"group": "Device"}, + Annotations: map[string]string{"group": "PsId"}, Short: fmt.Sprintf("Show all devices on account."), Long: fmt.Sprintf("Show all devices on account."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, - RunE: c.funcPsIdListList, + RunE: c.funcPsList, Args: cobra.MinimumNArgs(0), } cmd.AddCommand(self) @@ -54,13 +57,14 @@ func (c *CmdShow) AttachPsIdList(cmd *cobra.Command) *cobra.Command { return cmd } -func (c *CmdShow) funcPsIdListList(_ *cobra.Command, args []string) error { +func (c *CmdShow) funcPsList(_ *cobra.Command, args []string) error { for range Only.Once { var devices string - devices, c.Error = cmds.Api.SunGrow.Devices(args...) + devices, c.Error = cmds.Api.SunGrow.PsList(args...) if c.Error != nil { break } + fmt.Printf("%s\n", devices) } return c.Error @@ -68,7 +72,7 @@ func (c *CmdShow) funcPsIdListList(_ *cobra.Command, args []string) error { func (c *CmdShow) AttachPsIdList2(cmd *cobra.Command) *cobra.Command { var self = &cobra.Command{ - Use: "list", + Use: "list2", Aliases: []string{"ls"}, Annotations: map[string]string{"group": "PsId"}, Short: fmt.Sprintf("Show all available PS."), @@ -90,6 +94,7 @@ func (c *CmdShow) funcAttachPsIdList2(_ *cobra.Command, args []string) error { if c.Error != nil { break } + fmt.Printf("%s\n", pids) } return c.Error @@ -120,6 +125,7 @@ func (c *CmdShow) funcAttachPsTree(_ *cobra.Command, args []string) error { if c.Error != nil { break } + fmt.Printf("%s\n", pids) } return c.Error @@ -127,11 +133,11 @@ func (c *CmdShow) funcAttachPsTree(_ *cobra.Command, args []string) error { func (c *CmdShow) AttachPsPoints(cmd *cobra.Command) *cobra.Command { var self = &cobra.Command{ - Use: "points [device_type]", + Use: "points [ps_ids | .] [device_type]", Aliases: []string{"point"}, Annotations: map[string]string{"group": "PsId"}, - Short: fmt.Sprintf("Show available PS points."), - Long: fmt.Sprintf("Show available PS points."), + Short: fmt.Sprintf("List points used for a given ps_id."), + Long: fmt.Sprintf("List points used for a given ps_id."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, @@ -146,12 +152,73 @@ func (c *CmdShow) AttachPsPoints(cmd *cobra.Command) *cobra.Command { func (c *CmdShow) funcAttachPsPoints(_ *cobra.Command, args []string) error { for range Only.Once { args = MinimumArraySize(2, args) - points := cmds.Api.SunGrow.PointNames(strings.Split(args[0], ","), args[1]) - if cmds.Api.SunGrow.Error != nil { - c.Error = cmds.Api.SunGrow.Error + var points string + points, c.Error = cmds.Api.SunGrow.PsPoints(strings.Split(args[0], ","), args[1]) + if c.Error != nil { break } + fmt.Printf("%s\n", points) } return c.Error } + +func (c *CmdShow) AttachPsData(cmd *cobra.Command) *cobra.Command { + var self = &cobra.Command{ + Use: "data [device_type | .] [start date] [end date] [interval]", + Aliases: []string{"point"}, + Annotations: map[string]string{"group": "PsId"}, + Short: fmt.Sprintf("Generate points table for a given ps_id."), + Long: fmt.Sprintf("Generate points table for a given ps_id."), + DisableFlagParsing: false, + DisableFlagsInUseLine: false, + PreRunE: cmds.SunGrowArgs, + RunE: c.funcAttachPsData, + Args: cobra.MinimumNArgs(1), + } + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, "") + + return cmd +} +func (c *CmdShow) funcAttachPsData(_ *cobra.Command, args []string) error { + for range Only.Once { + cmds.Api.SunGrow.OutputType.SetTable() + args = MinimumArraySize(5, args) + c.Error = cmds.Api.SunGrow.PsPointsData(strings.Split(args[0], ","), args[1], args[2], args[3], args[4]) + if c.Error != nil { + break + } + } + return c.Error +} + +func (c *CmdShow) AttachPsGraph(cmd *cobra.Command) *cobra.Command { + var self = &cobra.Command{ + Use: "graph [device_type]", + Aliases: []string{}, + Annotations: map[string]string{"group": "PsId"}, + Short: fmt.Sprintf("Generate graphs of points for a given ps_id."), + Long: fmt.Sprintf("Generate graphs of points for a given ps_id."), + DisableFlagParsing: false, + DisableFlagsInUseLine: false, + PreRunE: cmds.SunGrowArgs, + RunE: c.funcAttachPsGraph, + Args: cobra.MinimumNArgs(1), + } + cmd.AddCommand(self) + self.Example = cmdHelp.PrintExamples(self, "") + + return cmd +} +func (c *CmdShow) funcAttachPsGraph(_ *cobra.Command, args []string) error { + for range Only.Once { + cmds.Api.SunGrow.OutputType.SetGraph() + args = MinimumArraySize(5, args) + c.Error = cmds.Api.SunGrow.PsPointsData(strings.Split(args[0], ","), args[1], args[2], args[3], args[4]) + if c.Error != nil { + break + } + } + return c.Error +} diff --git a/cmd/cmd_show_template.go b/cmd/cmd_show_template.go index a2cc89b14..b31dbffc6 100644 --- a/cmd/cmd_show_template.go +++ b/cmd/cmd_show_template.go @@ -14,8 +14,8 @@ func (c *CmdShow) AttachTemplate(cmd *cobra.Command) *cobra.Command { Use: "template", Aliases: []string{}, Annotations: map[string]string{"group": "Template"}, - Short: fmt.Sprintf("General iSolarCloud functions."), - Long: fmt.Sprintf("General iSolarCloud functions."), + Short: fmt.Sprintf("Template related Sungrow commands."), + Long: fmt.Sprintf("Template related Sungrow commands."), DisableFlagParsing: false, DisableFlagsInUseLine: false, PreRunE: cmds.SunGrowArgs, @@ -30,16 +30,16 @@ func (c *CmdShow) AttachTemplate(cmd *cobra.Command) *cobra.Command { c.AttachTemplateList(self) c.AttachTemplatePoints(self) c.AttachTemplateData(self) - c.AttachTemplateDataGraph(self) + c.AttachTemplateGraph(self) } return c.SelfCmd } + func (c *CmdShow) AttachTemplateList(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** var self = &cobra.Command{ Use: "list", - Aliases: []string{}, + Aliases: []string{"ls"}, Annotations: map[string]string{"group": "Template"}, Short: fmt.Sprintf("Get all defined templates."), Long: fmt.Sprintf("Get all defined templates."), @@ -63,13 +63,12 @@ func (c *CmdShow) funcTemplateList(_ *cobra.Command, _ []string) error { } func (c *CmdShow) AttachTemplatePoints(cmd *cobra.Command) *cobra.Command { - // ******************************************************************************** var self = &cobra.Command{ Use: "points