switchbot

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 15 Imported by: 6

README

go-switchbot

Go Reference test

A SwitchBot API client for Golang

SYNOPSIS

const (
	openToken = "blahblahblah"
	secretKey = "blahblahblah"
)

c := switchbot.New(openToken, secretKey)

// get physical devices and show
pdev, _, _ := c.Device().List(context.Background())

for _, d := range pdev {
	fmt.Printf("%s\t%s\n", d.Type, d.Name)
}

Get Open Token

To use SwitchBot API, you need to get Open Token for auth. Follow steps below:

  1. Download the SwitchBot app on App Store or Google Play Store
  2. Register a SwitchBot account and log in into your account
  3. Generate an Open Token within the app a) Go to Profile > Preference b) Tap App Version 10 times. Developer Options will show up c) Tap Developer Options d) Tap Get Token
  4. Roll up your sleeves and get your hands dirty with SwitchBot OpenAPI!

Documentation

Index

Constants

View Source
const DefaultEndpoint = "https://api.switch-bot.com"

Variables

This section is empty.

Functions

func ParseWebhookRequest added in v0.3.0

func ParseWebhookRequest(r *http.Request) (interface{}, error)

Types

type ACFanSpeed

type ACFanSpeed int

ACFanSpeed represents a fan speed mode for air conditioner.

const (
	ACAutoSpeed ACFanSpeed = iota + 1
	ACLow
	ACMedium
	ACHigh
)

type ACMode

type ACMode int

ACMode represents a mode for air conditioner.

const (
	ACAuto ACMode = iota + 1
	ACCool
	ACDry
	ACFan
	ACHeat
)

type AmbientBrightness added in v0.2.0

type AmbientBrightness string
const (
	AmbientBrightnessBright AmbientBrightness = "bright"
	AmbientBrightnessDim    AmbientBrightness = "dim"
)

type BrightnessState added in v0.2.0

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

func (BrightnessState) AmbientBrightness added in v0.2.0

func (brightness BrightnessState) AmbientBrightness() (AmbientBrightness, error)

func (BrightnessState) Int added in v0.2.0

func (brightness BrightnessState) Int() (int, error)

func (*BrightnessState) UnmarshalJSON added in v0.2.0

func (brightness *BrightnessState) UnmarshalJSON(b []byte) error

type CeilingEvent added in v1.0.0

type CeilingEvent struct {
	EventType    string              `json:"eventType"`
	EventVersion string              `json:"eventVersion"`
	Context      CeilingEventContext `json:"context"`
}

type CeilingEventContext added in v1.0.0

type CeilingEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// ON/OFF state
	PowerState PowerState `json:"powerState"`
	// the brightness value, range from 1 to 100
	Brightness int `json:"brightness"`
	// the color temperature value, range from 2700 to 6500
	ColorTemperature int `json:"colorTemperature"`
}

type CleanerOnlineStatus added in v1.0.0

type CleanerOnlineStatus string
const (
	CleanerOnline  CleanerOnlineStatus = "online"
	CleanerOffline CleanerOnlineStatus = "offline"
)

type CleanerWorkingStatus added in v1.0.0

type CleanerWorkingStatus string
const (
	CleanerStandBy          CleanerWorkingStatus = "StandBy"
	CleanerClearing         CleanerWorkingStatus = "Clearing"
	CleanerPaused           CleanerWorkingStatus = "Paused"
	CleanerGotoChargeBase   CleanerWorkingStatus = "GotoChargeBase"
	CleanerCharging         CleanerWorkingStatus = "Charging"
	CleanerChargeDone       CleanerWorkingStatus = "ChargeDone"
	CleanerDormant          CleanerWorkingStatus = "Dormant"
	CleanerInTrouble        CleanerWorkingStatus = "InTrouble"
	CleanerInRemoteControl  CleanerWorkingStatus = "InRemoteControl"
	CleanerInDustCollecting CleanerWorkingStatus = "InDustCollecting"
)

type Client

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

func New

func New(openToken, secretKey string, opts ...Option) *Client

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.

func (*Client) Webhook added in v0.3.0

func (c *Client) Webhook() *WebhookService

type ColorBulbEvent added in v0.3.0

type ColorBulbEvent struct {
	EventType    string                `json:"eventType"`
	EventVersion string                `json:"eventVersion"`
	Context      ColorBulbEventContext `json:"context"`
}

type ColorBulbEventContext added in v0.3.0

type ColorBulbEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the current power state of the device, "ON" or "OFF"
	PowerState PowerState `json:"powerState"`
	// the brightness value, range from 1 to 100
	Brightness int `json:"brightness"`
	// the color value, in the format of RGB value, "255:255:255"
	Color string `json:"color"`
	// the color temperature value, range from 2700 to 6500
	ColorTemperature int `json:"colorTemperature"`
}

type Command

type Command interface {
	Request() DeviceCommandRequest
}

Command is an interface which represents Commands for devices to be used (*Client).Device().Command() method.

func ACSetAllCommand added in v1.0.0

func ACSetAllCommand(temperature int, mode ACMode, fanSpeed ACFanSpeed, power PowerState) Command

ACSetAllCommand returns a new Command which sets all state of air conditioner.

func ButtonPushCommand added in v1.0.0

func ButtonPushCommand(name string) Command

ButtonPushCommand returns a new Command which triggers button push.

func ChannelAddCommand added in v1.0.0

func ChannelAddCommand() Command

ChannelAddCommand returns a new Command which is for switching to next channel.

func ChannelSubCommand added in v1.0.0

func ChannelSubCommand() Command

ChannelSubCommand returns a new Command which is for switching to previous channel.

func CreateKeyCommand added in v1.0.0

func CreateKeyCommand(name string, typ PasscodeType, password string, start, end time.Time) (Command, error)

CreateKeyCommand returns a new Command which creates a new key for Lock devices. Due to security concerns, the created passcodes will be stored locally so you need to get the result through webhook. A name is a unique name for the passcode, duplicates under the same device are not allowed. A password must be a 6 to 12 digit passcode. Start time and end time are required for one-time passcode (DisposablePasscode) or temporary passcode (TimeLimitPasscode).

func DeleteKeyCommand added in v1.0.0

func DeleteKeyCommand(id int) Command

DeleteKeyCommand returns a new Command which deletes a key from Lock devices.

func DockCommand added in v1.0.0

func DockCommand() Command

DockCommand returns a new Command which returns robot vacuum cleaner to charging dock.

func FanHighSpeedCommand added in v1.0.0

func FanHighSpeedCommand() Command

FanHighSpeedCommand returns a new Command which sets fan speed to high.

func FanLowSpeedCommand added in v1.0.0

func FanLowSpeedCommand() Command

FanLowSpeedCommand returns a new Command which sets fan speed to low.

func FanMiddleSpeedCommand added in v1.0.0

func FanMiddleSpeedCommand() Command

FanMiddleSpeedCommand returns a new Command which sets fan speed to medium.

func FanSwingCommand added in v1.0.0

func FanSwingCommand() Command

FanSwingCommand returns a new Command which makes a fan swing.

func FanTimerCommand added in v1.0.0

func FanTimerCommand() Command

FanTimerCommand returns a new Command which sets timer for a fan.

func FastForwardCommand added in v1.0.0

func FastForwardCommand() Command

FastForwardCommand returns a new Command to make DVD player or speaker fastforward.

func LightBrightnessDownCommand added in v1.0.0

func LightBrightnessDownCommand() Command

LightBrightnessDownCommand returns a new Command which make light's brigtness down.

func LightBrightnessUpCommand added in v1.0.0

func LightBrightnessUpCommand() Command

LightBrightnessUpCommand returns a new Command which make light's brigtness up.

func LockCommand added in v1.0.0

func LockCommand() Command

LockCommand returns a new Command which rotates the Lock device to locked position.

func NextCommand added in v1.0.0

func NextCommand() Command

NextCommand returns a new Command to switch DVD player or speaker to next track.

func PauseCommand added in v1.0.0

func PauseCommand() Command

PauseCommand returns a new Command to make DVD player or speaker pause.

func PlayCommand added in v1.0.0

func PlayCommand() Command

PlayCommand returns a new Command to make DVD player or speaker play.

func PowLevelCommand added in v1.0.0

func PowLevelCommand(level VacuumPowerLevel) Command

PowLevelCommand returns a new Command which sets suction power level of robot vacuum cleaner.

func PressCommand added in v1.0.0

func PressCommand() Command

PressCommand returns a new command which trigger Bot's press command.

func PreviousCommand added in v1.0.0

func PreviousCommand() Command

PreviousCommand returns a new Command to switch DVD player or speaker to previous track.

func RewindCommand added in v1.0.0

func RewindCommand() Command

RewindCommand returns a new Command to make DVD player or speaker rewind.

func SetAllStatusCommand added in v1.0.0

func SetAllStatusCommand(power PowerState, fanMode SmartFanMode, fanSpeed, shakeRange int) Command

SetAllStatusCommand returns a new Commend which sets all status for smart fan.

func SetBrightnessCommand added in v1.0.0

func SetBrightnessCommand(brightness int) Command

SetBrightnessCommand returns a new Command which set brightness of color bulb, strip light, or ceiling ligths.

func SetChannelCommand added in v1.0.0

func SetChannelCommand(channelNumber int) Command

SetChannelCommand returns a new Command which set the TV channel to given channel.

func SetColorCommand added in v1.0.0

func SetColorCommand(r, g, b int) Command

SetColorCommand returns a new Command which set RGB color value of color bulb or strip light.

func SetColorTemperatureCommand added in v1.0.0

func SetColorTemperatureCommand(temperature int) Command

SetColorTemperatureCommand returns a new Command which set color temperature of color bulb or ceiling lights.

func SetModeCommand added in v1.0.0

func SetModeCommand(mode HumidifierMode) Command

SetModeCommand returns a new Command which 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 SetMuteCommand added in v1.0.0

func SetMuteCommand() Command

SetMuteCommand returns a new Command to make DVD player or speaker mute/unmute.

func SetPosition

func SetPosition(index int, mode SetPositionMode, position int) Command

SetPositionCommand 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.

func StartCommand added in v1.0.0

func StartCommand() Command

StartCommand returns a new Command which starts vacuuming.

func StopCommand added in v1.0.0

func StopCommand() Command

StopCommand returns a new Command which stops vacuuming.

func StopPlayerCommand added in v1.0.0

func StopPlayerCommand() Command

PlayerStopCommand returns a new Command to make DVD player or speaker stop.

func ToggleCommand added in v1.0.0

func ToggleCommand() Command

ToggleCommand returns a new Command which toggles state of color bulb, strip light or plug mini.

func TurnOffCommand added in v1.0.0

func TurnOffCommand() Command

TurnOffCommand returns a nw Command which turns off Bot, plug, Curtain, Humidifier, or so on. For curtain devices, turn off is equivalent to set position to 100.

func TurnOnCommand added in v1.0.0

func TurnOnCommand() Command

TurnOnCommand returns a new Command which turns on Bot, Plug, Curtain, Humidifier, or so on. For curtain devices, turn on is equivalent to set position to 0.

func UnlockCommand added in v1.0.0

func UnlockCommand() Command

LockCommand returns a new Command which rotates the Lock device to unlocked position.

func VolumeAddCommand added in v1.0.0

func VolumeAddCommand() Command

VolumeAddCommand returns a new Command which is for volume up.

func VolumeSubCommand added in v1.0.0

func VolumeSubCommand() Command

VolumeSubCommand returns a new Command which is for volume up.

type ContactSensorEvent added in v0.3.0

type ContactSensorEvent struct {
	EventType    string                    `json:"eventType"`
	EventVersion string                    `json:"eventVersion"`
	Context      ContactSensorEventContext `json:"context"`
}

type ContactSensorEventContext added in v0.3.0

type ContactSensorEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the motion state of the device, "DETECTED" stands for motion is detected;
	// "NOT_DETECTED" stands for motion has not been detected for some time
	DetectionState string `json:"detectionState"`
	// when the enter or exit mode gets triggered, "IN_DOOR" or "OUT_DOOR" is returned
	DoorMode string `json:"doorMode"`
	// the level of brightness, can be "bright" or "dim"
	Brightness AmbientBrightness `json:"brightness"`
	// the state of the contact sensor, can be "open" or "close" or "timeOutNotClose"
	OpenState string `json:"openState"`
}

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"`
	GroupName            bool               `json:"groupName"` // is this Boolean, right?
	LockDeviceIDs        []string           `json:"lockDeviceIds"`
	LockDeviceID         string             `json:"lockDeviceId"`
	KeyList              []KeyListItem      `json:"keyList"`
}

Device represents a physical SwitchBot device.

type DeviceCommandRequest added in v0.2.0

type DeviceCommandRequest struct {
	Command     string `json:"command"`
	Parameter   string `json:"parameter,omitempty"`
	CommandType string `json:"commandType,omitempty"`
}

func (DeviceCommandRequest) Request added in v0.2.0

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) Command

func (svc *DeviceService) Command(ctx context.Context, id string, cmd Command) error

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"`
	IsMoveDetected         bool                 `json:"moveDetected"`
	Brightness             BrightnessState      `json:"brightness"`
	OpenState              OpenState            `json:"openState"`
	Color                  string               `json:"color"`
	ColorTemperature       int                  `json:"colorTemperature"`
	IsLackWater            bool                 `json:"lackWater"`
	Voltage                int                  `json:"voltage"`
	Weight                 int                  `json:"weight"`
	ElectricityOfDay       int                  `json:"electricityOfDay"`
	ElectricCurrent        float64              `json:"electricCurrent"`
	LockState              string               `json:"lockState"`
	DoorState              string               `json:"doorState"`
	WorkingStatus          CleanerWorkingStatus `json:"workingStatus"`
	OnlineStatus           CleanerOnlineStatus  `json:"onlineStatus"`
	Battery                int                  `json:"battery"`
}

type HumidifierMode

type HumidifierMode int
const (
	AutoMode HumidifierMode = -1
	LowMode  HumidifierMode = 101
	MidMode  HumidifierMode = 102
	HighMode HumidifierMode = 103
)

type IndoorCamEvent added in v0.3.0

type IndoorCamEvent struct {
	EventType    string                `json:"eventType"`
	EventVersion string                `json:"eventVersion"`
	Context      IndoorCamEventContext `json:"context"`
}

type IndoorCamEventContext added in v0.3.0

type IndoorCamEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the detection state of the device, "DETECTED" stands for motion is detected
	DetectionState string `json:"detectionState"`
}

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 KeyListItem added in v1.0.0

type KeyListItem struct {
	ID         int            `json:"id"`
	Name       string         `json:"name"`
	Type       PasscodeType   `json:"type"`
	Password   string         `json:"password"`
	IV         string         `json:"iv"`
	Status     PasscodeStatus `json:"status"`
	CreateTime int64          `json:"createTime"`
}

KeyListItem is an item for keyList, which maintains a list of passcodes.

type KeypadEvent added in v1.0.0

type KeypadEvent struct {
	EventType    string             `json:"eventType"`
	EventVersion string             `json:"eventVersion"`
	Context      KeypadEventContext `json:"context"`
}

type KeypadEventContext added in v1.0.0

type KeypadEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the name fo the command being sent
	EventName string `json:"eventName"`
	// the command ID
	CommandID string `json:"commandId"`
	// the result of the command, success, failed, or timeout
	Result string `json:"result"`
}

type LockEvent added in v0.3.0

type LockEvent struct {
	EventType    string           `json:"eventType"`
	EventVersion string           `json:"eventVersion"`
	Context      LockEventContext `json:"context"`
}

type LockEventContext added in v0.3.0

type LockEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the state of the device, "LOCKED" stands for the motor is rotated to locking position;
	// "UNLOCKED" stands for the motor is rotated to unlocking position; "JAMMED" stands for
	// the motor is jammed while rotating
	LockState string `json:"lockState"`
}

type MeterEvent added in v0.3.0

type MeterEvent struct {
	EventType    string            `json:"eventType"`
	EventVersion string            `json:"eventVersion"`
	Context      MeterEventContext `json:"context"`
}

type MeterEventContext added in v0.3.0

type MeterEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	Temperature float64 `json:"temperature"`
	Scale       string  `json:"scale"`
	Humidity    int     `json:"humidity"`
}

type MeterPlusEvent added in v0.3.0

type MeterPlusEvent struct {
	EventType    string                `json:"eventType"`
	EventVersion string                `json:"eventVersion"`
	Context      MeterPlusEventContext `json:"context"`
}

type MeterPlusEventContext added in v0.3.0

type MeterPlusEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	Temperature float64 `json:"temperature"`
	Scale       string  `json:"scale"`
	Humidity    int     `json:"humidity"`
}

type MotionSensorEvent added in v0.3.0

type MotionSensorEvent struct {
	EventType    string                   `json:"eventType"`
	EventVersion string                   `json:"eventVersion"`
	Context      MotionSensorEventContext `json:"context"`
}

type MotionSensorEventContext added in v0.3.0

type MotionSensorEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the motion state of the device, "DETECTED" stands for motion is detected;
	// "NOT_DETECTED" stands for motion has not been detected for some time
	DetectionState string `json:"detectionState"`
}

type OpenState added in v0.2.0

type OpenState string
const (
	ContactOpen            OpenState = "open"
	ContactClose           OpenState = "close"
	ContactTimeoutNotClose OpenState = "timeOutNotClose"
)

type Option

type Option func(*Client)

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint allows you to set an endpoint of SwitchBot API.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient allows you to pass your http client for a SwitchBot API client.

type PanTiltCamEvent added in v0.3.0

type PanTiltCamEvent struct {
	EventType    string                 `json:"eventType"`
	EventVersion string                 `json:"eventVersion"`
	Context      PanTiltCamEventContext `json:"context"`
}

type PanTiltCamEventContext added in v0.3.0

type PanTiltCamEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the detection state of the device, "DETECTED" stands for motion is detected
	DetectionState string `json:"detectionState"`
}

type PasscodeStatus added in v1.0.0

type PasscodeStatus string
const (
	PasscodeStatusValid   PasscodeStatus = "normal"
	PasscodeStautsInvalid PasscodeStatus = "expired"
)

type PasscodeType added in v1.0.0

type PasscodeType string
const (
	PermanentPasscode  PasscodeType = "permanent"
	TimeLimitPasscode  PasscodeType = "timeLimit"
	DisposablePasscode PasscodeType = "disposable"
	UrgentPasscode     PasscodeType = "urgent"
)

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"
	// MeterPlusJP is SwitchBot Thermometer and Hygrometer Plus (JP) Model No. W2201500
	MeterPlusJP PhysicalDeviceType = "Meter Plus (JP)"
	// MeterPlusUS is SwitchBot Thermometer and Hygrometer Plus (US) Model No. W2301500
	MeterPlusUS PhysicalDeviceType = "Meter Plus (US)"
	// Humidifier is SwitchBot Humidifier Model No. W0801801
	Humidifier PhysicalDeviceType = "Humidifier"
	// SmartFan is SwitchBot Smart Fan Model No. W0601100
	SmartFan PhysicalDeviceType = "Smart Fan"
	// StripLight is SwitchBot LED Strip Light Model No. W1701100
	StripLight PhysicalDeviceType = "Strip Light"
	// PlugMiniUS is SwitchBot Plug Mini (US) Model No. W1901400
	PlugMiniUS PhysicalDeviceType = "Plug Mini (US)"
	// PlugMiniJP is SwitchBot Plug Mini (JP) Model No. W2001400
	PlugMiniJP PhysicalDeviceType = "Plug Mini (JP)"
	// Lock is SwitchBot Lock Model No. W1601700
	Lock PhysicalDeviceType = "Lock"
	// RobotVacuumCleanerS1 is SwitchBot Robot Vacuum Cleaner S1 Model No. W3011000; currently only available in Japan
	RobotVacuumCleanerS1 PhysicalDeviceType = "Robot Vacuum Cleaner S1"
	// RobotVacuumCleanerS1Plus is SwitchBot Robot Vacuum Cleaner S1 Plus Model No. W3011010; currently only available in Japan
	RobotVacuumCleanerS1Plus PhysicalDeviceType = "Robot Vacuum Cleaner S1 Plus"
	// MotionSensor is SwitchBot Motion Sensor Model No. W1101500
	MotionSensor PhysicalDeviceType = "Motion Sensor"
	// ContactSensor is SwitchBot Contact Sensor Model No. W1201500
	ContactSensor PhysicalDeviceType = "Contact Sensor"
	// ColorBulb is SwitchBot Color Bulb Model No. W1401400
	ColorBulb PhysicalDeviceType = "Color Bulb"
	// MeterPlusJP is SwitchBot Thermometer and Hygrometer Plus (JP) Model No. W2201500 / (US) Model No. W2301500
	MeterPlus PhysicalDeviceType = "MeterPlus"
	// KeyPad is SwitchBot Lock Model No. W2500010
	KeyPad PhysicalDeviceType = "KeyPad"
	// KeyPadTouch is SwitchBot Lock Model No. W2500020
	KeyPadTouch PhysicalDeviceType = "KeyPad Touch"
	// CeilingLight is SwitchBot Ceiling Light Model No. W2612230 and W2612240.
	CeilingLight PhysicalDeviceType = "Ceiling Light"
	// CeilingLightPro is SwitchBot Ceiling Light Pro Model No. W2612210 and W2612220.
	CeilingLightPro PhysicalDeviceType = "Ceiling Light Pro"
	// IndoorCam is SwitchBot Indoor Cam Model No. W1301200
	IndoorCam PhysicalDeviceType = "Indoor Cam"
	// PanTiltCam is SwitchBot Pan/Tilt Cam Model No. W1801200
	PanTiltCam PhysicalDeviceType = "Pan/Tilt Cam"
	//PanTiltCam2K is SwitchBot Pan/Tilt Cam 2K Model No. W3101100
	PanTiltCam2K PhysicalDeviceType = "Pan/Tilt Cam 2K"
)

type PlugMiniJPEvent added in v0.3.0

type PlugMiniJPEvent struct {
	EventType    string                 `json:"eventType"`
	EventVersion string                 `json:"eventVersion"`
	Context      PlugMiniJPEventContext `json:"context"`
}

type PlugMiniJPEventContext added in v0.3.0

type PlugMiniJPEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the current power state of the device, "ON" or "OFF"
	PowerState PowerState `json:"powerState"`
}

type PlugMiniUSEvent added in v0.3.0

type PlugMiniUSEvent struct {
	EventType    string                 `json:"eventType"`
	EventVersion string                 `json:"eventVersion"`
	Context      PlugMiniUSEventContext `json:"context"`
}

type PlugMiniUSEventContext added in v0.3.0

type PlugMiniUSEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the current power state of the device, "ON" or "OFF"
	PowerState PowerState `json:"powerState"`
}

type PowerState

type PowerState string
const (
	PowerOn  PowerState = "ON"
	PowerOff PowerState = "OFF"
)

func (PowerState) ToLower

func (power PowerState) ToLower() string

type Scene

type Scene struct {
	ID   string `json:"sceneId"`
	Name string `json:"sceneName"`
}

Scene represents a manual scene created by the current user.

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.

func (*SceneService) Execute

func (svc *SceneService) Execute(ctx context.Context, id string) error

Execute sends a request to execute a manual scene. The first given argument `id` is a scene ID which you want to execute, which can be retrieved by (*Client).Scene().List() function.

func (*SceneService) List

func (svc *SceneService) List(ctx context.Context) ([]Scene, error)

List get a list of manual scenes created by the current user. The first returned value is a list of scenes.

type SetPositionMode

type SetPositionMode int

SetPositionMode represents a mode for curtain devices' set position mode.

const (
	DefaultMode SetPositionMode = iota
	PerformanceMode
	SilentMode
)

type SmartFanMode added in v0.3.0

type SmartFanMode int
const (
	StandardFanMode SmartFanMode = 1
	NaturalFanMode  SmartFanMode = 2
)

type StripLightEvent added in v0.3.0

type StripLightEvent struct {
	EventType    string                 `json:"eventType"`
	EventVersion string                 `json:"eventVersion"`
	Context      StripLightEventContext `json:"context"`
}

type StripLightEventContext added in v0.3.0

type StripLightEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the current power state of the device, "ON" or "OFF"
	PowerState PowerState `json:"powerState"`
	// the brightness value, range from 1 to 100
	Brightness int `json:"brightness"`
	// the color value, in the format of RGB value, "255:255:255"
	Color string `json:"color"`
}

type SweeperEvent added in v1.0.0

type SweeperEvent struct {
	EventType    string              `json:"eventType"`
	EventVersion string              `json:"eventVersion"`
	Context      SweeperEventContext `json:"context"`
}

type SweeperEventContext added in v1.0.0

type SweeperEventContext struct {
	DeviceType   string `json:"deviceType"`
	DeviceMac    string `json:"deviceMac"`
	TimeOfSample int64  `json:"timeOfSample"`

	// the working status of the device, "StandBy", "Clearing",
	// "Paused", "GotoChargeBase", "Charging", "ChargeDone",
	// "Dormant", "InTrouble", "InRemoteControl", or "InDustCollecting"
	WorkingStatus CleanerWorkingStatus `json:"workingStatus"`
	// the connection status of the device, "online" or "offline"
	OnlineStatus CleanerOnlineStatus `json:"onlineStatus"`
	// the battery level.
	Battery int `json:"battery"`
}

type VacuumPowerLevel added in v0.3.0

type VacuumPowerLevel int
const (
	QuietVacuumPowerLevel    VacuumPowerLevel = 0
	StandardVacuumPowerLevel VacuumPowerLevel = 1
	StrongVacuumPowerLevel   VacuumPowerLevel = 2
	MaxVacuumPowerLevel      VacuumPowerLevel = 3
)

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"
)

type WebhookQueryActionType added in v0.3.0

type WebhookQueryActionType string
const (
	QueryURL     WebhookQueryActionType = "queryUrl"
	QueryDetails WebhookQueryActionType = "queryDetails"
)

type WebhookService added in v0.3.0

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

func (*WebhookService) Delete added in v0.3.0

func (svc *WebhookService) Delete(ctx context.Context, url string) error

Delete do delete the configuration of the webhook.

func (*WebhookService) Query added in v0.3.0

func (svc *WebhookService) Query(ctx context.Context, action WebhookQueryActionType, url string) error

Query retrieves the current configuration info of the webhook. The second argument `url` is required for QueryDetails action type.

func (*WebhookService) Setup added in v0.3.0

func (svc *WebhookService) Setup(ctx context.Context, url, deviceList string) error

Setup configures the url that all the webhook events will be sent to. Currently the deviceList is only supporting "ALL".

func (*WebhookService) Update added in v0.3.0

func (svc *WebhookService) Update(ctx context.Context, url string, enable bool) error

Update do update the configuration of the webhook.

Jump to

Keyboard shortcuts

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