Skip to content

Commit

Permalink
Merge pull request #301 from observerly/feature/cover/GetStatus
Browse files Browse the repository at this point in the history
feat: amend GetStatus() return in cover module in @observerly/alpacago
  • Loading branch information
michealroberts authored Jan 4, 2025
2 parents 3f85847 + 47907e5 commit 0896084
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions pkg/alpacago/calibrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ const (
CalibratorError
)

func (s CalibratorState) String() string {
name := []string{"not_present", "off", "not_ready", "ready", "unknown", "error"}

i := uint8(s)

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

const (
// This device does not have a cover that can be closed independently
CoverNotPresent CoverState = iota
Expand Down Expand Up @@ -115,9 +128,9 @@ GetStatus()
@see https://ascom-standards.org/api/#/ASCOM%20Methods%20Common%20To%20All%20Devices/get__device_type___device_number__calibratorstate
@see https://ascom-standards.org/Help/Platform/html/T_ASCOM_DeviceInterface_CalibratorStatus.htm
*/
func (c *CoverCalibrator) GetStatus() (CalibratorState, error) {
func (c *CoverCalibrator) GetStatus() (string, error) {
status, err := c.Alpaca.GetInt32Response("covercalibrator", c.DeviceNumber, "calibratorstate")
return CalibratorState(status), err
return CalibratorState(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 @@ -122,7 +122,7 @@ func TestNewCalibratorCoverGetStatus(t *testing.T) {
t.Errorf("got %q", err)
}

if got != CalibratorReady && got != CalibratorNotReady {
if got != "ready" && got != "not_ready" && got != "unknown" {
t.Errorf("got %v, but expected the calibrator to be ready", got)
}

Expand Down

0 comments on commit 0896084

Please sign in to comment.