Skip to content

Commit

Permalink
* UPD: getEnergyUsageCommand for float32 support
Browse files Browse the repository at this point in the history
  • Loading branch information
avegao committed Feb 20, 2018
1 parent 7c67218 commit a4bff10
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions command/get/energy_usage/get_energy_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
)

type getEnergyUsageCommandInterface interface {
Run() (whInSession int, whAccumulated int, err error)
parseResponse(response string) (whInSession int, whAccumulated int, err error)
Run() (whInSession float32, whAccumulated float32, err error)
parseResponse(response string) (whInSession float32, whAccumulated float32, err error)
}

type getEnergyUsageCommand struct {
getEnergyUsageCommandInterface
command.Command
}

func (c getEnergyUsageCommand) Run() (whInSession int, whAccumulated int, err error) {
func (c getEnergyUsageCommand) Run() (whInSession float32, whAccumulated float32, err error) {
response, err := c.SendRequest()

if err != nil {
Expand All @@ -27,15 +27,16 @@ func (c getEnergyUsageCommand) Run() (whInSession int, whAccumulated int, err er
return c.parseResponse(response.Response)
}

func (c getEnergyUsageCommand) parseResponse(response string) (whInSession int, whAccumulated int, err error) {
func (c getEnergyUsageCommand) parseResponse(response string) (whInSession float32, whAccumulated float32, err error) {
split := strings.Split(response, " ")

switch split[0] {
case command.SuccessResponse:
whInSession, whAccumulated, err = parseResponseFromSplit(split)
var whInSessionInt, whAccumulatedInt int
whInSessionInt, whAccumulatedInt, err = parseResponseFromSplit(split)

whInSession /= 3600
whAccumulated /= 1000
whInSession = float32(whInSessionInt)/3600
whAccumulated = float32(whAccumulatedInt)/1000
case command.FailureResponse:
err = errors.New("openevse - invalid request")
default:
Expand Down

0 comments on commit a4bff10

Please sign in to comment.