Documentation
¶
Index ¶
- Variables
- func IsEndpointUnavailable(err error) bool
- type APIError
- type Alarm
- type AlarmActions
- func (a *AlarmActions) ActiveAlarms(ctx context.Context) ([]map[string]any, error)
- func (a *AlarmActions) Dismiss(ctx context.Context, alarmID string) error
- func (a *AlarmActions) DismissActive(ctx context.Context) (dismissed []string, err error)
- func (a *AlarmActions) DismissAll(ctx context.Context) error
- func (a *AlarmActions) DismissAllRoute() string
- func (a *AlarmActions) DismissRoute(alarmID string) string
- func (a *AlarmActions) NextAlarmID(ctx context.Context) (string, error)
- func (a *AlarmActions) Snooze(ctx context.Context, alarmID string) error
- func (a *AlarmActions) VibrationTest(ctx context.Context) error
- type AlarmVibration
- type AudioActions
- func (a *AudioActions) AddFavorite(ctx context.Context, trackID string) error
- func (a *AudioActions) Categories(ctx context.Context) (any, error)
- func (a *AudioActions) Favorites(ctx context.Context) (any, error)
- func (a *AudioActions) Pair(ctx context.Context) error
- func (a *AudioActions) Pause(ctx context.Context) error
- func (a *AudioActions) Play(ctx context.Context, trackID string) error
- func (a *AudioActions) PlayerState(ctx context.Context) (any, error)
- func (a *AudioActions) RecommendedNext(ctx context.Context) (any, error)
- func (a *AudioActions) RemoveFavorite(ctx context.Context, trackID string) error
- func (a *AudioActions) Seek(ctx context.Context, positionMs int) error
- func (a *AudioActions) Tracks(ctx context.Context) ([]AudioTrack, error)
- func (a *AudioActions) Volume(ctx context.Context, level int) error
- type AudioTrack
- type AutopilotActions
- func (a *AutopilotActions) Details(ctx context.Context) (any, error)
- func (a *AutopilotActions) History(ctx context.Context) (any, error)
- func (a *AutopilotActions) Recap(ctx context.Context) (any, error)
- func (a *AutopilotActions) SetLevelSuggestions(ctx context.Context, enabled bool) error
- func (a *AutopilotActions) SetSnoreMitigation(ctx context.Context, enabled bool) error
- type BaseActions
- func (b *BaseActions) Info(ctx context.Context) (any, error)
- func (b *BaseActions) Presets(ctx context.Context) (any, error)
- func (b *BaseActions) RunPreset(ctx context.Context, name string) error
- func (b *BaseActions) SetAngle(ctx context.Context, head, foot int) error
- func (b *BaseActions) VibrationTest(ctx context.Context) error
- type Client
- func (c *Client) Alarms() *AlarmActions
- func (c *Client) Audio() *AudioActions
- func (c *Client) Authenticate(ctx context.Context) error
- func (c *Client) Autopilot() *AutopilotActions
- func (c *Client) Base() *BaseActions
- func (c *Client) CreateAlarm(ctx context.Context, alarm Alarm) (*Alarm, error)
- func (c *Client) CreateSchedule(ctx context.Context, s TemperatureSchedule) (*TemperatureSchedule, error)
- func (c *Client) CurrentDevice(ctx context.Context) (map[string]any, error)
- func (c *Client) DeleteAlarm(ctx context.Context, alarmID string) error
- func (c *Client) DeleteSchedule(ctx context.Context, id string) error
- func (c *Client) Device() *DeviceActions
- func (c *Client) DeviceStatus(ctx context.Context, deviceID string) (map[string]any, error)
- func (c *Client) EnsureDeviceID(ctx context.Context) (string, error)
- func (c *Client) EnsureUserID(ctx context.Context) error
- func (c *Client) GetAwayMode(ctx context.Context, userID string) (bool, error)
- func (c *Client) GetPresence(ctx context.Context, from, to, timezone string) (bool, error)
- func (c *Client) GetSleepDay(ctx context.Context, date string, timezone string) (*SleepDay, error)
- func (c *Client) GetSmartSchedule(ctx context.Context) (map[string]any, error)
- func (c *Client) GetStatus(ctx context.Context) (*TempStatus, error)
- func (c *Client) GetStatusForUser(ctx context.Context, userID string) (*TempStatus, error)
- func (c *Client) Household() *HouseholdActions
- func (c *Client) HouseholdUserTargets(ctx context.Context) ([]HouseholdUserTarget, error)
- func (c *Client) Identity() tokencache.Identity
- func (c *Client) ListAlarms(ctx context.Context) ([]Alarm, error)
- func (c *Client) ListSchedules(ctx context.Context) ([]TemperatureSchedule, error)
- func (c *Client) ListTracks(ctx context.Context) ([]AudioTrack, error)
- func (c *Client) Metrics() *MetricsActions
- func (c *Client) ReleaseFeatures(ctx context.Context) ([]ReleaseFeature, error)
- func (c *Client) SetAwayMode(ctx context.Context, userID string, away bool) error
- func (c *Client) SetTemperature(ctx context.Context, level int) error
- func (c *Client) SetTemperatureForUser(ctx context.Context, userID string, level int) error
- func (c *Client) TempModes() *TempModes
- func (c *Client) TokenExpiry() time.Time
- func (c *Client) Travel() *TravelActions
- func (c *Client) TrendDays(ctx context.Context, from, to, tz string) ([]any, error)
- func (c *Client) TurnOff(ctx context.Context) error
- func (c *Client) TurnOffForUser(ctx context.Context, userID string) error
- func (c *Client) TurnOn(ctx context.Context) error
- func (c *Client) TurnOnForUser(ctx context.Context, userID string) error
- func (c *Client) UpdateAlarm(ctx context.Context, alarmID string, patch map[string]any) (*Alarm, error)
- func (c *Client) UpdateSchedule(ctx context.Context, id string, patch map[string]any) (*TemperatureSchedule, error)
- func (c *Client) UseHosts(h Hosts)
- type DeviceActions
- func (d *DeviceActions) Info(ctx context.Context) (any, error)
- func (d *DeviceActions) Online(ctx context.Context) (any, error)
- func (d *DeviceActions) Owner(ctx context.Context) (any, error)
- func (d *DeviceActions) Peripherals(ctx context.Context) (any, error)
- func (d *DeviceActions) PrimingSchedule(ctx context.Context) (any, error)
- func (d *DeviceActions) PrimingTasks(ctx context.Context) (any, error)
- func (d *DeviceActions) Sides(ctx context.Context) (*DeviceSides, error)
- func (d *DeviceActions) Warranty(ctx context.Context) (any, error)
- type DeviceSides
- type Hosts
- type HouseholdActions
- func (h *HouseholdActions) CurrentSet(ctx context.Context) (any, error)
- func (h *HouseholdActions) Devices(ctx context.Context) (any, error)
- func (h *HouseholdActions) Guests(ctx context.Context) (any, error)
- func (h *HouseholdActions) Invitations(ctx context.Context) (any, error)
- func (h *HouseholdActions) Schedule(ctx context.Context) (any, error)
- func (h *HouseholdActions) Summary(ctx context.Context) (any, error)
- func (h *HouseholdActions) Users(ctx context.Context) (any, error)
- type HouseholdUserTarget
- type MetricsActions
- func (m *MetricsActions) Aggregate(ctx context.Context, out any) error
- func (m *MetricsActions) Insights(ctx context.Context, out any) error
- func (m *MetricsActions) Intervals(ctx context.Context, sessionID string, out any) error
- func (m *MetricsActions) Summary(ctx context.Context, out any) error
- func (m *MetricsActions) Trends(ctx context.Context, from, to, timezone string, out any) error
- type ReleaseFeature
- type SleepDay
- type Stage
- type TempModes
- func (t *TempModes) HotFlashActivate(ctx context.Context) error
- func (t *TempModes) HotFlashDeactivate(ctx context.Context) error
- func (t *TempModes) HotFlashStatus(ctx context.Context, out any) error
- func (t *TempModes) NapActivate(ctx context.Context) error
- func (t *TempModes) NapDeactivate(ctx context.Context) error
- func (t *TempModes) NapExtend(ctx context.Context) error
- func (t *TempModes) NapStatus(ctx context.Context, out any) error
- func (t *TempModes) TempEvents(ctx context.Context, from, to string, out any) error
- type TempStatus
- type TemperatureSchedule
- type TravelActions
- func (t *TravelActions) AirportSearch(ctx context.Context, query string) (any, error)
- func (t *TravelActions) CreatePlan(ctx context.Context, tripID string, body map[string]any) error
- func (t *TravelActions) CreateTrip(ctx context.Context, body map[string]any) error
- func (t *TravelActions) DeleteTrip(ctx context.Context, tripID string) error
- func (t *TravelActions) FlightStatus(ctx context.Context, flight string) (any, error)
- func (t *TravelActions) PlanTasks(ctx context.Context, planID string) (any, error)
- func (t *TravelActions) Plans(ctx context.Context, tripID string) (any, error)
- func (t *TravelActions) Trips(ctx context.Context) (any, error)
- func (t *TravelActions) UpdatePlan(ctx context.Context, planID string, body map[string]any) error
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidHouseholdUser = errors.New("invalid household user response")
var ErrNoSmartSchedule = errors.New("no Autopilot schedule configured")
ErrNoSmartSchedule is returned when the user has no Autopilot schedule configured.
Functions ¶
func IsEndpointUnavailable ¶
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.
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 ¶
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) 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) Tracks ¶
func (a *AudioActions) Tracks(ctx context.Context) ([]AudioTrack, 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) 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) 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 (*Client) Audio ¶
func (c *Client) Audio() *AudioActions
func (*Client) Authenticate ¶
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 (*Client) CreateSchedule ¶
func (c *Client) CreateSchedule(ctx context.Context, s TemperatureSchedule) (*TemperatureSchedule, error)
func (*Client) CurrentDevice ¶
CurrentDevice returns the user's current device record, or an empty map.
func (*Client) DeleteAlarm ¶
func (*Client) DeleteSchedule ¶
func (*Client) Device ¶
func (c *Client) Device() *DeviceActions
func (*Client) DeviceStatus ¶
DeviceStatus returns the device's sensor info, online state, last contact and side assignments, or an empty map.
func (*Client) EnsureDeviceID ¶
EnsureDeviceID fetches current device id if not already set.
func (*Client) EnsureUserID ¶
EnsureUserID populates UserID by calling /users/me if missing.
func (*Client) GetAwayMode ¶
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 (*Client) GetSleepDay ¶
GetSleepDay fetches sleep trends for a date (YYYY-MM-DD).
func (*Client) GetSmartSchedule ¶
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 (*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) 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 ¶
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 ¶
SetTemperature sets target heating/cooling level (-100..100) for the authenticated user's current pod side.
func (*Client) SetTemperatureForUser ¶
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) TokenExpiry ¶
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 ¶
TrendDays returns the raw trend days between two dates, every session included.
func (*Client) TurnOffForUser ¶
func (*Client) TurnOnForUser ¶
func (*Client) UpdateAlarm ¶
func (*Client) UpdateSchedule ¶
type DeviceActions ¶
type DeviceActions struct {
// contains filtered or unexported fields
}
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.
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 ¶
type Hosts struct {
Client string // https://client-api.8slp.net
App string // https://app-api.8slp.net
Auth string // https://auth-api.8slp.net
}
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)
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
type ReleaseFeature ¶
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 TempModes ¶
type TempModes struct {
// contains filtered or unexported fields
}
func (*TempModes) HotFlashActivate ¶
Hot flash controls
func (*TempModes) HotFlashDeactivate ¶
func (*TempModes) HotFlashStatus ¶
func (*TempModes) NapActivate ¶
Nap mode controls
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 (*TravelActions) CreatePlan ¶
func (*TravelActions) CreateTrip ¶
func (*TravelActions) DeleteTrip ¶
func (t *TravelActions) DeleteTrip(ctx context.Context, tripID string) error