wemo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wemo.rb +8 -0
- data/lib/wemo/switch.rb +26 -11
- data/lib/wemo/version.rb +1 -1
- metadata +3 -3
data/lib/wemo.rb
CHANGED
data/lib/wemo/switch.rb
CHANGED
@@ -4,6 +4,31 @@ require 'curb'
|
|
4
4
|
require 'simple_upnp'
|
5
5
|
module Wemo
|
6
6
|
class Switch
|
7
|
+
def self.on(name)
|
8
|
+
send_command(name, 'on')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.off(name)
|
12
|
+
send_command(name, 'off')
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.state(name)
|
16
|
+
send_command(name, 'off')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.set_binary_state(device_location, signal)
|
20
|
+
c = Curl::Easy.new(device_location.to_s + 'upnp/control/basicevent1')
|
21
|
+
c.headers["Content-type"] = 'text/xml; charset="utf-8"'
|
22
|
+
c.headers["SOAPACTION"] = "\"urn:Belkin:service:basicevent:1#SetBinaryState\""
|
23
|
+
c.verbose = false
|
24
|
+
begin
|
25
|
+
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
|
+
c.perform
|
27
|
+
rescue Curb::Err
|
28
|
+
end
|
29
|
+
# c.body_str
|
30
|
+
end
|
31
|
+
|
7
32
|
def self.send_command(wemo, action)
|
8
33
|
case action
|
9
34
|
when "on"
|
@@ -29,7 +54,6 @@ module Wemo
|
|
29
54
|
if device_json['root']['device']
|
30
55
|
if device_json['root']['device']['friendlyName']
|
31
56
|
friendlyName = device_json['root']['device']['friendlyName']
|
32
|
-
# puts "WeMo Friendly Name: " + friendlyName
|
33
57
|
if friendlyName.downcase == wemo.strip.downcase
|
34
58
|
wemo_device = device_json['root']['device']
|
35
59
|
device_name = friendlyName
|
@@ -41,16 +65,7 @@ module Wemo
|
|
41
65
|
end
|
42
66
|
end
|
43
67
|
if wemo_device
|
44
|
-
|
45
|
-
c.headers["Content-type"] = 'text/xml; charset="utf-8"'
|
46
|
-
c.headers["SOAPACTION"] = "\"urn:Belkin:service:basicevent:1#SetBinaryState\""
|
47
|
-
c.verbose = false
|
48
|
-
begin
|
49
|
-
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>")
|
50
|
-
c.perform
|
51
|
-
rescue Curb::Err
|
52
|
-
end
|
53
|
-
# c.body_str
|
68
|
+
set_binary_state(device_location, signal)
|
54
69
|
end
|
55
70
|
end
|
56
71
|
end
|
data/lib/wemo/version.rb
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
segments:
|
111
111
|
- 0
|
112
|
-
hash: -
|
112
|
+
hash: -1162693111217817383
|
113
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
114
|
none: false
|
115
115
|
requirements:
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash: -
|
121
|
+
hash: -1162693111217817383
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
124
|
rubygems_version: 1.8.23
|