shactions

package module
v0.0.0-...-4d3504f Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAuthExpired indicates credentials have expired.
	ErrAuthExpired = ErrorCode{
					// contains filtered or unexported fields
	}

	// ErrAuthFailure is a general failure to authenticate.
	ErrAuthFailure = ErrorCode{
					// contains filtered or unexported fields
	}

	// ErrDeviceOffline indicates the target is unreachable.
	ErrDeviceOffline = ErrorCode{
						// contains filtered or unexported fields
	}

	// ErrTimeout indicates an internal timeout.
	ErrTimeout = ErrorCode{
				// contains filtered or unexported fields
	}

	// ErrDeviceTurnedOff indicates the device is turned hard off (different than unreachable).
	ErrDeviceTurnedOff = ErrorCode{
						// contains filtered or unexported fields
	}

	// ErrDeviceNotFound reports that the device doesn't exist on the partner's side. This indicates an internal error such as data synchronization or a race condition.
	ErrDeviceNotFound = ErrorCode{
						// contains filtered or unexported fields
	}

	// ErrValueOutOfRange indicates the range in parameters is out of bounds, such as the temperature of an AC unit.
	ErrValueOutOfRange = ErrorCode{
						// contains filtered or unexported fields
	}

	// ErrNotSupported indicates the command or its parameters are unsupported (this should generally not happen, as traits and business logic should prevent it).
	ErrNotSupported = ErrorCode{
					// contains filtered or unexported fields
	}

	// ErrProtocolError is a general failure in processing the request.
	ErrProtocolError = ErrorCode{
						// contains filtered or unexported fields
	}

	// ErrUnknownError is for any other type of error, although in practice should be treated as a TODO.
	ErrUnknownError = ErrorCode{
					// contains filtered or unexported fields
	}
)

Functions

This section is empty.

Types

type Device

type Device struct {
	DeviceKey

	Type            string                 `json:"type"`
	Traits          []string               `json:"traits"`          // the possible ways this can be controlled
	WillReportState bool                   `json:"willReportState"` // true is real-time, false is polling
	RoomHint        string                 `json:"roomHint,omitempty"`
	Attributes      map[string]interface{} `json:"attributes,omitempty"`
	DeviceInfo      *DeviceInfo            `json:"deviceInfo,omitempty"`

	Name struct {
		Name         string   `json:"name"`
		DefaultNames []string `json:"defaultNames,omitempty"`
		Nicknames    []string `json:"nicknames,omitempty"`
	} `json:"name"`
}

Device describes a device which can be controlled.

type DeviceInfo

type DeviceInfo struct {
	Manufacturer    string `json:"manufacturer,omitempty"`
	Model           string `json:"model,omitempty"`
	HardwareVersion string `json:"hwVersion,omitempty"`
	SoftwareVersion string `json:"swVersion,omitempty"`
}

DeviceInfo describes a device's manufacturer, model etc.

type DeviceKey

type DeviceKey struct {
	ID         string                 `json:"id"`
	CustomData map[string]interface{} `json:"customData,omitempty"`
}

DeviceKey identifies a device by its ID and optional custom key/value pairs.

type ErrorCode

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

ErrorCode is an internal, recoverable error caused by Smart Home Actions.

func (ErrorCode) Error

func (ec ErrorCode) Error() string

Error returns the internal error code, or a blank string if nil.

type Exec

type Exec struct {
	Task   string                 `json:"command"`
	Params map[string]interface{} `json:"params"`
}

Exec identifies a general user request.

type RequestFulfiller

type RequestFulfiller interface {
	Sync() (string, []Device, error)
	Query([]DeviceKey) ([]States, error)
	Exec([]DeviceKey, []Exec) ([]States, error)
	Disconnect() error
}

RequestFulfiller fulfills a single request (potentially in a series).

type SmartHomeActions

type SmartHomeActions struct {
	Request func(*http.Request, string) (RequestFulfiller, error)
}

SmartHomeActions contains the Request method, which can be used to fulfill a request.

func (*SmartHomeActions) ServeHTTP

func (sh *SmartHomeActions) ServeHTTP(w http.ResponseWriter, r *http.Request)

type States

type States struct {
	Status      Status // for Exec only, ignored for Query
	ErrorCode   ErrorCode
	DebugString string
	Online      bool
	// contains filtered or unexported fields
}

States is a helper that wraps a Map plus some known, fixed keys.

func (States) Extract

func (s States) Extract() map[string]interface{}

extract converts this States into a single map.

func (*States) Set

func (s *States) Set(key string, value interface{})

Set is a convenience helper to set a map value.

type Status

type Status int

Status is a status returned by this API.

const (
	// Unknown is the default, zero state of Status.
	Unknown Status = iota

	// Success confirms that the command(s) has/have succeeded.
	Success

	// Pending indicates that the command(s) are enqueued but expected to succeed.
	Pending

	// Offline indicates that the target devices(s) are in an offline state or unreachable.
	Offline

	// Error requires that the ErrorCode field is also set.
	Error
)

func (Status) String

func (status Status) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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