Skip to content

Commit

Permalink
Merge pull request #12 from ronhks/3-unable-to-use-the-aquarea-web-in…
Browse files Browse the repository at this point in the history
…terface-when-the-container-is-running

redesign the session handling
  • Loading branch information
ronhks committed Jun 28, 2023
2 parents a3dbb2c + 60cca6a commit b9109de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
22 changes: 13 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ import (
log "github.com/sirupsen/logrus"
)

func main() {
func init() {
initializeTheEnvironment()
}

err := loginAndGetContract()
if err != nil {
log.Error(err)
log.Error("Error while Login and get Contract")
return
}

func main() {
startQueryStatusData()
}

Expand All @@ -46,7 +41,6 @@ func initializeTheEnvironment() {
httputils.InitHttpClient()
mqtt.InitMqttConnection()
setLogSetup()

}

func setLogSetup() {
Expand All @@ -73,14 +67,24 @@ func loginAndGetContract() error {

func getStatusData() bool {

err := loginAndGetContract()
if err != nil {
log.Error(err)
log.Error("Error while Login and get Contract")
return false
}

statusData, err := data.GetDeviceData()
if err != nil || len(statusData.Status) == 0 {
log.Error(err)
log.Error("Error while get DeviceData")
panasonic.Logout()
return false
}
mqtt.PublishStatus(statusData)
log.Trace(statusData)

panasonic.Logout()

return true
}
20 changes: 18 additions & 2 deletions src/login/login.go → src/auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package login
package auth

import (
"encoding/json"
Expand All @@ -22,7 +22,7 @@ type ResponseStruct struct {
ErrorCode int `json:"errorCode"`
}

func GetLogin() error {
func Login() error {

var loginResponseStruct ResponseStruct
loginURL := config.GetConfig().AquareaSmartCloudURL + "/remote/v1/api/auth/login"
Expand Down Expand Up @@ -91,3 +91,19 @@ func getBodyFromResponse(err error, response *http.Response) ([]byte, error) {
func isPanasonicResponseHasError(loginStruct ResponseStruct) bool {
return loginStruct.ErrorCode != 0
}

func Logout() error {
logoutURL := config.GetConfig().AquareaSmartCloudURL + "/remote/v1/api/auth/logout"

response, err := httputils.PostREQ(logoutURL)
if err != nil {
return err
}

if response.StatusCode != http.StatusOK {
log.Error("HTTP call result code is:", response.StatusCode)
return err
}

return nil
}
12 changes: 10 additions & 2 deletions src/panasonic/panasonic.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package panasonic

import (
auth "github.com/ronhks/panasonic-aquarea-smart-cloud-mqtt/src/auth"
conf "github.com/ronhks/panasonic-aquarea-smart-cloud-mqtt/src/config"
httputils "github.com/ronhks/panasonic-aquarea-smart-cloud-mqtt/src/http"
"github.com/ronhks/panasonic-aquarea-smart-cloud-mqtt/src/login"
log "github.com/sirupsen/logrus"
)

func Login() {
err := login.GetLogin()
err := auth.Login()
if err != nil {
log.Error(err)
return
}
}

func Logout() {
err := auth.Logout()
if err != nil {
log.Error(err)
return
Expand Down

0 comments on commit b9109de

Please sign in to comment.