sladdfri

package module
v0.0.0-...-ad37bb9 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2018 License: MIT Imports: 8 Imported by: 0

README

Sladdfri

Sladdfri is a library to control the Ikea Trådfri smart lighting solution.

Installation

go get github.com/Hjdskes/sladdfri

Usage

The package documentation is available at godoc.org.

Bugs

For any bug or request, please create an issue on GitHub.

License

Please see LICENSE on GitHub. This work is based on go-tradfri.

Copyright © 2018 Jente Hidskes <hjdskes@gmail.com>

Documentation

Index

Constants

View Source
const (
	ColorTempCold  = "f5faf6"
	ColorTempColdX = 24841
	ColorTempColdY = 24593
)
View Source
const (
	ColorTempDay  = "f1e0b5"
	ColorTempDayX = 29969
	ColorTempDayY = 26804
)
View Source
const (
	ColorTempWarm  = "efd275"
	ColorTempWarmX = 32977
	ColorTempWarmY = 27105
)
View Source
const (
	DimMax   = 254
	DimMin   = 0
	MiredMin = 250 // 4000K
	MiredMax = 454 // 2200K
)

Variables

This section is empty.

Functions

func DimToPercentage

func DimToPercentage(dim uint8) uint8

func HexRGBToColorXYDim

func HexRGBToColorXYDim(rgb string) (x int, y int, dim uint8, err error)

Convert sRGB D65 -> xy colour space

func KelvinToColorXYDim

func KelvinToColorXYDim(k int) (x int, y int, dim uint8)

func KelvinToMired

func KelvinToMired(k int) int

func KelvinToRGB

func KelvinToRGB(k int) (r, g, b float64)

func MiredToKelvin

func MiredToKelvin(mired int) int

func MsToDuration

func MsToDuration(ms int) int

func PercentageToDim

func PercentageToDim(p uint8) uint8

func RGBToColorXYDim

func RGBToColorXYDim(r, g, b float64) (x int, y int, dim uint8)

Types

type AddGroupRequest

type AddGroupRequest struct {
	// Numeric identifiers of the elements in the new group.
	ID []uint32 `json:"9003,omitempty"`

	// The name of the group, as given by the user.
	Name string `json:"9001"`
}

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

func NewClient(gateway, key string) *Client

Creates a new Client, connecting to the given gateway using the given authentication.

func (*Client) AddGroup

func (c *Client) AddGroup(ids []uint32, name string) error

Adds a new group to the gateway, consisting of the given devices using the given name.

func (*Client) AddMood

func (c *Client) AddMood(name string) error

Adds a mood of the given name to the gateway.

func (*Client) Connect

func (c *Client) Connect(ident string) error

Connects the client to its gateway using the given identifier.

func (*Client) DeviceEvents

func (c *Client) DeviceEvents() <-chan *Device

Returns a channel over which any updates to any devices will be sent, see ObserveDevice.

func (*Client) FactoryReset

func (c *Client) FactoryReset() error

Resets the gateway to factory defaults.

func (*Client) GatewayEvents

func (c *Client) GatewayEvents() <-chan *Gateway

Returns a channel over which any updates to any devices will be sent, see ObserveDevice.

func (*Client) GetDevice

func (c *Client) GetDevice(id uint32) (*Device, error)

Gets the given device's information, see Device.

func (*Client) GetGateway

func (c *Client) GetGateway() (*Gateway, error)

Gets the gateway information, see Gateway.

func (*Client) GetGroup

func (c *Client) GetGroup(id uint32) (*Group, error)

Gets the given group's information, see Group.

func (*Client) GetMood

func (c *Client) GetMood(id uint32, parent *uint32) (*Mood, error)

Gets the given mood's information, see Mood.

func (*Client) ListDeviceIds

func (c *Client) ListDeviceIds() (deviceIds []uint32, err error)

Lists the identifiers of all devices connected to the gateway.

func (*Client) ListDevices

func (c *Client) ListDevices() (devices []*Device, err error)

Lists the device settings of all the devices connected to the gateway.

func (*Client) ListGroups

func (c *Client) ListGroups() ([]*Group, error)

Lists the group settings of all devices connected to the gateway.

func (*Client) ListMoods

func (c *Client) ListMoods() ([]*Mood, error)

Lists the mood settings of all the moods on the gateway.

func (*Client) ObserveDevice

func (c *Client) ObserveDevice(deviceId uint32) error

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

func (c *Client) ObserveGateway() error

Observe the gateway for changes. These changes will be sent over the channel returned by GatewayEvents, which must be called first.

func (*Client) Reboot

func (c *Client) Reboot() error

Reboots the gateway.

func (*Client) RemoveDevice

func (c *Client) RemoveDevice(id uint32) error

Removes the given device from the gateway.

func (*Client) RemoveGroup

func (c *Client) RemoveGroup(id uint32) error

Removes the given group from the gateway.

func (*Client) RemoveMood

func (c *Client) RemoveMood(id uint32) error

Removes the given mood from the gateway.

func (*Client) SetCommissioningMode

func (c *Client) SetCommissioningMode(seconds uint32) error

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.

func (*Client) SetGroup

func (c *Client) SetGroup(g Group) error

Changes the group's, whose identifier matches the one from the given Group, settings to that of the given Group.

func (*Client) SetNTP

func (c *Client) SetNTP(NTPServer string) error

Sets the NTP server used by the gateway.

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.

func (*Device) String

func (d *Device) String() string

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.

func (*Gateway) String

func (g *Gateway) String() string

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.

func (*Group) String

func (g *Group) String() string

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.

func (*Mood) String

func (m *Mood) String() string

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

Jump to

Keyboard shortcuts

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