wemo

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

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

Go to latest
Published: Jan 5, 2016 License: Apache-2.0 Imports: 17 Imported by: 0

README

go.wemo

GoDoc Build Status

Simple package to interface with Belkin wemo devices.

Standalone Usage Guide

Please utilize the branch forktest until a pull request has been submitted for the changes to this library, due to the nature of how go imports libraries.

Utilizing the library in projects

Here is some example usage of the various functionality incorporated in this go repository:

Example - Device discovery
package main

import (
	"fmt"
	"github.com/savaki/go.wemo"
	"time"
)

func main() {
  api, _ := wemo.NewByInterface("en0")
  devices, _ := api.DiscoverAll(3*time.Second)
  for _, device := range devices {
    fmt.Printf("Found %+v\n", device)
  }
}
Example - Control a device
package main

import (
  "fmt"
  "github.com/savaki/go.wemo"
)

func main() {
  // you can either create a device directly OR use the
  // #Discover/#DiscoverAll methods to find devices
  device        := &wemo.Device{Host:"10.0.1.32:49153"}

  // retrieve device info
  deviceInfo, _ := device.FetchDeviceInfo()
  fmt.Printf("Found => %+v\n", deviceInfo)

  // device controls
  device.On()
  device.Off()
  device.Toggle()
  device.BinaryState() // returns 0 or 1
}
Example - Control a named light

As a convenience method, you can control lights through a more generic interface.

package main

import (
  "github.com/savaki/go.wemo"
  "time"
)

func main() {
  api, _ := wemo.NewByInterface("en0")
  api.On("Left Light", 3*time.Second)
  api.Off("Left Light", 3*time.Second)
  api.Toggle("Left Light", 3*time.Second)
}

Documentation

Overview

Copyright 2014 Matt Ho

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	SSDP_BROADCAST = "239.255.255.250:1900"
	M_SEARCH       = "" /* 146-byte string literal not displayed */
	LOCATION       = "LOCATION: "
)

Variables

This section is empty.

Functions

func IncrementMacAddress

func IncrementMacAddress(inputMac string) string

Types

type Device

type Device struct {
	Host   string
	Logger func(string, ...interface{}) (int, error)
}

func (*Device) FetchDeviceInfo

func (d *Device) FetchDeviceInfo(ctx context.Context) (*DeviceInfo, error)

func (*Device) GetBinaryState

func (d *Device) GetBinaryState() int

func (*Device) Off

func (d *Device) Off()

func (*Device) On

func (d *Device) On()

func (*Device) Toggle

func (d *Device) Toggle()

type DeviceInfo

type DeviceInfo struct {
	Device          *Device `json:"-"`
	DeviceType      string  `xml:"deviceType" json:"device-type"`
	FriendlyName    string  `xml:"friendlyName" json:"friendly-name"`
	MacAddress      string  `xml:"macAddress" json:"mac-address"`
	FirmwareVersion string  `xml:"firmwareVersion" json:"firmware-version"`
	SerialNumber    string  `xml:"serialNumber" json:"serial-number"`
}

type DeviceInfos

type DeviceInfos []*DeviceInfo

func (DeviceInfos) Len

func (d DeviceInfos) Len() int

func (DeviceInfos) Less

func (d DeviceInfos) Less(i, j int) bool

func (DeviceInfos) Swap

func (d DeviceInfos) Swap(i, j int)

type Wemo

type Wemo struct {
	Debug bool
	// contains filtered or unexported fields
}

func NewByInterface

func NewByInterface(name string) (*Wemo, error)

find the ip address associated with the specified interface

func NewByIp

func NewByIp(ipAddr string) *Wemo

func (*Wemo) Discover

func (self *Wemo) Discover(urn string, timeout time.Duration) ([]*Device, error)

func (*Wemo) DiscoverAll

func (self *Wemo) DiscoverAll(timeout time.Duration) ([]*Device, error)

func (*Wemo) Off

func (self *Wemo) Off(friendlyName string, timeout time.Duration)

func (*Wemo) On

func (self *Wemo) On(friendlyName string, timeout time.Duration)

func (*Wemo) Toggle

func (self *Wemo) Toggle(friendlyName string, timeout time.Duration)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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