Documentation ¶
Index ¶
- Constants
- Variables
- func IsAccessTokenError(err error) bool
- func IsCredentialsError(err error) bool
- func IsPropertyNotExistsError(err error) bool
- func IsStatusPaginatedResponse(p *Packet) bool
- func Login2FA(email, password, corpID string) (func(code string) (*SessionInfo, error), error)
- func Login2FAStage1(email, corpID string) error
- type Controller
- func (c *Controller) BlastDeviceStatuses(ds []*ControllerDevice, statuses []bool, numSwitches int) error
- func (c *Controller) DeviceStatus(d *ControllerDevice) (ControllerDeviceStatus, error)
- func (c *Controller) DeviceStatuses(devs []*ControllerDevice) ([]ControllerDeviceStatus, []error)
- func (c *Controller) Devices() ([]*ControllerDevice, error)
- func (c *Controller) Login(email, password string) error
- func (c *Controller) SetDeviceCT(d *ControllerDevice, ct int) error
- func (c *Controller) SetDeviceCTAsync(d *ControllerDevice, ct int) error
- func (c *Controller) SetDeviceLum(d *ControllerDevice, lum int) error
- func (c *Controller) SetDeviceLumAsync(d *ControllerDevice, lum int) error
- func (c *Controller) SetDeviceRGB(d *ControllerDevice, r, g, b uint8) error
- func (c *Controller) SetDeviceRGBAsync(d *ControllerDevice, r, g, b uint8) error
- func (c *Controller) SetDeviceStatus(d *ControllerDevice, status bool) error
- func (c *Controller) SetDeviceStatusAsync(d *ControllerDevice, status bool) error
- type ControllerDevice
- type ControllerDeviceStatus
- type DeviceInfo
- type DeviceProperties
- type OptionalDate
- type Packet
- func NewPacketGetStatusPaginated(deviceID uint32, seq uint16) *Packet
- func NewPacketPipe(deviceID uint32, seq uint16, subtype uint8, data []byte) *Packet
- func NewPacketSetCT(deviceID uint32, seq uint16, device, ct int) *Packet
- func NewPacketSetDeviceStatus(deviceID uint32, seq uint16, device, status int) *Packet
- func NewPacketSetLum(deviceID uint32, seq uint16, device, brightness int) *Packet
- func NewPacketSetRGB(deviceID uint32, seq uint16, device int, r, g, b uint8) *Packet
- type PacketConn
- type RemoteError
- type SessionInfo
- type StatusPaginatedResponse
- type UserInfo
Constants ¶
const ( RemoteErrorCodeAccessTokenRefresh = 4031022 RemoteErrorCodePasswordError = 4001007 RemoteErrorCodeUserNotExists = 4041011 RemoteErrorCodePropertyNotExists = 4041009 )
const ( PacketTypeAuth uint8 = 1 PacketTypeSync = 4 PacketTypePipe = 7 PacketTypePipeSync = 8 )
const ( PacketPipeTypeSetStatus uint8 = 0xd0 PacketPipeTypeSetLum = 0xd2 PacketPipeTypeSetCT = 0xe2 PacketPipeTypeGetStatus = 0xdb PacketPipeTypeGetStatusPaginated = 0x52 )
const DefaultCorpID = "1007d2ad150c4000"
DefaultCorpID is the corporation ID used by the C by GE app.
const DefaultPacketConnHost = "cm.gelighting.com:23778"
const DefaultTimeout = time.Second * 10
const PacketConnTimeout = time.Second * 10
Variables ¶
var RemoteCallError = errors.New("the server returned with an error")
A RemoteCallError is triggered when the packet server returns an unspecified error.
var UnreachableError = errors.New("the device cannot be reached")
An UnreachableError is triggered when a device cannot be reached through any wifi-connected switch.
Functions ¶
func IsAccessTokenError ¶
IsAccessTokenError returns true if the error is an API error that can be solved by refreshing the access token.
func IsCredentialsError ¶
IsCredentialsError returns true if the error was the result of a bad username or password.
func IsPropertyNotExistsError ¶
IsPropertyNotExistsError returns true if an error was the result of looking up properties for a device without properties.
func Login2FA ¶
func Login2FA(email, password, corpID string) (func(code string) (*SessionInfo, error), error)
Login2FA authenticates using two-factor authentication, which is required for newer "Cync" accounts.
This method returns a callback which should be called with the emailed verification code.
func Login2FAStage1 ¶
Login2FAStage1 sends a two-factor authentication email to the user. Complete the login using Login2FAStage2.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
A Controller is a high-level API for manipulating C by GE devices.
func NewController ¶
func NewController(s *SessionInfo, timeout time.Duration) *Controller
NewController creates a Controller using a pre-created session and a specified timeout.
If timeout is 0, then DefaultTimeout is used.
func NewControllerLogin ¶
func NewControllerLogin(email, password string) (*Controller, error)
NewControllerLogin creates a Controller by logging in with a username and password.
func (*Controller) BlastDeviceStatuses ¶
func (c *Controller) BlastDeviceStatuses(ds []*ControllerDevice, statuses []bool, numSwitches int) error
BlastDeviceStatuses asynchronously turns on or off many devices in bulk. It will use up to numSwitches switches per device, providing redundancy if some switches are not connected. If numSwitches is 0, one switch will be used per device.
func (*Controller) DeviceStatus ¶
func (c *Controller) DeviceStatus(d *ControllerDevice) (ControllerDeviceStatus, error)
DeviceStatus gets the status for a previously enumerated device.
If no error occurs, the status is updated in d.LastStatus() in addition to being returned.
func (*Controller) DeviceStatuses ¶
func (c *Controller) DeviceStatuses(devs []*ControllerDevice) ([]ControllerDeviceStatus, []error)
DeviceStatuses gets the status for previously enumerated devices.
Each device will have its own status, and can have an independent error when fetching the status.
Each device's status is updated in d.LastStatus() if no error occurred for that device.
func (*Controller) Devices ¶
func (c *Controller) Devices() ([]*ControllerDevice, error)
Devices enumerates the devices available to the account.
Each device's status is available through its LastStatus() method.
func (*Controller) Login ¶
func (c *Controller) Login(email, password string) error
Login creates a new authentication token on the session using the username and password.
func (*Controller) SetDeviceCT ¶
func (c *Controller) SetDeviceCT(d *ControllerDevice, ct int) error
SetDeviceCT changes a device's color tone.
Color tone values are in [0, 100].
func (*Controller) SetDeviceCTAsync ¶
func (c *Controller) SetDeviceCTAsync(d *ControllerDevice, ct int) error
SetDeviceCTAsync is like SetDeviceCT, but does not wait for the device's status to change.
func (*Controller) SetDeviceLum ¶
func (c *Controller) SetDeviceLum(d *ControllerDevice, lum int) error
SetDeviceLum changes a device's brightness.
Brightness values are in [1, 100].
func (*Controller) SetDeviceLumAsync ¶
func (c *Controller) SetDeviceLumAsync(d *ControllerDevice, lum int) error
SetDeviceLumAsync is like SetDeviceLum, but does not wait for the device's status to change.
func (*Controller) SetDeviceRGB ¶
func (c *Controller) SetDeviceRGB(d *ControllerDevice, r, g, b uint8) error
SetDeviceRGB changes a device's RGB.
func (*Controller) SetDeviceRGBAsync ¶
func (c *Controller) SetDeviceRGBAsync(d *ControllerDevice, r, g, b uint8) error
SetDeviceRGBAsync is like SetDeviceRGB, but does not wait for the device's status to change.
func (*Controller) SetDeviceStatus ¶
func (c *Controller) SetDeviceStatus(d *ControllerDevice, status bool) error
SetDeviceStatus turns on or off a device.
func (*Controller) SetDeviceStatusAsync ¶
func (c *Controller) SetDeviceStatusAsync(d *ControllerDevice, status bool) error
SetDeviceStatusAsync is like SetDeviceStatus, but does not wait for the device's state to change.
type ControllerDevice ¶
type ControllerDevice struct {
// contains filtered or unexported fields
}
func (*ControllerDevice) DeviceID ¶
func (c *ControllerDevice) DeviceID() string
DeviceID gets a unique identifier for the device.
func (*ControllerDevice) LastStatus ¶
func (c *ControllerDevice) LastStatus() ControllerDeviceStatus
LastStatus gets the last known status of the device.
This is not updated automatically, but it will be updated on a device object when Controller.DeviceStatus() is called.
func (*ControllerDevice) Name ¶
func (c *ControllerDevice) Name() string
Name gets the user-assigned name of the device.
type ControllerDeviceStatus ¶
type ControllerDeviceStatus struct { StatusPaginatedResponse // If IsOnline is false, all other fields are invalid. // This means that the device could not be reached. IsOnline bool }
type DeviceInfo ¶
type DeviceInfo struct { AccessKey int64 `json:"access_key"` ActiveCode string `json:"active_code"` ActiveDate OptionalDate `json:"active_date"` AuthorizeCode string `json:"authorize_code"` FirmwareVersion int `json:"firmware_version"` Groups string `json:"groups"` ID uint32 `json:"id"` IsActive bool `json:"is_active"` IsOnline bool `json:"is_online"` LastLogin OptionalDate `json:"last_login"` MAC string `json:"mac"` MCUVersion int `json:"mcu_version"` Name string `json:"name"` ProductID string `json:"product_id"` Role int `json:"role"` Source int `json:"source"` SubscribeDate string `json:"subscribe_date"` }
func GetDevices ¶
func GetDevices(userID uint32, accessToken string) ([]*DeviceInfo, error)
GetDevices gets the devices using information from Login.
type DeviceProperties ¶
type DeviceProperties struct { Bulbs []struct { DeviceID int64 `json:"deviceID"` DisplayName string `json:"displayName"` SwitchID uint64 `json:"switchID"` } `json:"bulbsArray"` }
func GetDeviceProperties ¶
func GetDeviceProperties(accessToken, productID string, deviceID uint32) (*DeviceProperties, error)
GetDeviceProperties gets extended device information.
The resulting error can be checked with IsPropertyNotExistsError(), to check if the device has no properties.
type OptionalDate ¶
func (*OptionalDate) UnmarshalJSON ¶
func (o *OptionalDate) UnmarshalJSON(d []byte) error
type Packet ¶
func NewPacketGetStatusPaginated ¶
NewPacketGetStatusPaginated creates a packet for requesting the status of a device.
func NewPacketPipe ¶
NewPacketPipe creates a "pipe buffer" packet with a given subtype.
func NewPacketSetCT ¶
NewPacketSetCT creates a packet for setting a device's color tone.
Set tone is a number in [0, 100], where 100 is blue and 0 is orange.
func NewPacketSetDeviceStatus ¶
NewPacketSetDeviceStatus creates a packet for turning on or off a device.
Set status to 1 to turn on, or 0 to turn off.
func NewPacketSetLum ¶
NewPacketSetLum creates a packet for setting a device's brightness.
Set brightness to a number in [1, 100].
func NewPacketSetRGB ¶
NewPacketSetRGB creates a packet for setting a device's RGB color.
type PacketConn ¶
type PacketConn struct {
// contains filtered or unexported fields
}
func NewPacketConn ¶
func NewPacketConn() (*PacketConn, error)
NewPacketConn creates a PacketConn connected to the default server.
func NewPacketConnWrap ¶
func NewPacketConnWrap(conn net.Conn) *PacketConn
NewPacketConnWrap creates a PacketConn on top of an existing socket.
func (*PacketConn) Auth ¶
Auth does an authentication exchange with the server.
Provide an authorization code, as obtained by Login(). If timeout is non-zero, it is a socket read/write timeout; otherwise, no timeout is used.
func (*PacketConn) Close ¶
func (p *PacketConn) Close() error
func (*PacketConn) Read ¶
func (p *PacketConn) Read() (*Packet, error)
func (*PacketConn) Write ¶
func (p *PacketConn) Write(packet *Packet) error
type RemoteError ¶
A RemoteError is an error message returned by the HTTPS API server.
func (*RemoteError) Error ¶
func (l *RemoteError) Error() string
type SessionInfo ¶
type SessionInfo struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` UserID uint32 `json:"user_id"` ExpireIn int `json:"expire_in"` Authorize string `json:"authorize"` }
func Login ¶
func Login(email, password, corpID string) (*SessionInfo, error)
Login authenticates with the server to create a new session. This only works for older accounts, not newer "Cync" accounts.
The resulting error can be checked with IsCredentialsError() to see if it resulted from a bad login.
If corpID is "", then DefaultCorpID is used.
func Login2FAStage2 ¶
func Login2FAStage2(email, password, corpID, code string) (*SessionInfo, error)
Login2FAStage2 completes the two-factor authentication process, creating a session if the code and password is correct.
type StatusPaginatedResponse ¶
type StatusPaginatedResponse struct { Device int Brightness uint8 ColorTone uint8 IsOn bool UseRGB bool RGB [3]uint8 }
func DecodeStatusPaginatedResponse ¶
func DecodeStatusPaginatedResponse(p *Packet) ([]StatusPaginatedResponse, error)
type UserInfo ¶
type UserInfo struct { Gender int `json:"gender"` ActiveDate OptionalDate `json:"active_date"` Source int `json:"source"` PasswordInited bool `json:"passwd_inited"` IsValid bool `json:"is_valid"` Nickname string `json:"nickname"` ID uint32 `json:"id"` CreateDate OptionalDate `json:"create_date"` Email string `json:"email"` RegionID int `json:"region_id"` AuthorizeCode string `json:"authorize_code"` CertificateNo string `json:"certificate_no"` CertificateType int `json:"certificate_type"` CorpID string `json:"corp_id"` PrivacyCode string `json:"privacy_code"` Account string `json:"account"` Age int `json:"age"` Status int `json:"status"` }
Directories ¶
Path | Synopsis |
---|---|
Command login_2fa performs two-factor authentication for a C by GE (Cync) account, returning a session as JSON if the login succeeds.
|
Command login_2fa performs two-factor authentication for a C by GE (Cync) account, returning a session as JSON if the login succeeds. |