Documentation ¶
Index ¶
- Constants
- type ACFanSpeed
- type ACMode
- type Client
- type Command
- func ACSetAll(temperature int, mode ACMode, fanSpeed ACFanSpeed, power PowerState) Command
- func ButtonPush(name string) Command
- func Press() Command
- func SetMode(mode HumidifierMode) Command
- func SetPosition(index int, mode SetPositionMode, position int) Command
- func TurnOff() Command
- func TurnOn() Command
- type Device
- type DeviceService
- type DeviceStatus
- type HumidifierMode
- type InfraredDevice
- type Option
- type PhysicalDeviceType
- type PowerState
- type Scene
- type SceneService
- type SetPositionMode
- type VirtualDeviceType
Constants ¶
const DefaultEndpoint = "https://api.switch-bot.com"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ACFanSpeed ¶
type ACFanSpeed int
ACFanSpeed represents a fan speed mode for air conditioner.
const ( ACAutoSpeed ACFanSpeed = iota + 1 ACLow ACMedium ACHigh )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func New ¶
New returns a new switchbot client associated with given openToken. See https://github.com/OpenWonderLabs/SwitchBotAPI/blob/7a68353d84d07d439a11cb5503b634f24302f733/README.md#getting-started for getting openToken for SwitchBot API.
func (*Client) Device ¶
func (c *Client) Device() *DeviceService
Device returns the Service object for device APIs.
func (*Client) Scene ¶
func (c *Client) Scene() *SceneService
Scene returns the Service Object for scene APIs.
type Command ¶
type Command interface {
// contains filtered or unexported methods
}
Command is an interface which represents Commands for devices to be used (*Client).Device().Command() method.
func ACSetAll ¶
func ACSetAll(temperature int, mode ACMode, fanSpeed ACFanSpeed, power PowerState) Command
ACSetAll returns a new command which set all state of air conditioner.
func ButtonPush ¶
ButtonPush returns a command which triggers button push.
func SetMode ¶
func SetMode(mode HumidifierMode) Command
SetMode sets a mode for Humidifier. mode can be take one of HumidifierMode constants or 0 - 100 value. To use exact value 0 - 100, you need to pass like HumidifierMode(38).
func SetPosition ¶
func SetPosition(index int, mode SetPositionMode, position int) Command
SetPosition returns a new Command which sets curtain devices' position. The third argument `position` can be take 0 - 100 value, 0 means opened and 100 means closed. The position value will be treated as 0 if the given value is less than 0, or treated as 100 if the given value is over 100.
type Device ¶
type Device struct { ID string `json:"deviceId"` Name string `json:"deviceName"` Type PhysicalDeviceType `json:"deviceType"` IsEnableCloudService bool `json:"enableCloudService"` Hub string `json:"hubDeviceId"` Curtains []string `json:"curtainDeviceesIds"` IsCalibrated bool `json:"calibrate"` IsGrouped bool `json:"group"` IsMaster bool `json:"master"` OpenDirection string `json:"openDirection"` }
Device represents a physical SwitchBot device.
type DeviceService ¶
type DeviceService struct {
// contains filtered or unexported fields
}
DeviceService handles API calls related to devices. The devices API is used to access the properties and states of SwitchBot devices and to send control commands to those devices.
func (*DeviceService) List ¶
func (svc *DeviceService) List(ctx context.Context) ([]Device, []InfraredDevice, error)
List get a list of devices, which include physical devices and virtual infrared remote devices that have been added to the current user's account. The first returned value is a list of physical devices refer to the SwitchBot products. The second returned value is a list of virtual infrared remote devices such like air conditioner, TV, light, or so on. See also https://github.com/OpenWonderLabs/SwitchBotAPI/blob/7a68353d84d07d439a11cb5503b634f24302f733/README.md#get-device-list
func (*DeviceService) Status ¶
func (svc *DeviceService) Status(ctx context.Context, id string) (DeviceStatus, error)
Status get the status of a physical device that has been added to the current user's account. Physical devices refer to the SwitchBot products. The first given argument `id` is a device ID which can be retrieved by (*Client).Device().List() function. See also https://github.com/OpenWonderLabs/SwitchBotAPI/blob/7a68353d84d07d439a11cb5503b634f24302f733/README.md#get-device-status
type DeviceStatus ¶
type DeviceStatus struct { ID string `json:"deviceId"` Type PhysicalDeviceType `json:"deviceType"` Hub string `json:"hubDeviceId"` Power PowerState `json:"power"` Humidity int `json:"humidity"` Temperature float64 `json:"temperature"` NebulizationEfficiency int `json:"nebulizationEfficiency"` IsAuto bool `json:"auto"` IsChildLock bool `json:"childLock"` IsSound bool `json:"sound"` IsCalibrated bool `json:"calibrate"` IsGrouped bool `json:"group"` IsMoving bool `json:"moving"` SlidePosition int `json:"slidePosition"` FanMode int `json:"mode"` FanSpeed int `json:"speed"` IsShaking bool `json:"shaking"` ShakeCenter int `json:"shakeCenter"` ShakeRange int `json:"shakeRange"` }
type HumidifierMode ¶
type HumidifierMode int
const ( AutoMode HumidifierMode = -1 LowMode HumidifierMode = 101 MidMode HumidifierMode = 102 HighMode HumidifierMode = 103 )
type InfraredDevice ¶
type InfraredDevice struct { ID string `json:"deviceId"` Name string `json:"deviceName"` Type VirtualDeviceType `json:"remoteType"` Hub string `json:"hubDeviceId"` }
InfraredDevice represents a virtual infrared remote device.
type Option ¶
type Option func(*Client)
func WithEndpoint ¶
WithEndpoint allows you to set an endpoint of SwitchBot API.
func WithHTTPClient ¶
WithHTTPClient allows you to pass your http client for a SwitchBot API client.
type PhysicalDeviceType ¶
type PhysicalDeviceType string
const ( // Hub is generally referred to these devices, SwitchBot Hub Model No. SwitchBot Hub S1/SwitchBot Hub Mini Model No. W0202200/SwitchBot Hub Plus Model No. SwitchBot Hub S1 Hub PhysicalDeviceType = "Hub" // HubPlus is SwitchBot Hub Plus Model No. SwitchBot Hub S1 HubPlus PhysicalDeviceType = "Hub Plus" // HubMini is SwitchBot Hub Mini Model No. W0202200 HubMini PhysicalDeviceType = "Hub Mini" // Bot is SwitchBot Bot Model No. SwitchBot S1 Bot PhysicalDeviceType = "Bot" // Curtain is SwitchBot Curtain Model No. W0701600 Curtain PhysicalDeviceType = "Curtain" // Plug is SwitchBot Plug Model No. SP11 Plug PhysicalDeviceType = "Plug" // Meter is SwitchBot Thermometer and Hygrometer Model No. SwitchBot MeterTH S1 Meter PhysicalDeviceType = "Meter" // Humidifier is SwitchBot Humidifier Model No. W0801801 Humidifier PhysicalDeviceType = "Humidifier" // SmartFan is SwitchBot Smart Fan Model No. W0601100 SmartFan PhysicalDeviceType = "Smart Fan" )
type PowerState ¶
type PowerState string
const ( PowerOn PowerState = "ON" PowerOff PowerState = "OFF" )
func (PowerState) ToLower ¶
func (power PowerState) ToLower() string
type SceneService ¶
type SceneService struct {
// contains filtered or unexported fields
}
SceneService handles API calls related to scenes. The scene API is used to access the smart scenes created by a user and to execute manual scenes.
type SetPositionMode ¶
type SetPositionMode int
SetPositionMode represents a mode for curtain devices' set position mode.
const ( DefaultMode SetPositionMode = iota PerformanceMode SilentMode )
type VirtualDeviceType ¶
type VirtualDeviceType string
const ( AirConditioner VirtualDeviceType = "Air Conditioner" TV VirtualDeviceType = "TV" Light VirtualDeviceType = "Light" IPTVStreamer VirtualDeviceType = "IPTV/Streamer" SetTopBox VirtualDeviceType = "Set Top Box" DVD VirtualDeviceType = "DVD" Fan VirtualDeviceType = "Fan" Projector VirtualDeviceType = "Projector" Camera VirtualDeviceType = "Camera" AirPurifier VirtualDeviceType = "Air Purifier" Speaker VirtualDeviceType = "Speaker" WaterHeater VirtualDeviceType = "Water Heater" VacuumCleaner VirtualDeviceType = "Vacuum Cleaner" Others VirtualDeviceType = "Others" )