client

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 15 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 (server omits or nulls the `smart` field).

Functions

This section is empty.

Types

type Alarm

type Alarm struct {
	ID         string  `json:"id"`
	Enabled    bool    `json:"enabled"`
	Time       string  `json:"time"`
	DaysOfWeek []int   `json:"daysOfWeek"`
	Vibration  bool    `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) Dismiss

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

func (*AlarmActions) DismissAll

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

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 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
	// 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) DeleteAlarm

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

func (*Client) Device

func (c *Client) Device() *DeviceActions

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 added in v0.2.4

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 `smart` subfield of the app-api temperature resource (the Autopilot schedule).

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) 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) Travel

func (c *Client) Travel() *TravelActions

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)

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 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) Intervals

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

func (*MetricsActions) Trends

func (m *MetricsActions) Trends(ctx context.Context, from, to, tz 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 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