client

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHouseholdUser = errors.New("invalid household user response")
View Source
var ErrNoSmartSchedule = errors.New("no Autopilot schedule configured")

ErrNoSmartSchedule is returned when the user has no Autopilot schedule configured.

Functions

func IsEndpointUnavailable

func IsEndpointUnavailable(err error) bool

IsEndpointUnavailable returns true when the API indicates the requested route does not exist for the current backend/account.

Types

type APIError

type APIError struct {
	Method string
	URL    string
	Status int
	Body   string
	// Token marks a failure of the token request itself.
	Token bool
	// contains filtered or unexported fields
}

APIError is a failed Eight Sleep response: a non-2xx status from the API, retries exhausted on 401 or 429, or a refused token request. Its message is the one eightctl always printed.

func (*APIError) Error

func (e *APIError) Error() string

type Alarm

type Alarm struct {
	ID         string         `json:"id"`
	Enabled    bool           `json:"enabled"`
	Time       string         `json:"time"`
	DaysOfWeek []int          `json:"daysOfWeek"`
	Vibration  AlarmVibration `json:"vibration"`
	Sound      *string        `json:"sound,omitempty"`
}

Alarm represents alarm payload.

type AlarmActions

type AlarmActions struct {
	// contains filtered or unexported fields
}

AlarmActions groups alarm endpoints.

func (*AlarmActions) ActiveAlarms

func (a *AlarmActions) ActiveAlarms(ctx context.Context) ([]map[string]any, error)

ActiveAlarms returns the alarms ringing now, as the app API reports them.

func (*AlarmActions) Dismiss

func (a *AlarmActions) Dismiss(ctx context.Context, alarmID string) error

func (*AlarmActions) DismissActive

func (a *AlarmActions) DismissActive(ctx context.Context) (dismissed []string, err error)

DismissActive dismisses every active alarm with PUT on the app API, the route that advertises Allow: PUT. When that route answers 404 or 405 it dismisses each active alarm instead and returns their IDs; dismissed is nil when the bulk route worked.

func (*AlarmActions) DismissAll

func (a *AlarmActions) DismissAll(ctx context.Context) error

func (*AlarmActions) DismissAllRoute

func (a *AlarmActions) DismissAllRoute() string

DismissAllRoute is the app API route that dismisses every active alarm.

func (*AlarmActions) DismissRoute

func (a *AlarmActions) DismissRoute(alarmID string) string

DismissRoute is the app API route that dismisses one alarm.

func (*AlarmActions) NextAlarmID

func (a *AlarmActions) NextAlarmID(ctx context.Context) (string, error)

NextAlarmID reads the routines and returns the next alarm's ID: the state's nextAlarm, else the first alarm of the upcoming routine's override, else of the routine itself. Empty means none is scheduled.

func (*AlarmActions) Snooze

func (a *AlarmActions) Snooze(ctx context.Context, alarmID string) error

func (*AlarmActions) VibrationTest

func (a *AlarmActions) VibrationTest(ctx context.Context) error

type AlarmVibration

type AlarmVibration struct {
	Enabled    bool   `json:"enabled"`
	Pattern    string `json:"pattern,omitempty"`
	PowerLevel int    `json:"powerLevel,omitempty"`
}

AlarmVibration supports both historical boolean payloads and current object payloads.

func (AlarmVibration) MarshalJSON

func (v AlarmVibration) MarshalJSON() ([]byte, error)

func (*AlarmVibration) UnmarshalJSON

func (v *AlarmVibration) UnmarshalJSON(data []byte) error

type AudioActions

type AudioActions struct {
	// contains filtered or unexported fields
}

func (*AudioActions) AddFavorite

func (a *AudioActions) AddFavorite(ctx context.Context, trackID string) error

func (*AudioActions) Categories

func (a *AudioActions) Categories(ctx context.Context) (any, error)

func (*AudioActions) Favorites

func (a *AudioActions) Favorites(ctx context.Context) (any, error)

func (*AudioActions) Pair

func (a *AudioActions) Pair(ctx context.Context) error

func (*AudioActions) Pause

func (a *AudioActions) Pause(ctx context.Context) error

func (*AudioActions) Play

func (a *AudioActions) Play(ctx context.Context, trackID string) error

func (*AudioActions) PlayerState

func (a *AudioActions) PlayerState(ctx context.Context) (any, error)

func (*AudioActions) RecommendedNext

func (a *AudioActions) RecommendedNext(ctx context.Context) (any, error)

func (*AudioActions) RemoveFavorite

func (a *AudioActions) RemoveFavorite(ctx context.Context, trackID string) error

func (*AudioActions) Seek

func (a *AudioActions) Seek(ctx context.Context, positionMs int) error

func (*AudioActions) Tracks

func (a *AudioActions) Tracks(ctx context.Context) ([]AudioTrack, error)

func (*AudioActions) Volume

func (a *AudioActions) Volume(ctx context.Context, level int) error

type AudioTrack

type AudioTrack struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	Type  string `json:"type"`
}

ListTracks returns audio tracks metadata.

type AutopilotActions

type AutopilotActions struct {
	// contains filtered or unexported fields
}

func (*AutopilotActions) Details

func (a *AutopilotActions) Details(ctx context.Context) (any, error)

func (*AutopilotActions) History

func (a *AutopilotActions) History(ctx context.Context) (any, error)

func (*AutopilotActions) Recap

func (a *AutopilotActions) Recap(ctx context.Context) (any, error)

func (*AutopilotActions) SetLevelSuggestions

func (a *AutopilotActions) SetLevelSuggestions(ctx context.Context, enabled bool) error

func (*AutopilotActions) SetSnoreMitigation

func (a *AutopilotActions) SetSnoreMitigation(ctx context.Context, enabled bool) error

type BaseActions

type BaseActions struct {
	// contains filtered or unexported fields
}

func (*BaseActions) Info

func (b *BaseActions) Info(ctx context.Context) (any, error)

func (*BaseActions) Presets

func (b *BaseActions) Presets(ctx context.Context) (any, error)

func (*BaseActions) RunPreset

func (b *BaseActions) RunPreset(ctx context.Context, name string) error

func (*BaseActions) SetAngle

func (b *BaseActions) SetAngle(ctx context.Context, head, foot int) error

func (*BaseActions) VibrationTest

func (b *BaseActions) VibrationTest(ctx context.Context) error

type Client

type Client struct {
	Email        string
	Password     string
	UserID       string
	ClientID     string
	ClientSecret string
	DeviceID     string

	HTTP    *http.Client
	BaseURL string
	AppURL  string

	// Now is the clock for presence windows. Nil means time.Now.
	Now func() time.Time
	// contains filtered or unexported fields
}

Client represents Eight Sleep API client.

func New

func New(email, password, userID, clientID, clientSecret string) *Client

New creates a Client.

func (*Client) Alarms

func (c *Client) Alarms() *AlarmActions

Alarms helper accessor.

func (*Client) Audio

func (c *Client) Audio() *AudioActions

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context) error

Authenticate fetches a bearer token via the OAuth password-grant endpoint.

func (*Client) Autopilot

func (c *Client) Autopilot() *AutopilotActions

func (*Client) Base

func (c *Client) Base() *BaseActions

func (*Client) CreateAlarm

func (c *Client) CreateAlarm(ctx context.Context, alarm Alarm) (*Alarm, error)

func (*Client) CreateSchedule

func (c *Client) CreateSchedule(ctx context.Context, s TemperatureSchedule) (*TemperatureSchedule, error)

func (*Client) CurrentDevice

func (c *Client) CurrentDevice(ctx context.Context) (map[string]any, error)

CurrentDevice returns the user's current device record, or an empty map.

func (*Client) DeleteAlarm

func (c *Client) DeleteAlarm(ctx context.Context, alarmID string) error

func (*Client) DeleteSchedule

func (c *Client) DeleteSchedule(ctx context.Context, id string) error

func (*Client) Device

func (c *Client) Device() *DeviceActions

func (*Client) DeviceStatus

func (c *Client) DeviceStatus(ctx context.Context, deviceID string) (map[string]any, error)

DeviceStatus returns the device's sensor info, online state, last contact and side assignments, or an empty map.

func (*Client) EnsureDeviceID

func (c *Client) EnsureDeviceID(ctx context.Context) (string, error)

EnsureDeviceID fetches current device id if not already set.

func (*Client) EnsureUserID

func (c *Client) EnsureUserID(ctx context.Context) error

EnsureUserID populates UserID by calling /users/me if missing.

func (*Client) GetAwayMode

func (c *Client) GetAwayMode(ctx context.Context, userID string) (bool, error)

GetAwayMode reports whether away mode is currently active for a user. It reads the same app API endpoint SetAwayMode writes to, which answers with {"isAway": bool}. If userID is empty, it defaults to the authenticated user.

func (*Client) GetPresence

func (c *Client) GetPresence(ctx context.Context, from, to, timezone string) (bool, error)

func (*Client) GetSleepDay

func (c *Client) GetSleepDay(ctx context.Context, date string, timezone string) (*SleepDay, error)

GetSleepDay fetches sleep trends for a date (YYYY-MM-DD).

func (*Client) GetSmartSchedule

func (c *Client) GetSmartSchedule(ctx context.Context) (map[string]any, error)

GetSmartSchedule returns the Autopilot schedule from the app-api temperature resource.

func (*Client) GetStatus

func (c *Client) GetStatus(ctx context.Context) (*TempStatus, error)

GetStatus fetches temperature-based status (current mode/level).

func (*Client) GetStatusForUser

func (c *Client) GetStatusForUser(ctx context.Context, userID string) (*TempStatus, error)

func (*Client) Household

func (c *Client) Household() *HouseholdActions

func (*Client) HouseholdUserTargets

func (c *Client) HouseholdUserTargets(ctx context.Context) ([]HouseholdUserTarget, error)

HouseholdUserTargets returns the household users that can be targeted for side-aware commands.

func (*Client) Identity

func (c *Client) Identity() tokencache.Identity

func (*Client) ListAlarms

func (c *Client) ListAlarms(ctx context.Context) ([]Alarm, error)

func (*Client) ListSchedules

func (c *Client) ListSchedules(ctx context.Context) ([]TemperatureSchedule, error)

func (*Client) ListTracks

func (c *Client) ListTracks(ctx context.Context) ([]AudioTrack, error)

func (*Client) Metrics

func (c *Client) Metrics() *MetricsActions

func (*Client) ReleaseFeatures

func (c *Client) ReleaseFeatures(ctx context.Context) ([]ReleaseFeature, error)

func (*Client) SetAwayMode

func (c *Client) SetAwayMode(ctx context.Context, userID string, away bool) error

SetAwayMode activates or deactivates away mode for a specific user ID. The away-mode endpoint lives on the app API (app-api.8slp.net), not the client API used by most other endpoints. If userID is empty, it defaults to the authenticated user.

func (*Client) SetTemperature

func (c *Client) SetTemperature(ctx context.Context, level int) error

SetTemperature sets target heating/cooling level (-100..100) for the authenticated user's current pod side.

func (*Client) SetTemperatureForUser

func (c *Client) SetTemperatureForUser(ctx context.Context, userID string, level int) error

SetTemperatureForUser sets target heating/cooling level (-100..100) for a specific household user ID. If userID is empty, the authenticated user's ID is resolved and used.

func (*Client) TempModes

func (c *Client) TempModes() *TempModes

func (*Client) TokenExpiry

func (c *Client) TokenExpiry() time.Time

TokenExpiry is the expiry of the token the client holds, or zero before it has loaded or requested one.

func (*Client) Travel

func (c *Client) Travel() *TravelActions

func (*Client) TrendDays

func (c *Client) TrendDays(ctx context.Context, from, to, tz string) ([]any, error)

TrendDays returns the raw trend days between two dates, every session included.

func (*Client) TurnOff

func (c *Client) TurnOff(ctx context.Context) error

TurnOff powers device off.

func (*Client) TurnOffForUser

func (c *Client) TurnOffForUser(ctx context.Context, userID string) error

func (*Client) TurnOn

func (c *Client) TurnOn(ctx context.Context) error

TurnOn powers device on.

func (*Client) TurnOnForUser

func (c *Client) TurnOnForUser(ctx context.Context, userID string) error

func (*Client) UpdateAlarm

func (c *Client) UpdateAlarm(ctx context.Context, alarmID string, patch map[string]any) (*Alarm, error)

func (*Client) UpdateSchedule

func (c *Client) UpdateSchedule(ctx context.Context, id string, patch map[string]any) (*TemperatureSchedule, error)

func (*Client) UseHosts

func (c *Client) UseHosts(h Hosts)

UseHosts points every request at h. The client API keeps its fallback to the app API when a route is missing.

type DeviceActions

type DeviceActions struct {
	// contains filtered or unexported fields
}

func (*DeviceActions) Info

func (d *DeviceActions) Info(ctx context.Context) (any, error)

func (*DeviceActions) Online

func (d *DeviceActions) Online(ctx context.Context) (any, error)

func (*DeviceActions) Owner

func (d *DeviceActions) Owner(ctx context.Context) (any, error)

func (*DeviceActions) Peripherals

func (d *DeviceActions) Peripherals(ctx context.Context) (any, error)

func (*DeviceActions) PrimingSchedule

func (d *DeviceActions) PrimingSchedule(ctx context.Context) (any, error)

func (*DeviceActions) PrimingTasks

func (d *DeviceActions) PrimingTasks(ctx context.Context) (any, error)

func (*DeviceActions) Sides

func (d *DeviceActions) Sides(ctx context.Context) (*DeviceSides, error)

Sides fetches the left/right user ID assignments from device info.

func (*DeviceActions) Warranty

func (d *DeviceActions) Warranty(ctx context.Context) (any, error)

type DeviceSides

type DeviceSides struct {
	LeftUserID  string `json:"leftUserId"`
	RightUserID string `json:"rightUserId"`
}

DeviceSides holds the user IDs assigned to each side of the pod.

type Hosts

Hosts replaces the three Eight Sleep hosts, each a scheme and host with no path, so tests and fakes never reach the real service.

type HouseholdActions

type HouseholdActions struct {
	// contains filtered or unexported fields
}

func (*HouseholdActions) CurrentSet

func (h *HouseholdActions) CurrentSet(ctx context.Context) (any, error)

func (*HouseholdActions) Devices

func (h *HouseholdActions) Devices(ctx context.Context) (any, error)

func (*HouseholdActions) Guests

func (h *HouseholdActions) Guests(ctx context.Context) (any, error)

func (*HouseholdActions) Invitations

func (h *HouseholdActions) Invitations(ctx context.Context) (any, error)

func (*HouseholdActions) Schedule

func (h *HouseholdActions) Schedule(ctx context.Context) (any, error)

func (*HouseholdActions) Summary

func (h *HouseholdActions) Summary(ctx context.Context) (any, error)

func (*HouseholdActions) Users

func (h *HouseholdActions) Users(ctx context.Context) (any, error)

type HouseholdUserTarget

type HouseholdUserTarget struct {
	UserID    string
	Side      string
	FirstName string
	LastName  string
	Email     string
}

HouseholdUserTarget describes a user that can be targeted for side-aware actions.

func ResolveHouseholdSide

func ResolveHouseholdSide(targets []HouseholdUserTarget, side string) (*HouseholdUserTarget, error)

ResolveHouseholdSide resolves a single user target for left/right/solo side-aware commands.

func (HouseholdUserTarget) DisplayName

func (t HouseholdUserTarget) DisplayName() string

func (HouseholdUserTarget) SideLabel

func (t HouseholdUserTarget) SideLabel() string

type MetricsActions

type MetricsActions struct {
	// contains filtered or unexported fields
}

func (*MetricsActions) Aggregate

func (m *MetricsActions) Aggregate(ctx context.Context, out any) error

func (*MetricsActions) Insights

func (m *MetricsActions) Insights(ctx context.Context, out any) error

func (*MetricsActions) Intervals

func (m *MetricsActions) Intervals(ctx context.Context, sessionID string, out any) error

func (*MetricsActions) Summary

func (m *MetricsActions) Summary(ctx context.Context, out any) error

func (*MetricsActions) Trends

func (m *MetricsActions) Trends(ctx context.Context, from, to, timezone string, out any) error

type ReleaseFeature

type ReleaseFeature struct {
	Title string `json:"title"`
	Body  string `json:"body"`
}

ReleaseFeature represents release features payload.

type SleepDay

type SleepDay struct {
	Date          string  `json:"day"`
	Score         float64 `json:"score"`
	Tnt           int     `json:"tnt"`
	Respiratory   float64 `json:"respiratoryRate"`
	HeartRate     float64 `json:"heartRate"`
	LatencyAsleep float64 `json:"latencyAsleepSeconds"`
	LatencyOut    float64 `json:"latencyOutSeconds"`
	Duration      float64 `json:"sleepDurationSeconds"`
	Stages        []Stage `json:"stages"`
	SleepQuality  struct {
		HRV struct {
			Score float64 `json:"score"`
		} `json:"hrv"`
		Resp struct {
			Score float64 `json:"score"`
		} `json:"respiratoryRate"`
	} `json:"sleepQualityScore"`
}

SleepDay represents aggregated sleep metrics for a day.

type Stage

type Stage struct {
	Stage    string  `json:"stage"`
	Duration float64 `json:"duration"`
}

Stage represents sleep stage duration.

type TempModes

type TempModes struct {
	// contains filtered or unexported fields
}

func (*TempModes) HotFlashActivate

func (t *TempModes) HotFlashActivate(ctx context.Context) error

Hot flash controls

func (*TempModes) HotFlashDeactivate

func (t *TempModes) HotFlashDeactivate(ctx context.Context) error

func (*TempModes) HotFlashStatus

func (t *TempModes) HotFlashStatus(ctx context.Context, out any) error

func (*TempModes) NapActivate

func (t *TempModes) NapActivate(ctx context.Context) error

Nap mode controls

func (*TempModes) NapDeactivate

func (t *TempModes) NapDeactivate(ctx context.Context) error

func (*TempModes) NapExtend

func (t *TempModes) NapExtend(ctx context.Context) error

func (*TempModes) NapStatus

func (t *TempModes) NapStatus(ctx context.Context, out any) error

func (*TempModes) TempEvents

func (t *TempModes) TempEvents(ctx context.Context, from, to string, out any) error

Temp events history

type TempStatus

type TempStatus struct {
	CurrentLevel int `json:"currentLevel"`
	CurrentState struct {
		Type string `json:"type"`
	} `json:"currentState"`
}

TempStatus represents current temperature state payload.

type TemperatureSchedule

type TemperatureSchedule struct {
	ID         string `json:"id"`
	StartTime  string `json:"startTime"`
	Level      int    `json:"level"`
	DaysOfWeek []int  `json:"daysOfWeek"`
	Enabled    bool   `json:"enabled"`
}

TemperatureSchedule represents server-side temperature schedules.

type TravelActions

type TravelActions struct {
	// contains filtered or unexported fields
}

func (*TravelActions) AirportSearch

func (t *TravelActions) AirportSearch(ctx context.Context, query string) (any, error)

func (*TravelActions) CreatePlan

func (t *TravelActions) CreatePlan(ctx context.Context, tripID string, body map[string]any) error

func (*TravelActions) CreateTrip

func (t *TravelActions) CreateTrip(ctx context.Context, body map[string]any) error

func (*TravelActions) DeleteTrip

func (t *TravelActions) DeleteTrip(ctx context.Context, tripID string) error

func (*TravelActions) FlightStatus

func (t *TravelActions) FlightStatus(ctx context.Context, flight string) (any, error)

func (*TravelActions) PlanTasks

func (t *TravelActions) PlanTasks(ctx context.Context, planID string) (any, error)

func (*TravelActions) Plans

func (t *TravelActions) Plans(ctx context.Context, tripID string) (any, error)

func (*TravelActions) Trips

func (t *TravelActions) Trips(ctx context.Context) (any, error)

func (*TravelActions) UpdatePlan

func (t *TravelActions) UpdatePlan(ctx context.Context, planID string, body map[string]any) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL