autoblow

package
v0.1.0-alpha.87 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: GPL-3.0 Imports: 14 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

Overview

Package autoblow is a client for Autoblow's cloud device API (API V1 at developers.autoblow.com): the Autoblow Ultra and the VacuGlide. It speaks HTTP and server-sent events only. What a command means for motion belongs to the transport owners (ADR 0069).

Index

Constants

View Source
const (
	FamilyUltra     = "autoblow"
	FamilyVacuGlide = "vacuglide"
)

API families: the path prefix of each device's commands.

View Source
const (
	DeviceTypeUltra     = "autoblow-ultra"
	DeviceTypeVacuGlide = "vacuglide"
	DeviceTypeVacuPump  = "vacupump"
)

Device types that the connected request reports.

View Source
const (
	ValveStrokePlus  = "stroke-plus"
	ValveStrokeMinus = "stroke-minus"
)

Valves of the VacuGlide's cap. Opening one moves air into or out of the closed sleeve: stroke plus makes the stroke longer and tighter, stroke minus shorter and looser (ADR 0069 records how this was established).

View Source
const (
	ModeOnlineConnected    = "ONLINE_CONNECTED"
	ModeGoTo               = "GO_TO"
	ModeOscillatorPlaying  = "OSCILLATOR_PLAYING"
	ModeOscillatorPaused   = "OSCILLATOR_PAUSED"
	ModeTargetSpeedPlaying = "TARGET_SPEED_PLAYING"
	ModeTargetSpeedPaused  = "TARGET_SPEED_PAUSED"
)

Operational modes the owners act on.

View Source
const (
	EventConnected = "connected"
	EventHeartbeat = "heartbeat"
	// The Ultra's buttons.
	ButtonUltraPause     = "pause-button-pressed"
	ButtonUltraMode      = "mode-button-pressed"
	ButtonUltraSpeedUp   = "speed-up-button-pressed"
	ButtonUltraSpeedDown = "speed-down-button-pressed"
	// The VacuGlide's buttons.
	ButtonVacuGlideMode       = "mode-button-pressed"
	ButtonVacuGlideSpeedPlus  = "speed-plus-button-pressed"
	ButtonVacuGlideSpeedMinus = "speed-minus-button-pressed"
)

Button events. While a device is online its buttons stop acting on it and arrive here instead, so the app decides what each one does.

View Source
const (
	// DefaultLatencyURL answers which cluster a device joined, from any region.
	DefaultLatencyURL = "https://latency.autoblowapi.com"
)

Variables

View Source
var (
	// ErrNoToken means no device token was saved.
	ErrNoToken = errors.New("save the device token first")
	// ErrBadToken rejects a token that cannot be a device token.
	ErrBadToken = errors.New("the device token contains characters a token cannot have")
	// ErrOffline means the device is not connected to Autoblow's cloud.
	ErrOffline = errors.New("the device is not online: turn on its online mode")
	// ErrUnauthorized means Autoblow rejected the token.
	ErrUnauthorized = errors.New("autoblow rejected the device token")
	// ErrRateLimited means Autoblow is limiting requests for this token.
	ErrRateLimited = errors.New("autoblow is limiting requests for this device")
	// ErrBadCluster means the lookup named a server outside Autoblow's cloud.
	ErrBadCluster = errors.New("autoblow reported an unexpected server")
	// ErrNotResolved means a device request was made before the lookup.
	ErrNotResolved = errors.New("look up the device's cluster first")
)

Functions

func ValidToken

func ValidToken(token string) bool

ValidToken accepts printable ASCII without spaces, the shape of a device token, so a pasted token cannot inject header or query syntax.

Types

type APIError

type APIError struct {
	Status  int
	Code    string
	Message string
}

APIError is a refused request. Message is Autoblow's own description.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client talks to one device. It is safe for concurrent use.

func New

func New(family, token string, options Options) (*Client, error)

New returns a client for one device token.

func (*Client) Events

func (c *Client) Events(ctx context.Context) (*EventStream, error)

Events opens the device's event stream on its cluster. The stream takes the token in its query, so the request URL must never be logged; errors from this package never include it. ctx bounds the stream's life.

func (*Client) Family

func (c *Client) Family() string

Family names the device API family.

func (*Client) Goto

func (c *Client) Goto(ctx context.Context, position, speed float64) error

Goto moves the Ultra to a position at a speed, both percent. The cloud answers once it has sent the command, not when the move ends.

func (*Client) Info

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

Info reads the device's firmware.

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context) (Connection, error)

Lookup asks which cluster the device joined and binds later requests to it. A device that is offline, or a token for another kind of device, is an error, so a connected client always reaches the right device.

func (*Client) Oscillate

func (c *Client) Oscillate(ctx context.Context, speed, minY, maxY float64) (UltraState, error)

Oscillate strokes between minY and maxY at a speed, all percent, at least 10 apart.

func (*Client) RateLimit

func (c *Client) RateLimit() RateLimit

RateLimit reports the last limit the cloud reported.

func (*Client) StopUltra

func (c *Client) StopUltra(ctx context.Context) (UltraState, error)

StopUltra stops the Ultra whatever it is doing.

func (*Client) StopVacuGlide

func (c *Client) StopVacuGlide(ctx context.Context) (VacuGlideState, error)

StopVacuGlide stops the motor whatever is playing.

func (*Client) TargetSpeed

func (c *Client) TargetSpeed(ctx context.Context, speed float64) (VacuGlideState, error)

TargetSpeed runs the VacuGlide's motor at a constant speed, in percent.

func (*Client) UltraState

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

UltraState reads the Ultra's state.

func (*Client) VacuGlideState

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

VacuGlideState reads the VacuGlide's state.

func (*Client) Valve

func (c *Client) Valve(ctx context.Context, valve string, open bool) (VacuGlideState, error)

Valve opens or closes one of the VacuGlide's stroke valves.

type Connection

type Connection struct {
	Connected  bool   `json:"connected"`
	Cluster    string `json:"cluster"`
	DeviceType string `json:"deviceType"`
}

Connection is the lookup result.

type Event

type Event struct {
	Name string
}

Event is one server-sent event by name. Its data can carry the device token, so it is never kept or logged.

type EventStream

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

EventStream reads one device's server-sent events.

func (*EventStream) Close

func (s *EventStream) Close() error

Close ends the stream.

func (*EventStream) Next

func (s *EventStream) Next() (Event, error)

Next blocks until the next event. A heartbeat is an event too, so a reader can tell a quiet stream from a dead one.

type Info

type Info struct {
	FirmwareStatus  string  `json:"firmwareStatus"`
	FirmwareVersion float64 `json:"firmwareVersion"`
	FirmwareBranch  string  `json:"firmwareBranch"`
	HardwareVersion string  `json:"hardwareVersion"`
	DeviceType      string  `json:"deviceType"`
}

Info describes the device's firmware.

type Options

type Options struct {
	HTTPClient *http.Client
	// LatencyURL replaces the cluster lookup host, for tests and simulation.
	LatencyURL string
	// ClusterURL maps a reported cluster to its base URL. Nil accepts only
	// *.autoblowapi.com clusters over HTTPS, so the token never leaves
	// Autoblow's servers.
	ClusterURL func(cluster string) (string, error)
}

Options configures a client. The zero value reaches Autoblow's cloud.

type RateLimit

type RateLimit struct {
	Known     bool
	Limit     int
	Remaining int
	Reset     time.Time
}

RateLimit is the last limit the cloud reported, when it reports one.

type UltraState

type UltraState struct {
	OperationalMode       string  `json:"operationalMode"`
	LocalScript           int     `json:"localScript"`
	LocalScriptSpeed      int     `json:"localScriptSpeed"`
	MotorTemperature      float64 `json:"motorTemperature"`
	OscillatorTargetSpeed float64 `json:"oscillatorTargetSpeed"`
	OscillatorLowPoint    float64 `json:"oscillatorLowPoint"`
	OscillatorHighPoint   float64 `json:"oscillatorHighPoint"`
	SyncScriptToken       string  `json:"syncScriptToken"`
}

UltraState is the Autoblow Ultra's reported state.

type VacuGlideState

type VacuGlideState struct {
	OperationalMode  string  `json:"operationalMode"`
	LocalScript      int     `json:"localScript"`
	TargetSpeed      float64 `json:"targetSpeed"`
	StrokePlusValve  bool    `json:"strokePlusValve"`
	StrokeMinusValve bool    `json:"strokeMinusValve"`
	SyncScriptToken  string  `json:"syncScriptToken"`
}

VacuGlideState is the VacuGlide's reported state.

type WrongDeviceError

type WrongDeviceError struct {
	Want, Got string
}

WrongDeviceError means the token belongs to another kind of device.

func (WrongDeviceError) Error

func (e WrongDeviceError) Error() string

Jump to

Keyboard shortcuts

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