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
- Variables
- func ValidToken(token string) bool
- type APIError
- type Client
- func (c *Client) Events(ctx context.Context) (*EventStream, error)
- func (c *Client) Family() string
- func (c *Client) Goto(ctx context.Context, position, speed float64) error
- func (c *Client) Info(ctx context.Context) (Info, error)
- func (c *Client) Lookup(ctx context.Context) (Connection, error)
- func (c *Client) Oscillate(ctx context.Context, speed, minY, maxY float64) (UltraState, error)
- func (c *Client) RateLimit() RateLimit
- func (c *Client) StopUltra(ctx context.Context) (UltraState, error)
- func (c *Client) StopVacuGlide(ctx context.Context) (VacuGlideState, error)
- func (c *Client) TargetSpeed(ctx context.Context, speed float64) (VacuGlideState, error)
- func (c *Client) UltraState(ctx context.Context) (UltraState, error)
- func (c *Client) VacuGlideState(ctx context.Context) (VacuGlideState, error)
- func (c *Client) Valve(ctx context.Context, valve string, open bool) (VacuGlideState, error)
- type Connection
- type Event
- type EventStream
- type Info
- type Options
- type RateLimit
- type UltraState
- type VacuGlideState
- type WrongDeviceError
Constants ¶
const ( FamilyUltra = "autoblow" FamilyVacuGlide = "vacuglide" )
API families: the path prefix of each device's commands.
const ( DeviceTypeUltra = "autoblow-ultra" DeviceTypeVacuGlide = "vacuglide" DeviceTypeVacuPump = "vacupump" )
Device types that the connected request reports.
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).
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.
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.
const (
// DefaultLatencyURL answers which cluster a device joined, from any region.
DefaultLatencyURL = "https://latency.autoblowapi.com"
)
Variables ¶
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 = 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 ¶
ValidToken accepts printable ASCII without spaces, the shape of a device token, so a pasted token cannot inject header or query syntax.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one device. It is safe for concurrent use.
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) Goto ¶
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) 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 ¶
Oscillate strokes between minY and maxY at a speed, all percent, at least 10 apart.
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 ¶
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.
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) 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 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