Skip to content

Commit

Permalink
feat: amend GetCoverStatus() return in cover module in @observerly/al…
Browse files Browse the repository at this point in the history
…pacago

feat: amend GetCoverStatus() return in cover module in @observerly/alpacago
  • Loading branch information
michealroberts committed Jan 3, 2025
1 parent 170e3a1 commit 8ec4d49
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions pkg/alpacago/calibrator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package alpacago

import "fmt"
import (
"fmt"
"strconv"
)

type CalibratorState int32

Expand Down Expand Up @@ -36,6 +39,19 @@ const (
CoverError
)

func (s CoverState) String() string {
name := []string{"not_present", "closed", "moving", "open", "unknown", "error"}

i := uint8(s)

switch {
case i <= uint8(Error):
return name[i]
default:
return strconv.Itoa(int(i))
}
}

type CoverCalibrator struct {
Alpaca *ASCOMAlpacaAPIClient
DeviceNumber uint
Expand Down Expand Up @@ -111,9 +127,9 @@ GetCoverStatus()
@see https://ascom-standards.org/api/#/CoverCalibrator%20Specific%20Methods/get_covercalibrator__device_number__coverstate
@see https://ascom-standards.org/Help/Platform/html/T_ASCOM_DeviceInterface_CoverStatus.htm
*/
func (c *CoverCalibrator) GetCoverStatus() (CoverState, error) {
func (c *CoverCalibrator) GetCoverStatus() (string, error) {
status, err := c.Alpaca.GetInt32Response("covercalibrator", c.DeviceNumber, "coverstate")
return CoverState(status), err
return CoverState(status).String(), err
}

/*
Expand Down
2 changes: 1 addition & 1 deletion pkg/alpacago/calibrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestNewCalibratorCoverGetCoverStatus(t *testing.T) {
t.Errorf("got %q", err)
}

if got != CoverClosed && got != CoverOpen && got != CoverMoving && got != CoverUnknown {
if got != "closed" && got != "open" && got != "moving" && got != "unknown" {
t.Errorf("got %v, but expected the calibrator to be either open, close or moving", got)
}

Expand Down

0 comments on commit 8ec4d49

Please sign in to comment.