-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from AaronSaikovski/v2.0_refactor
V2.0 refactor
- Loading branch information
Showing
41 changed files
with
672 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ builds: | |
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
- darwin | ||
main: ./cmd/gogoodwe | ||
|
||
archives: | ||
- format: tar.gz | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
# CHANGELOG | ||
# GoGoodwe - CHANGELOG | ||
|
||
## v2.0.0 (2024-01-22) | ||
|
||
- Major refactoring to cleanup project structure. | ||
- Simplified package structure. | ||
- refactored structs to use pointers more efficiently. | ||
|
||
## v1.4.0 (2023-08-30) | ||
|
||
- Major refactoring to move non-shared code to /internal folder | ||
- Abstracted core away from main() | ||
|
||
## v1.1.0 (2023-08-16) | ||
|
||
- refactored code to make errors bubble back to main package and better error reporting/logging | ||
- refactored main package to include run() method | ||
- removed staticcheck as there is a bug with Go v1.21 | ||
|
||
## v1.0.0 (2023-08-10) | ||
|
||
- initial version 1.0 release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,92 @@ | ||
# Define Go command and flags | ||
GO = go | ||
GOFLAGS = -ldflags="-s -w" | ||
|
||
#export PATH=$PATH:$HOME/go/bin; | ||
|
||
# Define the target executable | ||
TARGET = gogoodwe | ||
MAINAPPPATH = ./cmd/${TARGET}/main.go | ||
|
||
default: help | ||
|
||
.PHONY: help | ||
## help - Display help about make targets for this Makefile | ||
help: | ||
@cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t | ||
|
||
## localrelease - Builds the project in preparation for (local)release | ||
localrelease: | ||
go build $(GOFLAGS) -o bin/${TARGET} main.go | ||
|
||
.PHONY: release | ||
## release - Builds the project in preparation for (local)release | ||
release: vet lint seccheck | ||
go build $(GOFLAGS) -o bin/${TARGET} ${MAINAPPPATH} | ||
file bin/${TARGET} | ||
|
||
## release - Builds the project in preparation for release | ||
release: | ||
goreleaser release --snapshot --clean | ||
|
||
## debug - Builds the project in preparation for debug | ||
|
||
.PHONY: goreleaser | ||
## goreleaser - Builds the project in preparation for release | ||
goreleaser: | ||
goreleaser release --snapshot --clean | ||
|
||
|
||
.PHONY: docs | ||
## docs - updates the swagger docs | ||
docs: | ||
swag init | ||
|
||
|
||
.PHONY: build | ||
## build - Builds the project in preparation for debug | ||
build: | ||
go build -o bin/${TARGET} main.go | ||
go build -o bin/${TARGET} ${MAINAPPPATH} | ||
file bin/${TARGET} | ||
|
||
## buildandrun - builds and runs the program on the target platform | ||
buildandrun: build | ||
./bin/${TARGET} | ||
|
||
## run - runs main.go for testing | ||
run: dep | ||
go run main.go | ||
.PHONY: run | ||
## run - builds and runs the program on the target platform | ||
run: | ||
go run ${MAINAPPPATH} | ||
|
||
|
||
.PHONY: clean | ||
## clean - Remove the old builds and any debug information | ||
clean: | ||
go clean -cache | ||
go clean | ||
rm -rf dist | ||
rm bin/${TARGET} | ||
|
||
## test - executes unit test | ||
|
||
.PHONY: test | ||
## test - executes unit tests | ||
test: | ||
go test ./... | ||
go test -v ./test/... | ||
|
||
## dep - fetches any external dependencies | ||
dep: | ||
|
||
.PHONY: deps | ||
## deps - fetches any external dependencies and updates | ||
deps: | ||
go mod tidy | ||
go mod download | ||
go get -u ./... | ||
|
||
|
||
.PHONY: vet | ||
## vet - Vet examines Go source code and reports suspicious constructs | ||
vet: | ||
go vet ./... | ||
|
||
## staticcheck - Runs static code analyzer staticcheck | ||
staticcheck: | ||
go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./... | ||
|
||
.PHONY: staticcheck | ||
## staticcheck - Runs static code analyzer staticcheck - currently broken | ||
staticcheck: | ||
staticcheck ./... | ||
|
||
|
||
.PHONY: seccheck | ||
## seccheck - Code vulnerability check | ||
seccheck: | ||
brew install govulncheck | ||
govulncheck ./... | ||
#govulncheck ./... | ||
|
||
|
||
.PHONY: lint | ||
## lint - format code and tidy modules | ||
lint: | ||
go fmt ./... | ||
go mod tidy -v | ||
go mod tidy -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
# gogoodwe TODO | ||
# GoGoodwe V2 - TODO | ||
|
||
GoGoodwe backlog | ||
### ToDo | ||
|
||
### Todo | ||
|
||
- [ ] Add ability to output to file with a flag | ||
- [ ] Add ability to have a smaller output struct of just key reporting data | ||
- [ ] Add Golang contexts for API calls | ||
- [ ] | ||
|
||
### In Progress | ||
|
||
- [ ] add unit tests | ||
|
||
### Done ✓ | ||
|
||
- [x] Add the ability to query the inverter status for Generation today and Status (check if operational). | ||
|
||
### Future/Roadmap | ||
|
||
- [ ] Format the inverter output to make it more human readable. | ||
- [ ] Add ability to output inverter data to a file. | ||
- [ ] Add the ability to query historical data for a single day. | ||
- [ ] Have the ability to have a realtime logging to the screen or to a file in 5 minute intervals. | ||
- [ ] Add the ability to produce a daily summary of key data (Generation today, Income today, total generation, total income). | ||
- [ ] Add goroutines and wait groups for the API calls and maybe channels for success/failed API calls. | ||
- [ ] Investigate the ability to generate .CSV files as output. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package app | ||
|
||
// Main package - This is the main program entry point | ||
import ( | ||
"github.com/AaronSaikovski/gogoodwe/cmd/gogoodwe/powerstation" | ||
"github.com/AaronSaikovski/gogoodwe/cmd/gogoodwe/utils" | ||
"github.com/alexflint/go-arg" | ||
) | ||
|
||
// Run - main program runner | ||
func Run() error { | ||
|
||
//Get the args input data | ||
var args utils.Args | ||
p := arg.MustParse(&args) | ||
|
||
//check for valid email address input | ||
if !utils.CheckValidEmail(args.Account) { | ||
p.Fail("Invalid Email address format - should be: 'user@somedomain.com'.") | ||
} | ||
|
||
//check for valid powerstation Id | ||
if !utils.CheckValidPowerstationID(args.PowerStationID) { | ||
p.Fail("Invalid Powerstation ID format: - should be: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'.") | ||
} | ||
|
||
// Get the data from the API, return any errors. Pass in args as string | ||
return powerstation.FetchData(args.Account, args.Password, args.PowerStationID, args.DailySummary) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package interfaces | ||
|
||
import ( | ||
"github.com/AaronSaikovski/gogoodwe/cmd/gogoodwe/types" | ||
) | ||
|
||
// Constraints for functions that return data from the API via marshalled structs | ||
type ISemsDataConstraint interface { | ||
types.InverterData | types.DailySummaryData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Package main implements a program that authenticates to and queries the SEMS Solar inverter API. | ||
*/ | ||
package main | ||
|
||
import ( | ||
"github.com/AaronSaikovski/gogoodwe/cmd/gogoodwe/app" | ||
"log" | ||
) | ||
|
||
func main() { | ||
if err := runApp(); err != nil { | ||
log.Fatalf("error: %v", err) | ||
} | ||
} | ||
|
||
func runApp() error { | ||
return app.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package powerstation | ||
|
||
const ( | ||
// Powerstation API Url | ||
PowerStationURL string = "v2/PowerStation/GetMonitorDetailByPowerstationId" | ||
|
||
// Default timeout value | ||
HTTPTimeout int = 20 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
# Name: data - fetches data from the goodwe API - and processes it to pass back to caller | ||
# Author: Aaron Saikovski - asaikovski@outlook.com | ||
*/ | ||
package powerstation | ||
|
||
import ( | ||
"github.com/AaronSaikovski/gogoodwe/cmd/gogoodwe/semsapi" | ||
"github.com/AaronSaikovski/gogoodwe/cmd/gogoodwe/types" | ||
"github.com/AaronSaikovski/gogoodwe/cmd/gogoodwe/utils" | ||
) | ||
|
||
func FetchData(Account string, Password string, PowerStationID string, DailySummary bool) error { | ||
|
||
// User account struct | ||
creds := &types.LoginCredentials{ | ||
Account: Account, | ||
Password: Password, | ||
PowerStationID: PowerStationID, | ||
} | ||
|
||
// Do the login..check for errors | ||
loginApiResponse, err := semsapi.Login(creds) | ||
if err != nil { | ||
utils.HandleError(err) | ||
return err | ||
} | ||
|
||
//fetch data based on | ||
if DailySummary { | ||
getMonitorSummaryByPowerstationId(creds, loginApiResponse) | ||
|
||
} else { | ||
//powerstationData = types.InverterData | ||
getMonitorDetailByPowerstationId(creds, loginApiResponse) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.