Documentation ¶
Overview ¶
Package belkin provides support for Belkin devices, such as the WeMo Switch
Index ¶
- Constants
- Variables
- type BinaryState
- type Device
- func (d *Device) FetchAttributes(timeout time.Duration) (*DeviceAttributes, error)
- func (d *Device) FetchBinaryState(timeout time.Duration) (int, error)
- func (d *Device) Load(timeout time.Duration) error
- func (d *Device) TurnOff(timeout time.Duration) error
- func (d *Device) TurnOn(timeout time.Duration) error
- type DeviceAttributes
- type DeviceType
- type ScanResponse
- type Service
Constants ¶
const ( // DTBridge - belkin bridge DTBridge DeviceType = "urn:Belkin:device:bridge:1" // DTSwitch - belkin switch DTSwitch = "urn:Belkin:device:controllee:1" // DTMotion - belkin motion sensor DTMotion = "urn:Belkin:device:sensor:1" // DTMaker - belkin maker DTMaker = "urn:Belkin:device:Maker:1" // DTInsight - belkin insight DTInsight = "urn:Belkin:device:insight:1" // DTLightSwitch - belkin light switch DTLightSwitch = "urn:Belkin:device:lightswitch:1" )
Variables ¶
var ErrUnsupportedAction = errors.New("unsupported action")
ErrUnsupportedAction is returned when you try to perform an action on a piece of hardware that doesn't support it, e.g. calling FetchAttributes on a non Maker device
Functions ¶
This section is empty.
Types ¶
type BinaryState ¶
BinaryState represents the BinaryState information returned from a device
func ParseBinaryState ¶
func ParseBinaryState(body string) *BinaryState
ParseBinaryState parses the BinaryState element that is received from some WeMo devices. It is expected that the body string looks like: <BinaryState>1|1477978435|0|0|0|1168438|0|100|0|0</BinaryState>
type Device ¶
type Device struct { Scan ScanResponse DeviceType string `xml:"deviceType"` FriendlyName string `xml:"friendlyName"` Manufacturer string `xml:"manufacturer"` ManufacturerURL string `xml:"manufacturerURL"` ModelDescription string `xml:"modelDescription"` ModelName string `xml:"modelName"` ModelNumber string `xml:"modelNumber"` ModelURL string `xml:"modelURL"` SerialNumber string `xml:"serialNumber"` UDN string `xml:"UDN"` UPC string `xml:"UPC"` MACAddress string `xml:"macAddress"` FirmwareVersion string `xml:"firmwareVersion"` IconVersion string `xml:"iconVersion"` BinaryState int `xml:"binaryState"` ServiceList []Service `xml:"serviceList>service"` Timeout time.Duration }
Device contains information about a device that has been found on the network
func Scan ¶
func Scan(dt DeviceType, waitTimeSeconds int) ([]*Device, error)
Scan detects Belkin devices on the network. The devices that are returned have limited information in the Scan field, to get more detailed information you will have to call Load() on the device
func (*Device) FetchAttributes ¶
func (d *Device) FetchAttributes(timeout time.Duration) (*DeviceAttributes, error)
FetchAttributes fetches the attributes of the device, such as switch state, sensor state etc
func (*Device) FetchBinaryState ¶
FetchBinaryState fetches the latest binary state value from the device
func (*Device) Load ¶
Load fetches all of the device specific information and updates the calling struct. The timeout parameter specifies how long to wait to connect and get a response before giving up
type DeviceAttributes ¶
type DeviceAttributes struct { // The current state of the switch, 1 -> on, 0 -> off Switch *int // The sensor value, 1 -> open, 0 -> closed Sensor *int // The mode of the switch, 0 -> toggle, 1 -> momentary SwitchMode *int // If the sensor is active, 1 -> yes, 0 -> no SensorPresent *int }
DeviceAttributes contains values returned from the FetchAttributes call. Values are pointers, a nil value indicated we didn't get any value for this particular attribute
func ParseAttributeList ¶
func ParseAttributeList(body string) *DeviceAttributes
ParseAttributeList parses the xml attributeList response from the device e.g. <attributeList><attribute><name>...</name><value>...</value></attribute>...</attributeList> the body must be the open and close attributeList element. If a valid input is not found the function will return nil
type DeviceType ¶
type DeviceType string
DeviceType represents an identifier for the type of Belkin device you want to scan the network for