wemo 0.0.2 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +13 -2
- data/lib/wemo.rb +4 -0
- data/lib/wemo/switch.rb +77 -26
- data/lib/wemo/version.rb +1 -1
- data/wemo.gemspec +1 -0
- metadata +20 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Wemo
|
2
2
|
|
3
|
-
|
3
|
+
I sort of combined some stuff. Hopefully noone is upset about the combination, I tried to make it clear where I found stuff.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,9 +16,20 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install wemo
|
18
18
|
|
19
|
+
Use from the command line:
|
20
|
+
|
21
|
+
$ wemo start friendlyName
|
22
|
+
|
23
|
+
$ wemo start light
|
24
|
+
$ wemo start pump
|
25
|
+
$ wemo stop pump
|
26
|
+
$ wemo stop light
|
27
|
+
$ wemo start 'exhaust fan'
|
28
|
+
|
19
29
|
## Usage
|
20
30
|
|
21
|
-
|
31
|
+
Wemo.off('friendlyName')
|
32
|
+
Wemo.on('friendlyName')
|
22
33
|
|
23
34
|
## Contributing
|
24
35
|
|
data/lib/wemo.rb
CHANGED
data/lib/wemo/switch.rb
CHANGED
@@ -2,70 +2,121 @@
|
|
2
2
|
|
3
3
|
require 'curb'
|
4
4
|
require 'simple_upnp'
|
5
|
+
require 'nokogiri'
|
5
6
|
module Wemo
|
6
7
|
class Switch
|
8
|
+
|
9
|
+
attr_accessor :name, :state, :location, :details
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
self.name = name
|
13
|
+
self.find_device
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
7
17
|
def self.on(name)
|
8
|
-
|
18
|
+
new(name).on
|
9
19
|
end
|
10
20
|
|
11
21
|
def self.off(name)
|
12
|
-
|
22
|
+
new(name).off
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.status(name)
|
26
|
+
new(name).status
|
27
|
+
end
|
28
|
+
|
29
|
+
def on
|
30
|
+
set_binary_state(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
def off
|
34
|
+
set_binary_state(0)
|
13
35
|
end
|
14
36
|
|
15
|
-
def
|
16
|
-
|
37
|
+
def status
|
38
|
+
get_binary_state
|
17
39
|
end
|
18
40
|
|
19
|
-
def
|
20
|
-
|
41
|
+
def set_binary_state(signal)
|
42
|
+
find_device unless self.location != nil
|
43
|
+
c = Curl::Easy.new(self.location.to_s + 'upnp/control/basicevent1')
|
21
44
|
c.headers["Content-type"] = 'text/xml; charset="utf-8"'
|
22
45
|
c.headers["SOAPACTION"] = "\"urn:Belkin:service:basicevent:1#SetBinaryState\""
|
23
46
|
c.verbose = false
|
24
47
|
begin
|
25
48
|
c.http_post("<?xml version='1.0' encoding='utf-8'?><s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/' s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><s:Body><u:SetBinaryState xmlns:u='urn:Belkin:service:basicevent:1'><BinaryState>#{signal}</BinaryState></u:SetBinaryState></s:Body></s:Envelope>")
|
26
49
|
c.perform
|
27
|
-
rescue
|
50
|
+
rescue
|
28
51
|
end
|
52
|
+
self.state = signal
|
29
53
|
# c.body_str
|
30
54
|
end
|
31
55
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
56
|
+
|
57
|
+
def get_binary_state
|
58
|
+
find_device unless self.location != nil
|
59
|
+
c = Curl::Easy.new(self.location.to_s + 'upnp/control/basicevent1')
|
60
|
+
c.headers["Content-type"] = 'text/xml; charset="utf-8"'
|
61
|
+
c.headers["SOAPACTION"] = "\"urn:Belkin:service:basicevent:1#GetBinaryState\""
|
62
|
+
c.verbose = false
|
63
|
+
begin
|
64
|
+
c.http_post("<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:GetBinaryState xmlns:u=\"urn:Belkin:service:basicevent:1\"></u:GetBinaryState></s:Body></s:Envelope>")
|
65
|
+
c.perform
|
66
|
+
rescue
|
38
67
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
68
|
+
|
69
|
+
xml = Nokogiri::XML(c.body_str).text.strip.to_i
|
70
|
+
self.state = xml
|
71
|
+
if xml == 0
|
72
|
+
return false
|
73
|
+
else
|
74
|
+
return true
|
75
|
+
end
|
76
|
+
end
|
43
77
|
|
78
|
+
def find_device
|
44
79
|
SimpleUpnp::Discovery.find do |device|
|
45
80
|
begin
|
46
|
-
device_json = device.to_json(
|
81
|
+
device_json = device.to_json(true)
|
47
82
|
rescue
|
48
83
|
next
|
49
84
|
end
|
50
|
-
|
51
85
|
# puts device_json.inspect
|
52
|
-
|
86
|
+
|
53
87
|
if device_json['root']
|
54
88
|
if device_json['root']['device']
|
55
89
|
if device_json['root']['device']['friendlyName']
|
56
90
|
friendlyName = device_json['root']['device']['friendlyName']
|
57
|
-
if friendlyName.downcase ==
|
58
|
-
|
59
|
-
|
60
|
-
|
91
|
+
if friendlyName.downcase == self.name.strip.downcase
|
92
|
+
self.details = device_json['root']['device']
|
93
|
+
self.name = friendlyName
|
94
|
+
self.location = /https?:\/\/[\S]+\//.match(device_json[:location]).to_s
|
61
95
|
break
|
62
96
|
end
|
63
97
|
end
|
64
98
|
end
|
65
99
|
end
|
66
100
|
end
|
67
|
-
|
68
|
-
|
101
|
+
status
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.send_command(name, action)
|
105
|
+
case action
|
106
|
+
when "on"
|
107
|
+
signal = 1
|
108
|
+
when "off"
|
109
|
+
signal = 0
|
110
|
+
when 'status'
|
111
|
+
signal = false
|
112
|
+
end
|
113
|
+
d = Wemo::Switch.new(name)
|
114
|
+
if d.details
|
115
|
+
if signal
|
116
|
+
response = d.set_binary_state(signal)
|
117
|
+
else
|
118
|
+
response = d.get_binary_state
|
119
|
+
end
|
69
120
|
end
|
70
121
|
end
|
71
122
|
end
|
data/lib/wemo/version.rb
CHANGED
data/wemo.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wemo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: nokogiri
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
description: this is a combo. I took several things from around and fixed them, mostly
|
79
95
|
taken from https://github.com/bobbrodie/siriproxy-wemo
|
80
96
|
email:
|
@@ -109,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
125
|
version: '0'
|
110
126
|
segments:
|
111
127
|
- 0
|
112
|
-
hash:
|
128
|
+
hash: 2588951935745406503
|
113
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
130
|
none: false
|
115
131
|
requirements:
|
@@ -118,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
134
|
version: '0'
|
119
135
|
segments:
|
120
136
|
- 0
|
121
|
-
hash:
|
137
|
+
hash: 2588951935745406503
|
122
138
|
requirements: []
|
123
139
|
rubyforge_project:
|
124
140
|
rubygems_version: 1.8.23
|