Documentation
¶
Index ¶
- Constants
- Variables
- type AccessTokenValidator
- type Command
- type CommandArg
- type CommandBrightnessAbsolute
- type CommandBrightnessRelative
- type CommandColorAbsolute
- type CommandGeneric
- type CommandMute
- type CommandNextInput
- type CommandOnOff
- type CommandPreviousInput
- type CommandSetFanSpeed
- type CommandSetInput
- type CommandSetVolume
- type CommandSetVolumeRelative
- type CommandThermostatTemperatureSetpoint
- type Device
- func (d *Device) AddBrightnessTrait(onlyCommand bool) *Device
- func (d *Device) AddColourTemperatureTrait(minTempK int, maxTempK int, onlyCommand bool) *Device
- func (d *Device) AddColourTrait(model string, onlyCommand bool) *Device
- func (d *Device) AddInputSelectorTrait(availableInputs []DeviceInput, ordered bool) *Device
- func (d *Device) AddOnOffTrait(onlyCommand, onlyQuery bool) *Device
- func (d *Device) AddVolumeTrait(maxLevel int, canMute bool, onlyCommand bool) *Device
- func (d Device) MarshalJSON() ([]byte, error)
- func (d *Device) UnmarshalJSON(data []byte) error
- type DeviceArg
- type DeviceInfo
- type DeviceInput
- type DeviceInputName
- type DeviceName
- type DeviceState
- func (ds DeviceState) MarshalJSON() ([]byte, error)
- func (ds DeviceState) RecordBrightness(brightness int) DeviceState
- func (ds DeviceState) RecordColorHSV(hue float64, saturation float64, value float64) DeviceState
- func (ds DeviceState) RecordColorRGB(spectrumRgb int) DeviceState
- func (ds DeviceState) RecordColorTemperature(temperatureK int) DeviceState
- func (ds DeviceState) RecordInput(input string) DeviceState
- func (ds DeviceState) RecordOnOff(on bool) DeviceState
- func (ds DeviceState) RecordVolume(volume int, isMuted bool) DeviceState
- func (ds *DeviceState) UnmarshalJSON(data []byte) error
- type ExecuteRequest
- type ExecuteResponse
- type OtherDeviceID
- type Provider
- type QueryRequest
- type QueryResponse
- type Service
- type SyncResponse
Constants ¶
const ( RGB = "rgb" HSV = "hsv" )
ColorModel defines which model of the color wheel the device supports.
const (
// GoogleFulfillmentPath represents the HTTP path which the Google fulfillment hander will call
GoogleFulfillmentPath = "/fulfillment"
)
Variables ¶
var ( // ErrSyncFailed is returned if the request to HomeGraph to force a SYNC operation failed. // The log will contain more information about what occurred. ErrSyncFailed = errors.New("sync failed") // ErrReportStateFailed is returned if the request to HomeGraph to update a device failed. // The log will contain more information about what occurred. ErrReportStateFailed = errors.New("report state failed") )
Functions ¶
This section is empty.
Types ¶
type AccessTokenValidator ¶
type AccessTokenValidator interface { // Validate performs the actual token validation. Returning an error will force validation to fail. // The user ID that corresponds to the token should be returned on success. Validate(context.Context, string) (string, error) }
AccessTokenValidator allows for the auth token supplied by Google to be validated.
type Command ¶
type Command struct { Name string Generic *CommandGeneric BrightnessAbsolute *CommandBrightnessAbsolute BrightnessRelative *CommandBrightnessRelative ColorAbsolute *CommandColorAbsolute OnOff *CommandOnOff Mute *CommandMute SetVolume *CommandSetVolume AdjustVolume *CommandSetVolumeRelative SetInput *CommandSetInput NextInput *CommandNextInput PreviousInput *CommandPreviousInput SetFanSpeed *CommandSetFanSpeed ThermostatTemperatureSetpoint *CommandThermostatTemperatureSetpoint }
Command defines which command, and what details, are being specified. Only one of the contained fields will be set at any point in time.
func (Command) MarshalJSON ¶
MarshalJSON is a custom JSON serializer for our Command
func (*Command) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON deserializer for our Command
type CommandArg ¶
CommandArg contains the fields used to execute a change on a set of devices. Only one of the various pointers in Command should be set per command.
type CommandBrightnessAbsolute ¶
type CommandBrightnessAbsolute struct {
Brightness int `json:"brightness"`
}
CommandBrightnessAbsolute requests to set the brightness to an absolute value See https://developers.google.com/assistant/smarthome/traits/brightness
type CommandBrightnessRelative ¶
type CommandBrightnessRelative struct { RelativePercent int `json:"brightnessRelativePercent"` RelativeWeight int `json:"brightnessRelativeWeight"` }
CommandBrightnessRelative requests to set the brightness to a relative level Only one of the two fields will be set. See https://developers.google.com/assistant/smarthome/traits/brightness
type CommandColorAbsolute ¶
type CommandColorAbsolute struct { Color struct { Name string `json:"name"` Temperature int `json:"temperature"` RGB int `json:"spectrumRGB"` HSV struct { Hue float64 `json:"hue"` Saturation float64 `json:"saturation"` Value float64 `json:"value"` } `json:"spectrumHSV"` } `json:"color"` }
CommandColorAbsolute requests to set the colour of a light to a particular value. Only one of temperature, RGB and HSV will be set. See https://developers.google.com/assistant/smarthome/traits/colorsetting
type CommandGeneric ¶
type CommandGeneric struct { Command string `json:"command"` Params map[string]interface{} `json:"params"` }
CommandGeneric contains a command definition which hasn't been parsed into a specific command structure. This is intended to support newly defined commands which callers of this SDK may handle but this does not yet support.
type CommandMute ¶
type CommandMute struct {
Mute bool `json:"mute"`
}
CommandMute requests the device be muted. See https://developers.google.com/assistant/smarthome/traits/volume
type CommandNextInput ¶
type CommandNextInput struct { }
CommandNextInput requests the device input be changed to the next logical one. See https://developers.google.com/assistant/smarthome/traits/inputselector
type CommandOnOff ¶
type CommandOnOff struct {
On bool `json:"on"`
}
CommandOnOff requests to turn the entity on or off. See https://developers.google.com/assistant/smarthome/traits/onoff
type CommandPreviousInput ¶
type CommandPreviousInput struct { }
CommandPreviousInput requests the device input be changed to the previous logical one. See https://developers.google.com/assistant/smarthome/traits/inputselector
type CommandSetFanSpeed ¶
type CommandSetFanSpeed struct { // The requested speed setting of the fan, which corresponds to one of the // settings specified during the sync response. FanSpeed *string `json:"fanSpeed,omitempty"` // The requested speed setting percentage (0-100). FanSpeedPercent *float32 `json:"fanSpeedPercent,omitempty"` }
CommandSetFanSpeed requests the device fan speed be set to the specified value.
See https://developers.google.com/assistant/smarthome/traits/fanspeed
type CommandSetInput ¶
type CommandSetInput struct {
NewInput string `json:"newInput"`
}
CommandSetInput requests the device input be changed. See https://developers.google.com/assistant/smarthome/traits/inputselector
type CommandSetVolume ¶
type CommandSetVolume struct {
Level int `json:"volumeLevel"`
}
CommandSetVolume requests the device volume be set to the specified value. See https://developers.google.com/assistant/smarthome/traits/volume
type CommandSetVolumeRelative ¶
type CommandSetVolumeRelative struct {
Amount int `json:"relativeSteps"`
}
CommandSetVolumeRelative requests the device volume be increased or decreased. See https://developers.google.com/assistant/smarthome/traits/volume
type CommandThermostatTemperatureSetpoint ¶
type CommandThermostatTemperatureSetpoint struct { // Target temperature setpoint. Supports up to one decimal place. ThermostatTemperatureSetpointCelcius float32 `json:"thermostatTemperatureSetpoint"` }
CommandThermostatTemperatureSetpoint requests the target temperature be set to a particular temperature.
type Device ¶
type Device struct { // ID of the device ID string // Type of the device. // See https://developers.google.com/assistant/smarthome/guides is a list of possible types Type string // Traits of the device. // See https://developers.google.com/assistant/smarthome/traits for a list of possible traits // The set of assigned traits will dictate which actions can be performed on the device Traits map[string]bool // Name of the device. Name DeviceName // WillReportState using the ReportState API (should be true) WillReportState bool // RoomHint guides Google as to which room this device is in RoomHint string // Attributes linked to the defined traits Attributes map[string]interface{} // DeviceInfo that is physically defined DeviceInfo DeviceInfo // OtherDeviceIDs allows for this to be logically linked to other devices OtherDeviceIDs []OtherDeviceID // CustomData specified which will be included unmodified in subsequent requests. CustomData map[string]interface{} }
Device represents a single provider-supplied device profile.
func NewLight ¶
NewLight creates a new device with the attributes for an on-off light. This can be customized with any of the light-related traits (Color, Brightness).
func NewSimpleAVReceiver ¶
func NewSimpleAVReceiver(id string, inputs []DeviceInput, maxLevel int, canMute bool, onlyCommand bool) *Device
NewSimpleAVReceiver creates a new device with the attributes for a simple AV receiver setup.
func NewSwitch ¶
NewSwitch creates a new device with the attributes for an on-off switch. This can be customized with the Brightness trait.
func (*Device) AddBrightnessTrait ¶
AddBrightnessTrait indicates this device is capable of having its brightness controlled. If the device does not support querying, set onlyCommand to true (i.e. a write-only switch). See https://developers.google.com/assistant/smarthome/traits/brightness
func (*Device) AddColourTemperatureTrait ¶
AddColourTemperatureTrait indicates this device is capable of having its colour display controlled using the colour temperature model. This can be set alongside AddColorSetting to indicate both color temperature and another algorithm are supported. If the device does not support querying, set onlyCommand to true (i.e. a write-only lightbulb). See https://developers.google.com/assistant/smarthome/traits/colorsetting
func (*Device) AddColourTrait ¶
AddColourTrait indicates this device is capable of having its colour display controlled using the specified color model. It is mutually exclusive to support RGB or HSV. It is possible to support either one of RGB and HSV alongside color temperature. See AddColorTemperatureSetting If the device does not support querying, set onlyCommand to true (i.e. a write-only lightbulb). See https://developers.google.com/assistant/smarthome/traits/colorsetting
func (*Device) AddInputSelectorTrait ¶
func (d *Device) AddInputSelectorTrait(availableInputs []DeviceInput, ordered bool) *Device
AddInputSelectorTrait indicates this device is capable of having its input selected. See https://developers.google.com/assistant/smarthome/traits/inputselector
func (*Device) AddOnOffTrait ¶
AddOnOffTrait indicates this device is capable of having its state toggled on or off. If the device can be commanded but not queried, set onlyCommand to true (i.e. a write-only switch). If the devie cannot be commanded but only queried, set onlyQuery to true (i.e. a sensor). See https://developers.google.com/assistant/smarthome/traits/onoff
func (*Device) AddVolumeTrait ¶
AddVolumeTrait indicates this device is capable of having its volume controlled See https://developers.google.com/assistant/smarthome/traits/volume
func (Device) MarshalJSON ¶
MarshalJSON is a custom JSON serializer for our Device
func (*Device) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON deserializer for our Device
type DeviceArg ¶
DeviceArg contains the common fields used when executing requests against a device. It has 2 fields of note: - the ID of the device - any custom data supplied for the device ID as part of the original response to SYNC
type DeviceInfo ¶
type DeviceInfo struct { // Manufacturer of the device Manufacturer string // Model of the device Model string // HwVersion of the device HwVersion string // SwVersion of the device SwVersion string }
DeviceInfo contains different properties of the device
type DeviceInput ¶
type DeviceInput struct { Key string `json:"key"` Names []DeviceInputName `json:"names"` }
DeviceInput represents a single input of a device
type DeviceInputName ¶
type DeviceInputName struct { LanguageCode string `json:"lang"` Synonyms []string `json:"name_synonym"` }
DeviceInputName represents the human-readable name shown for an input
type DeviceName ¶
type DeviceName struct { // DefaultNames (not user settable) DefaultNames []string // Name supplied by the user for display purposes Name string // Nicknames given to this, should a user have multiple ways to refer to the device Nicknames []string }
DeviceName contains different ways of identifying the device
type DeviceState ¶
DeviceState contains the state of a device.
func NewDeviceState ¶
func NewDeviceState(online bool) DeviceState
NewDeviceState creates a new device state to be added to as defined by the relevant traits on a device.
func (DeviceState) MarshalJSON ¶
func (ds DeviceState) MarshalJSON() ([]byte, error)
MarshalJSON is a custom JSON serializer for our DeviceState
func (DeviceState) RecordBrightness ¶
func (ds DeviceState) RecordBrightness(brightness int) DeviceState
RecordBrightness adds the current brightness to the device. Should only be applied to devices with the Brightness trait See https://developers.google.com/assistant/smarthome/traits/brightness
func (DeviceState) RecordColorHSV ¶
func (ds DeviceState) RecordColorHSV(hue float64, saturation float64, value float64) DeviceState
RecordColorHSV adds the current color in HSV to the device. Should only be applied to devices with the ColorSetting trait See https://developers.google.com/assistant/smarthome/traits/colorsetting
func (DeviceState) RecordColorRGB ¶
func (ds DeviceState) RecordColorRGB(spectrumRgb int) DeviceState
RecordColorRGB adds the current color in RGB to the device. Should only be applied to devices with the ColorSetting trait See https://developers.google.com/assistant/smarthome/traits/colorsetting
func (DeviceState) RecordColorTemperature ¶
func (ds DeviceState) RecordColorTemperature(temperatureK int) DeviceState
RecordColorTemperature adds the current color temperature (in Kelvin) to the device. Should only be applied to devices with the ColorSetting trait See https://developers.google.com/assistant/smarthome/traits/colorsetting
func (DeviceState) RecordInput ¶
func (ds DeviceState) RecordInput(input string) DeviceState
RecordInput adds the current input active to the device. Should only be applied to devices with the InputSelector trait See https://developers.google.com/assistant/smarthome/traits/inputselector
func (DeviceState) RecordOnOff ¶
func (ds DeviceState) RecordOnOff(on bool) DeviceState
RecordOnOff adds the current on/off state to the device. Should only be applied to devices with the OnOff trait See https://developers.google.com/assistant/smarthome/traits/onoff
func (DeviceState) RecordVolume ¶
func (ds DeviceState) RecordVolume(volume int, isMuted bool) DeviceState
RecordVolume adds the current volume state to the device. Should only be applied to devices with the Volume trait See https://developers.google.com/assistant/smarthome/traits/volume
func (*DeviceState) UnmarshalJSON ¶
func (ds *DeviceState) UnmarshalJSON(data []byte) error
UnmarshalJSON is a custom JSON deserializer for our DeviceState
type ExecuteRequest ¶
type ExecuteRequest struct { Commands []CommandArg AgentID string }
ExecuteRequest includes what is being asked for by the Google Assistant when making a change. The customData is a JSON object originally returned during the Sync operation.
type ExecuteResponse ¶
type ExecuteResponse struct { UpdatedState DeviceState UpdatedDevices []string OfflineDevices []string FailedDevices map[string]struct { Devices []string } }
ExecuteResponse includes the results of an Execute command to be sent back to the Google home graph after an execute. Between the UpdatedDevices and FailedDevices maps all device IDs in the Execute request should be accounted for.
type OtherDeviceID ¶
OtherDeviceID contains alternative ways to identify this device.
type Provider ¶
type Provider interface { Sync(context.Context, string) (*SyncResponse, error) Disconnect(context.Context, string) error Query(context.Context, *QueryRequest) (*QueryResponse, error) Execute(context.Context, *ExecuteRequest) (*ExecuteResponse, error) }
Provider exposes methods that can be invoked by the Google Smart Home Action intents
type QueryRequest ¶
QueryRequest includes what is being asked for by the Google Smart Home Action when querying.
type QueryResponse ¶
type QueryResponse struct {
States map[string]DeviceState
}
QueryResponse includes what should be returned in response to the query to the Google Home Smart Action. The States map should have the same IDs supplied in the request.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service links together the updates coming from the different sources and ensures they are consistent. Updates may come in via: - the GoogleCallbackHandler, which is registered externally on an HTTPS endpoint which the Google Smart Home Actions framework will POST to - the API calls made against this service by the underlying device
func NewService ¶
func NewService(logger *zap.Logger, atValidator AccessTokenValidator, provider Provider, hgService *homegraph.Service) *Service
NewService creates a new service to handle Google Action operations. It is required that an access token validator be specified to properly process requests. This access token validator should be pointed to the same data source as the OAuth2 server configured in the Google Smart Home Actions portal in the OAuth2 account linking section.
func (*Service) GoogleFulfillmentHandler ¶
func (s *Service) GoogleFulfillmentHandler(w http.ResponseWriter, r *http.Request)
GoogleFulfillmentHandler must be registered on an HTTPS endpoint at the path specified by GoogleFulfillmentPath This HTTPS endpoint needs to be registered on the Smart Home Actions fulfillment path. See https://developers.google.com/assistant/smarthome/concepts/fulfillment-authentication or https://developers.google.com/assistant/smarthome/develop/process-intents for details.
func (*Service) ReportState ¶
func (s *Service) ReportState(ctx context.Context, agentUserID string, deviceStates map[string]DeviceState) error
ReportState is used to report a state change which occurred on a device to the Google HomeGraph. This should be called whenever a local action triggers a change, as well as after receiving an Execute callback. The supplied state argument should have a complete definition of the device state (i.e. do not perform incremental updates). The deviceStates map is indexed by device ID. This library does not attempt to report on state changes automatically as it is possible that the action triggers a change on the device that is not reflected in the initial request. It is best if the underlying service ensures that the Google HomeGraph is kept in sync through an explicit state update after execution.
func (*Service) RequestSync ¶
RequestSync is used to trigger a Google HomeGraph sync operation. This should be called whenever the list of devices, or their properties, change. This will request a sync occur synchronously, so make sure that the Sync method is not blocked on anything this method may be doing.
type SyncResponse ¶
type SyncResponse struct {
Devices []*Device
}
SyncResponse contains the set of devices to supply to the Google Smart Home Action when setting up.