Documentation ¶
Index ¶
- Constants
- func DimToPercentage(dim uint8) uint8
- func HexRGBToColorXYDim(rgb string) (x int, y int, dim uint8, err error)
- func KelvinToColorXYDim(k int) (x int, y int, dim uint8)
- func KelvinToMired(k int) int
- func KelvinToRGB(k int) (r, g, b float64)
- func MiredToKelvin(mired int) int
- func MsToDuration(ms int) int
- func PercentageToDim(p uint8) uint8
- func RGBToColorXYDim(r, g, b float64) (x int, y int, dim uint8)
- type AddGroupRequest
- type AddMoodRequest
- type Client
- func (c *Client) AddGroup(ids []uint32, name string) error
- func (c *Client) AddMood(name string) error
- func (c *Client) Connect(ident string) error
- func (c *Client) DeviceEvents() <-chan *Device
- func (c *Client) FactoryReset() error
- func (c *Client) GatewayEvents() <-chan *Gateway
- func (c *Client) GetDevice(id uint32) (*Device, error)
- func (c *Client) GetGateway() (*Gateway, error)
- func (c *Client) GetGroup(id uint32) (*Group, error)
- func (c *Client) GetMood(id uint32, parent *uint32) (*Mood, error)
- func (c *Client) ListDeviceIds() (deviceIds []uint32, err error)
- func (c *Client) ListDevices() (devices []*Device, err error)
- func (c *Client) ListGroups() ([]*Group, error)
- func (c *Client) ListMoods() ([]*Mood, error)
- func (c *Client) ObserveDevice(deviceId uint32) error
- func (c *Client) ObserveGateway() error
- func (c *Client) Reboot() error
- func (c *Client) RemoveDevice(id uint32) error
- func (c *Client) RemoveGroup(id uint32) error
- func (c *Client) RemoveMood(id uint32) error
- func (c *Client) SetCommissioningMode(seconds uint32) error
- func (c *Client) SetDevice(id uint32, change LightControl) error
- func (c *Client) SetGroup(g Group) error
- func (c *Client) SetNTP(NTPServer string) error
- type Device
- type DeviceSet
- type DeviceType
- type Gateway
- type Group
- type LightControl
- type Mood
- type PSKRequest
- type PSKResponse
- type PowerSource
Constants ¶
const ( ColorTempCold = "f5faf6" ColorTempColdX = 24841 ColorTempColdY = 24593 )
const ( ColorTempDay = "f1e0b5" ColorTempDayX = 29969 ColorTempDayY = 26804 )
const ( ColorTempWarm = "efd275" ColorTempWarmX = 32977 ColorTempWarmY = 27105 )
const ( DimMax = 254 DimMin = 0 MiredMin = 250 // 4000K MiredMax = 454 // 2200K )
Variables ¶
This section is empty.
Functions ¶
func DimToPercentage ¶
func HexRGBToColorXYDim ¶
Convert sRGB D65 -> xy colour space
func KelvinToMired ¶
func KelvinToRGB ¶
func MiredToKelvin ¶
func MsToDuration ¶
func PercentageToDim ¶
Types ¶
type AddGroupRequest ¶
type AddMoodRequest ¶
type AddMoodRequest struct { // The name of the new mood. Name string `json:"9001"` // IsActive uint8 `json:"9058"` }
The data sent to the gateway in a request to add a new mood.
type Client ¶
type Client struct { // Hostname or IP address of the gateway for this client Gateway string // Gateway code at the bottom of your gateway; used for authentication Key string // contains filtered or unexported fields }
Client represent the connection to a Trådfri gateway. Any and all communication goes through this struct's methods.
func NewClient ¶
Creates a new Client, connecting to the given gateway using the given authentication.
func (*Client) AddGroup ¶
Adds a new group to the gateway, consisting of the given devices using the given name.
func (*Client) DeviceEvents ¶
Returns a channel over which any updates to any devices will be sent, see ObserveDevice.
func (*Client) FactoryReset ¶
Resets the gateway to factory defaults.
func (*Client) GatewayEvents ¶
Returns a channel over which any updates to any devices will be sent, see ObserveDevice.
func (*Client) GetGateway ¶
Gets the gateway information, see Gateway.
func (*Client) ListDeviceIds ¶
Lists the identifiers of all devices connected to the gateway.
func (*Client) ListDevices ¶
Lists the device settings of all the devices connected to the gateway.
func (*Client) ListGroups ¶
Lists the group settings of all devices connected to the gateway.
func (*Client) ObserveDevice ¶
Observe the given device, i.e., any changes through other channels (such as a remote) will be sent over the channel returned by DeviceEvents, which must be called first.
func (*Client) ObserveGateway ¶
Observe the gateway for changes. These changes will be sent over the channel returned by GatewayEvents, which must be called first.
func (*Client) RemoveDevice ¶
Removes the given device from the gateway.
func (*Client) RemoveGroup ¶
Removes the given group from the gateway.
func (*Client) RemoveMood ¶
Removes the given mood from the gateway.
func (*Client) SetCommissioningMode ¶
Sets the gateway into commissioning mode for the given duration in seconds.
func (*Client) SetDevice ¶
func (c *Client) SetDevice(id uint32, change LightControl) error
Changes the given device's settings to that of the given LightControl.
type Device ¶
type Device struct { // Device related information according to IPSO 3. Device struct { // Read-only. Defined in IPSO 3. Manufacturer string `json:"0"` // Read-only. Defined in IPSO 3. ModelNumber string `json:"1"` // Read-only. Defined in IPSO 3. Serial string `json:"2"` // Read-only. Defined in IPSO 3. FirmwareVersion string `json:"3"` // See PowerSource. Read-only. Defined in IPSO 3. AvailablePowerSource PowerSource `json:"6"` // Battery level as a percentage. Read-only. Defined in IPSO 3. BatteryLevel uint8 `json:"9"` } `json:"3"` // A list of light source controls, according to IPSO 3311. See LightControl. LightControl []LightControl `json:"3311"` // The application type of this device, see DeviceType. Read-write. Defined in IPSO 3311, 3335, 3342. Type DeviceType `json:"5750"` // The name of this device, as given by the user. Name string `json:"9001"` // The time at which this bulb was paired with the gateway. CreatedAt int64 `json:"9002"` // Numeric identifier of this device. ID uint32 `json:"9003"` // Whether this device is reachable or not. Reachable uint8 `json:"9019"` // LastSeen int64 `json:"9020"` // OtaUpdateState int `json:"9054"` }
The Device struct holds all information related to a Trådfri device.
type DeviceSet ¶
type DeviceSet struct {
LightControl []LightControl `json:"3311"`
}
The DeviceSet struct is used in a request to change a Trådfri light bulb's settings.
type DeviceType ¶
type DeviceType uint8
The application type of the sensor or actuator. Defined in IPSO 3311, 3335, 3342.
const ( // The Trådfri wireless remote. Remote DeviceType = 0 // The Trådfri wireless dimmer. Dimmer DeviceType = 1 // Any Trådfri light bulb. Light DeviceType = 2 // The Trådfri motion sensor. Sensor DeviceType = 4 )
func (DeviceType) String ¶
func (t DeviceType) String() string
type Gateway ¶
type Gateway struct { // The identifier of this gateway ID string `json:"9081"` // The NTP server the gateway uses NTPServer string `json:"9023"` // The firmware version of the gateway FirmwareVersion string `json:"9029"` // The current time as a Unix timestamp CurrentTimestamp int64 `json:"9059"` // The current time of the gateway in the format YYYY-MM-DDTHH:MM:SS.MMM CurrentTimestampUTC string `json:"9060"` // The amount of seconds in which this gateway accepts pairing requests from // new devices. A value of 0 means this gateway is not in commissioning mode. CommissioningMode uint32 `json:"9061"` // URL pointing to the release notes of the latest (?) update. ReleaseNotesURL string `json:"9056"` // The name of the gateway. Name string `json:"9035"` // All of the following fields have been reverse-engineered through the Android APK file. // Their naming and type matches the Java source code, but their function is unknown. It is // also likely that we may be able to use more precise types (e.g. uint8) for many of these. TimeSource int `json:"9071"` OtaUpdateState int `json:"9054"` UpdateProgress int `json:"9055"` UpdatePriority int `json:"9066"` UpdateAcceptedTimestamp int `json:"9069"` ForceOtaUpdateCheck string `json:"9032"` DstTimeOffset int `json:"9080"` DstStartMonth int `json:"9072"` DstStartDay int `json:"9073"` DstStartHour int `json:"9074"` DstStartMinute int `json:"9075"` DstEndMonth int `json:"9076"` DstEndDay int `json:"9077"` DstEndHour int `json:"9078"` DstEndMinute int `json:"9079"` GoogleHomePairStatus int `json:"9105"` AlexaPairStatus int `json:"9093"` CertificateProvisioned int `json:"9092"` }
The Gateway struct holds all information related to the Trådfri gateway.
type Group ¶
type Group struct { // Whether the light bulbs in this group are on or off. Read-write. Defined in IPSO 3311. Power uint8 `json:"5850"` // Dimmer value, i.e. how bright the bulbs in this group are. Valid values are in the range [0,254]. // Read-write. This code is defined in IPSO 3311, but note that the values in Ikea's implementation // are not a percentage. Dim uint8 `json:"5851"` // The name of this group, as given by the user. Name string `json:"9001"` // The time at which this group was created. CreatedAt int64 `json:"9002"` // Numeric identifier of this group. ID uint32 `json:"9003"` // AccessoryLink struct { // LinkedItems struct { // Numeric identifier of the light bulbs in this group. DeviceIDs []uint32 `json:"9003"` } `json:"15002"` } `json:"9018,omitempty"` // The identifier of the currently active mood, if any. MoodID uint32 `json:"9039"` }
The Group struct holds all information relating to a group on the Trådfri gateway.
type LightControl ¶
type LightControl struct { // The hex color string of this light bulb. Read-write. Defined in IPSO 3311, 3335. Color string `json:"5706"` // The hue of this light bulb, only for RGB bulbs. ColorHue int `json:"5707"` // The saturation of this light bulb, only for RGB bulbs. ColorSat int `json:"5708"` // ColorX int `json:"5709"` // ColorY int `json:"5710"` // Whether this light bulb is on or off. Read-write. Defined in IPSO 3311. Power uint8 `json:"5850"` // Dimmer value, i.e. how bright this bulb is. Valid values are in the range [0,254]. // Read-write. This code is defined in IPSO 3311, but note that the values in Ikea's implementation // are not a percentage. Dim uint8 `json:"5851"` // Current color temperature in mired. Valid values are in the range [250,454], // which corresponds to [4000K,2200K]. Mireds int `json:"5711"` // The duration of a transition in tenths of a second, only for RGB bulbs. TransitionDuration int `json:"5712"` // The total power in Wh that the light has used. Read-only. Defined in IPSO 3311. CumulativeActivePower float64 `json:"5805"` // The time in seconds that the light has been on. Writing a value of 0 resets the counter. Read-write. // Defined in IPSO 3311, 3342. OnTime uint32 `json:"5852"` // The power factor of the light. Read-only. Defined in IPSO 3311. PowerFactor float64 `json:"5820"` // If present, the type of sensor defined as the UCUM Unit Definition. Read-only. // Defined in IPSO 3311, 3335. SensorUnit string `json:"5701"` // Numeric identifier of this bulb. ID uint32 `json:"9003"` }
The LightControl struct holds all settings to control a given Trådfri light bulb.
type Mood ¶
type Mood struct { // Numeric identifier of this mood. ID uint32 `json:"9003"` // The time at which this mood was created. CreatedAt int64 `json:"9002"` // The name of this mood, as given by the user. Name string `json:"9001"` // Whether this mood was predefined by Ikea, or created by the user. IsPredefined uint8 `json:"9068"` // Index int32 `json:"9057"` // IsActive uint8 `json:"9058"` // LightControls []LightControl `json:"15013"` // UseCurrentLightSettings uint8 `json:"9070"` }
The Mood struct holds all information related to a mood on the Trådfri gateway.
type PSKRequest ¶
type PSKRequest struct { // Identifier sent in an authentication request. Ident string `json:"9090"` }
A PSKRequest is sent to the gateway in an authentication request.
type PSKResponse ¶
type PSKResponse struct { // Preshared key as returned by the gateway following an authentication request. PSK string `json:"9091"` }
A PSKResponse is received from the gateway following an authentication request.
type PowerSource ¶
type PowerSource uint8
Available power sources. Defined in IPSO 3.
const ( DC PowerSource = 0 InternalBat PowerSource = 1 ExternalBat PowerSource = 2 Battery PowerSource = 3 PoE PowerSource = 4 USB PowerSource = 5 AC PowerSource = 6 Solar PowerSource = 7 )
func (PowerSource) String ¶
func (p PowerSource) String() string