This repository has been archived on 2023-08-29. You can view files and clone it, but cannot push or open issues or pull requests.
automation/integration/google/trait.go
Dreaded_X dd03ae56ee
Some checks failed
continuous-integration/drone/push Build is failing
Reorganized code, added google home intergrations and added zigbee2mqtt kettle
2022-11-15 01:03:30 +01:00

73 lines
1.7 KiB
Go

package google
import "github.com/kr/pretty"
type Trait string
// https://developers.google.com/assistant/smarthome/traits/onoff
const TraitOnOff Trait = "action.devices.traits.OnOff"
func (d *Device) AddOnOffTrait(onlyCommand bool, onlyQuery bool) *Device {
d.Traits = append(d.Traits, TraitOnOff)
if onlyCommand {
d.Attributes["commandOnlyOnOff"] = true
}
if onlyQuery {
d.Attributes["queryOnlyOnOff"] = true
}
return d
}
// https://developers.google.com/assistant/smarthome/traits/startstop
const TraitStartStop = "action.devices.traits.StartStop"
func (d *Device) AddStartStopTrait(pausable bool) *Device {
d.Traits = append(d.Traits, TraitStartStop)
if pausable {
d.Attributes["pausable"] = true
}
return d
}
// https://developers.google.com/assistant/smarthome/traits/onoff
const TraitRunCycle = "action.devices.traits.RunCycle"
func (d *Device) AddRunCycleTrait() *Device {
d.Traits = append(d.Traits, TraitRunCycle)
return d
}
// https://developers.google.com/assistant/smarthome/traits/camerastream
const TraitCameraStream = "action.devices.traits.CameraStream"
func (d *Device) AddCameraStreamTrait(authTokenNeeded bool, supportedProtocols ...string) *Device {
d.Traits = append(d.Traits, TraitCameraStream)
if len(supportedProtocols) > 0 {
d.Attributes["cameraStreamSupportedProtocols"] = supportedProtocols
}
d.Attributes["cameraStreamNeedAuthToken"] = authTokenNeeded
pretty.Logln(d)
return d
}
// https://developers.google.com/assistant/smarthome/traits/scene
const TraitScene = "action.devices.traits.Scene"
func (d *Device) AddSceneTrait(reversible bool) *Device {
d.Traits = append(d.Traits, TraitScene)
if reversible {
d.Attributes["sceneReversible"] = true
}
return d
}