Skip to content

Commit

Permalink
Merge pull request #15 from AaronSaikovski/v3.0.0_new_ver
Browse files Browse the repository at this point in the history
V3.0.0 new ver
  • Loading branch information
AaronSaikovski authored Jul 4, 2024
2 parents fe455aa + 83ffd56 commit c04c61a
Show file tree
Hide file tree
Showing 42 changed files with 1,522 additions and 269 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cSpell.words": ["monitorsummary"]
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# GoGoodwe - CHANGELOG

## v3.0.0 (2024-07-04)

- added new report types
- added new command line report types
- Minor performance and optimisation fixes

## v2.0.6 (2024-06-13)

- renamed SemsDataConstraint
Expand Down
78 changes: 55 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

## GoGoodwe V2.0.6
## GoGoodwe v3.0.0

A command line tool to query the GOODWE SEMS Solar Inverter APIs - written in 100% Go.

Expand All @@ -9,31 +9,48 @@ A command line tool to query the GOODWE SEMS Solar Inverter APIs - written in 10

</div>

## Installation
### Software Requirements:

The toolchain is mainly driven by the Makefile.
- [Go v1.22.X](https://www.go.dev/dl/) or later needs to be installed to build the code.
- [Azure CLI tools](https://learn.microsoft.com/en-us/cli/azure/) 2.50 or later
- [Taskfile](https://taskfile.dev/) to run the build chain commands listed below.

## Installation:

The toolchain is driven by using [Taskfile](https://taskfile.dev/) and all commands are managed via the file `Taskfile.yml`

The list of commands is as follows:

```bash
help - Display help about make targets for this Makefile
release - Builds the project in preparation for (local)release
goreleaser - Builds the project in preparation for release
docs - updates the swagger docs
build - Builds the project in preparation for debug
run - builds and runs the program on the target platform
clean - Remove the old builds and any debug information
test - executes unit tests
deps - fetches any external dependencies and updates
vet - Vet examines Go source code and reports suspicious constructs
staticcheck - Runs static code analyzer staticcheck - currently broken
seccheck - Code vulnerability check
lint - format code and tidy modules
* build: Builds the project in preparation for debug.
* clean: Removes the old builds and any debug information from the source tree.
* deps: Fetches any external dependencies and updates.
* destroy: Destroy Azure resources for testing.
* docs: Updates the swagger docs - For APIs.
* generate: update binary build version using gogenerate.
* goreleaser: Builds a cross platform release using goreleaser.
* lint: Lint, format and tidy code.
* release: Builds the project in preparation for (local)release.
* run: Builds and runs the program on the target platform.
* seccheck: Code vulnerability scanner check.
* staticcheck: Runs static code analyzer staticcheck.
* test: Executes unit tests.
* version: Get the Go version.
* vet: Vet examines Go source code and reports suspicious constructs.
* watch: Use air server for hot reloading.
```

Execute using the taskfile utility:

```bash
task <command_from_above_list>
```

To get started type,

- make dep - to fetch all dependencies
- make build - to build debug version for your target environment architecture
- make release - Builds a release version for your target environment architecture
- `task deps` - to fetch all dependencies and update all dependencies.
- `task build` - to build debug version for your target environment architecture.
- `task release` - Builds a release version for your target environment architecture - outputs to /bin folder.

## Usage

Expand All @@ -45,14 +62,29 @@ Then the Station ID is `11112222-aaaa-bbbb-cccc-ddddeeeeeffff`.

From the command line the usage is pretty simple:

The Report Type corresponds to the type of API call and Report that is generated:

- (0)-Detail - Fully detailed report.
- (1)-Summary - Summary Data report (reduced information).
- (2)-Point - Inverter All points data.
- (3)-Plant - Plant Detail By Powerstation Id.
- (4)-PlantChart - Plant Chart data for use in Charts and Graphs.
- (5)-PowerFlow - Powerflow Summary data

```bash
##Note the use of single quotes ''
./gogoodwe --account '<user@email.com>' --pwd '<password>' --powerstationid '<powerstation id>' --summary
./gogoodwe --account '<user@email.com>' \
--pwd '<password>' \
--powerstationid '<powerstation id>' \
--reporttype '<report type (Optional)>'

# Or
./gogoodwe -a '<user@email.com>' -p '<password>' -i '<powerstation id>' -s
./gogoodwe -a '<user@email.com>' \
-p '<password>' \
-i '<powerstation id>' \
-r '<report type> (Optional)>'

##where daily summary provides a shorter daily view of the inverter data
##w
```

To get the help on using the command line tool, type:
Expand All @@ -78,4 +110,4 @@ GOODWE access is based on the undocumented API used by mobile apps. This could b

## Known Issues

**None at time of release.**
- The Powerchart report is returning no/blank values - investigating.
34 changes: 34 additions & 0 deletions cmd/gogoodwe/app/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
MIT License
# Copyright (c) 2024 Aaron Saikovski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package app

// Constants for Report lookups
const (
Detail = iota // 0
Summary // 1
Point // 2
Plant // 3
PlantChart // 4
PowerFlow // 5
)
31 changes: 18 additions & 13 deletions cmd/gogoodwe/app/fetchdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"context"
"fmt"

"github.com/AaronSaikovski/gogoodwe/internal/apilogin"
"github.com/AaronSaikovski/gogoodwe/internal/monitordata"
"github.com/AaronSaikovski/gogoodwe/pkg/auth"
"github.com/AaronSaikovski/gogoodwe/pkg/interfaces"
)

// fetchData fetches data using the provided account credentials and power station ID.
Expand All @@ -39,33 +39,38 @@ import (
// PowerStationID: the ID of the power station.
// DailySummary: a boolean indicating whether to retrieve a daily summary.
// error: an error if there was a problem logging in or fetching data.
func fetchData(context context.Context, Account, Password, PowerStationID string, isDailySummary bool) error {
func fetchData(context context.Context, Account, Password, PowerStationID string, ReportType int) error {

// User account struct
apiLoginCreds := &apilogin.ApiLoginCredentials{
Account: Account,
Password: Password,
PowerStationID: PowerStationID,
}
apiLoginCreds := auth.NewSemsLoginCredentials(Account, Password, PowerStationID)

// Assign the login interface
var loginService interfaces.SemsLogin = apiLoginCreds

// Do the login
loginApiResponse, err := apiLoginCreds.APILogin()
loginApiResponse, err := loginService.SemsLogin()
if err != nil {
return fmt.Errorf("login failed: %w", err)
}

monitordata := &monitordata.MonitorDataLoginInfo{
LoginApiCredentials: apiLoginCreds,
LoginApiResponse: loginApiResponse,
//Populate the loginInfo struct
loginInfo := &auth.LoginInfo{
SemsLoginCredentials: apiLoginCreds,
SemsLoginResponse: loginApiResponse,
}

if err := monitordata.GetPowerData(isDailySummary); err != nil {
// fetch the data
var dataService interfaces.PowerData = lookupMonitorData(ReportType)

if err := dataService.GetPowerData(loginInfo); err != nil {
return fmt.Errorf("data retrieval failed: %w", err)
}

if err := context.Err(); err != nil {
return fmt.Errorf("context error: %w", err)
}

defer context.Done()
return nil

}
63 changes: 63 additions & 0 deletions cmd/gogoodwe/app/lookupmonitordata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
MIT License
# Copyright (c) 2024 Aaron Saikovski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package app

// Main package - This is the main program entry point
import (
"github.com/AaronSaikovski/gogoodwe/pkg/interfaces"
inverteallpoint "github.com/AaronSaikovski/gogoodwe/pkg/inverterallpoint"
"github.com/AaronSaikovski/gogoodwe/pkg/monitordetail"
"github.com/AaronSaikovski/gogoodwe/pkg/monitorsummary"
"github.com/AaronSaikovski/gogoodwe/pkg/plantdetail"
plantchartdata "github.com/AaronSaikovski/gogoodwe/pkg/plantpowerchart"
"github.com/AaronSaikovski/gogoodwe/pkg/powerflow"
)

// lookupMonitorData returns a PowerData object based on the given reportData string.
//
// Parameters:
// - reportData: a string representing the type of data to retrieve.
//
// Returns:
// - interfaces.PowerData: the PowerData object corresponding to the reportData.
func lookupMonitorData(reportData int) interfaces.PowerData {

switch reportData {

case Point:
return inverteallpoint.NewInverterAllPoint()
case Detail:
return monitordetail.NewMonitorData()
case Summary:
return monitorsummary.NewDailySummaryData()
case Plant:
return plantdetail.NewGetPlantDetailByPowerstationId()
case PlantChart:
return plantchartdata.NewPlantPowerChart()
case PowerFlow:
return powerflow.NewPowerflow()
default:
return monitordetail.NewMonitorData()
}
}
2 changes: 1 addition & 1 deletion cmd/gogoodwe/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Run(ctx context.Context, versionString string) error {
}

// Get the data from the API, return any errors
if err := fetchData(ctx, args.Account, args.Password, args.PowerStationID, args.DailySummary); err != nil {
if err := fetchData(ctx, args.Account, args.Password, args.PowerStationID, args.ReportType); err != nil {
return ctx.Err()
} else {
ctx.Done()
Expand Down
7 changes: 4 additions & 3 deletions cmd/gogoodwe/utils/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ package utils
var (
// Version string
VersionString string = "v0.0.1"
infoString string = "*GoGoodwe - A command line tool to query your SEMS Solar inverter.*"
infoString string = "GoGoodwe - A CLI tool to query your SEMS Solar Inverter API."
reportString string = "Report Types: (0)-Detail, (1)-Summary, (2)-Point, (3)-Plant, (4)-PlantChart, (5)-PowerFlow"
)

// Args - struct using go-arg- https://github.com/alexflint/go-arg
type Args struct {
Account string `arg:"required,-a,--account" help:"SEMS Email Account."`
Password string `arg:"required,-p,--password" help:"SEMS Account password."`
PowerStationID string `arg:"required,-i,--powerstationid" help:"SEMS Powerstation ID."`
DailySummary bool `arg:"-s,--summary" help:"Output as a daily summary."`
ReportType int `arg:",-r,--reporttype" help:"Inverter Report Number"`
}

// Description returns a command line tool to query the GOODWE SEMS Portal APIs and Solar SEMS API.
//
// No parameters.
// Returns a string.
func (Args) Description() string {
return infoString
return infoString + "\n" + reportString
}

// Version returns the version string of the Args struct.
Expand Down
2 changes: 1 addition & 1 deletion cmd/gogoodwe/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0.6
v3.0.0
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/AaronSaikovski/gogoodwe

go 1.22.4
go 1.22.5

require (
github.com/alexflint/go-arg v1.5.0
github.com/alexflint/go-arg v1.5.1
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/valyala/fastjson v1.6.4
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/alexflint/go-arg v1.5.0 h1:rwMKGiaQuRbXfZNyRUvIfke63QvOBt1/QTshlGQHohM=
github.com/alexflint/go-arg v1.5.0/go.mod h1:A7vTJzvjoaSTypg4biM5uYNTkJ27SkNTArtYXnlqVO8=
github.com/alexflint/go-arg v1.5.1 h1:nBuWUCpuRy0snAG+uIJ6N0UvYxpxA0/ghA/AaHxlT8Y=
github.com/alexflint/go-arg v1.5.1/go.mod h1:A7vTJzvjoaSTypg4biM5uYNTkJ27SkNTArtYXnlqVO8=
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
Loading

0 comments on commit c04c61a

Please sign in to comment.