mios 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/lib/mios/device.rb CHANGED
@@ -42,7 +42,15 @@ module MiOS
42
42
  def integer_for(urn, key)
43
43
  value_for(urn, key).to_i
44
44
  end
45
-
45
+
46
+ def float_for(urn, key)
47
+ value_for(urn, key).to_f
48
+ end
49
+
50
+ def time_for(urn, key)
51
+ Time.at(value_for(urn, key).to_i)
52
+ end
53
+
46
54
  def value_for(urn, key)
47
55
  @states.each do |state_hash|
48
56
  if state_hash['service'] == urn
@@ -61,12 +69,12 @@ module MiOS
61
69
  data.select { |k, v|
62
70
  !data[k].kind_of?(Hash) and !data[k].kind_of?(Array)
63
71
  }.to_a
64
- ] unless skip_attributes
65
-
72
+ ] unless skip_attributes
66
73
  @states = data['states']
67
74
  @states.map { |state|
68
75
  state['service'].split(":").last
69
76
  }.uniq.each { |service|
77
+ service.gsub!(/[^a-zA-Z0-9]/, '')
70
78
  if MiOS::Services.const_defined?(service)
71
79
  extend MiOS::Services.const_get(service)
72
80
  else
@@ -33,7 +33,6 @@ module MiOS
33
33
  ['loadtime', 'devicesync'].each do |attr|
34
34
  @attributes[attr] = Time.at(@attributes[attr].to_i)
35
35
  end
36
-
37
36
  @devices = Hash[
38
37
  data['devices'].map { |device|
39
38
  [device['id'], Device.new(@client, @base_uri, device)]
@@ -13,7 +13,7 @@ module MiOS
13
13
  new_level = new_load_level.to_i
14
14
  new_level = 100 if new_load_level > 100
15
15
  new_level = 0 if new_load_level < 0
16
- set(@dimming1_urn, "SetLoadLevelTarget", {"newLoadLevelTarget" => new_level}, async, &block)
16
+ set(@dimming1_urn, "SetLoadLevelTarget", {"newLoadlevelTarget" => new_level}, async, &block)
17
17
  end
18
18
  end
19
19
  end
@@ -2,12 +2,20 @@ module MiOS
2
2
  module Services
3
3
  module EnergyMetering1
4
4
  def self.extended(base)
5
- base.instance_variable_set("@energymetering1_urn", "urn:upnp-org:serviceId:EnergyMetering1")
5
+ base.instance_variable_set("@energymetering1_urn", "urn:micasaverde-com:serviceId:EnergyMetering1")
6
6
  end
7
7
 
8
8
  def watts
9
9
  integer_for(@energymetering1_urn, 'Watts')
10
10
  end
11
+
12
+ def kWh
13
+ float_for(@energymetering1_urn, 'KWH')
14
+ end
15
+
16
+ def last_reading_at
17
+ time_for(@energymetering1_urn, "KWHReading")
18
+ end
11
19
  end
12
20
  end
13
21
  end
@@ -0,0 +1,13 @@
1
+ module MiOS
2
+ module Services
3
+ module HVACFanOperatingMode1
4
+ def self.extended(base)
5
+ base.instance_variable_set("@hvac_fan_operating_mode1_urn", "urn:upnp-org:serviceId:HVAC_FanOperatingMode1")
6
+ end
7
+
8
+ def fan_mode
9
+ value_for(@hvac_fan_operating_mode1_urn, 'Mode')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module MiOS
2
+ module Services
3
+ module HVACOperatingState1
4
+ def self.extended(base)
5
+ base.instance_variable_set("@hvac_operating_state1_urn", "urn:micasaverde-com:serviceId:HVAC_OperatingState1")
6
+ end
7
+
8
+ def operating_state
9
+ value_for(@hvac_operating_state1_urn, 'ModeState')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module MiOS
2
+ module Services
3
+ module HVACUserOperatingMode1
4
+ def self.extended(base)
5
+ base.instance_variable_set("@hvac_user_operating_mode1_urn", "urn:upnp-org:serviceId:HVAC_UserOperatingMode1")
6
+ end
7
+
8
+ def mode
9
+ value_for(@hvac_user_operating_mode1_urn, 'ModeStatus')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module MiOS
2
+ module Services
3
+ module TemperatureSetpoint1Cool
4
+ def self.extended(base)
5
+ base.instance_variable_set("@temperaturesetpoint1cool_urn", "urn:upnp-org:serviceId:TemperatureSetpoint1_Cool")
6
+ end
7
+
8
+ def cool_target
9
+ integer_for(@temperaturesetpoint1cool_urn, 'CurrentSetpoint')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module MiOS
2
+ module Services
3
+ module TemperatureSetpoint1Heat
4
+ def self.extended(base)
5
+ base.instance_variable_set("@temperaturesetpoint1heat_urn", "urn:upnp-org:serviceId:TemperatureSetpoint1_Heat")
6
+ end
7
+
8
+ def heat_target
9
+ integer_for(@temperaturesetpoint1heat_urn, 'CurrentSetpoint')
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/mios/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MiOS
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/mios.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
-
19
+
20
20
  gem.add_dependency "httpclient", ">= 2.2.0"
21
21
  gem.add_dependency "multi_json", ">= 1.3.0"
22
22
 
@@ -24,4 +24,8 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency "syntax"
25
25
  gem.add_development_dependency "rake", ">= 0.9.2"
26
26
  gem.add_development_dependency "yard", ">= 0.7.2"
27
+ gem.add_development_dependency "pry"
28
+ gem.add_development_dependency "vcr"
29
+ gem.add_development_dependency "webmock"
30
+ gem.add_development_dependency "simplecov"
27
31
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe "device" do
4
+ it "should correctly parse service names" do
5
+ output = capture_stderr do
6
+ device = MiOS::Device.new(nil, '', MultiJson.load(File.read('spec/support/device_data/echo-energy-manager.json')))
7
+ end
8
+ expect(output).to eql "WARNING: EEMPlugin1 not yet supported\n"
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "interface" do
4
+ it "should load all the devices" do
5
+ VCR.use_cassette('data_request') do
6
+ mios = MiOS::Interface.new('http://192.168.50.21:3480')
7
+ expect(mios.devices.length).to eql 16
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe MiOS::Services::EnergyMetering1 do
4
+ before do
5
+ @meter = MiOS::Device.new(nil, '', MultiJson.load(File.read('spec/support/device_data/power-meter.json')))
6
+ end
7
+
8
+ describe :watts do
9
+ it "should return the correct power value" do
10
+ expect(@meter.watts).to eql 501
11
+ end
12
+ end
13
+
14
+ describe :kWh do
15
+ it "should return the correct energy value" do
16
+ expect(@meter.kWh).to eql 22.1990
17
+ end
18
+ end
19
+
20
+ describe :last_reading_at do
21
+ it "should return the correct time the last energy value was read" do
22
+ expect(@meter.last_reading_at).to eql Time.at(1395006325)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MiOS::Services::HVACFanOperatingMode1 do
4
+ before do
5
+ @thermostat = MiOS::Device.new(nil, '', MultiJson.load(File.read('spec/support/device_data/thermostat.json')))
6
+ end
7
+
8
+ describe :mode do
9
+ it "should return the correct fan mode" do
10
+ expect(@thermostat.fan_mode).to eql "Auto"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MiOS::Services::HVACOperatingState1 do
4
+ before do
5
+ @thermostat = MiOS::Device.new(nil, '', MultiJson.load(File.read('spec/support/device_data/thermostat.json')))
6
+ end
7
+
8
+ describe :operating_state do
9
+ it "should return the correct operating state" do
10
+ expect(@thermostat.operating_state).to eql "Idle"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MiOS::Services::HVACUserOperatingMode1 do
4
+ before do
5
+ @thermostat = MiOS::Device.new(nil, '', MultiJson.load(File.read('spec/support/device_data/thermostat.json')))
6
+ end
7
+
8
+ describe :mode do
9
+ it "should return the correct operating mode" do
10
+ expect(@thermostat.mode).to eql "HeatOn"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MiOS::Services::TemperatureSetpoint1Cool do
4
+ before do
5
+ @thermostat = MiOS::Device.new(nil, '', MultiJson.load(File.read('spec/support/device_data/thermostat.json')))
6
+ end
7
+
8
+ describe :cool_target do
9
+ it "should return the correct target" do
10
+ expect(@thermostat.cool_target).to eql 80
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MiOS::Services::TemperatureSetpoint1Heat do
4
+ before do
5
+ @thermostat = MiOS::Device.new(nil, '', MultiJson.load(File.read('spec/support/device_data/thermostat.json')))
6
+ end
7
+
8
+ describe :heat_target do
9
+ it "should return the correct target" do
10
+ expect(@thermostat.heat_target).to eql 68
11
+ end
12
+ end
13
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,28 @@
1
1
  require 'rubygems'
2
2
  require 'rspec'
3
+ require 'vcr'
4
+ require 'pry'
5
+ require 'simplecov'
6
+ SimpleCov.start
3
7
 
4
8
  $LOAD_PATH << "#{File.expand_path(File.dirname(__FILE__))}/../lib"
5
9
  require "mios"
10
+
11
+
12
+ VCR.configure do |c|
13
+ c.cassette_library_dir = 'spec/support/vcr_cassettes'
14
+ c.hook_into :webmock # or :fakeweb
15
+ c.allow_http_connections_when_no_cassette = true
16
+ end
17
+
18
+
19
+ def capture_stderr(&block)
20
+ original_stderr = $stderr
21
+ $stderr = fake = StringIO.new
22
+ begin
23
+ yield
24
+ ensure
25
+ $stderr = original_stderr
26
+ end
27
+ fake.string
28
+ end
@@ -0,0 +1,84 @@
1
+ {
2
+ "id":"17",
3
+ "room":"0",
4
+ "id_parent":0,
5
+ "embedded":0,
6
+ "disabled":0,
7
+ "device_file":"D_EchoEnergyManager.xml",
8
+ "manufacturer":"",
9
+ "model":"",
10
+ "altid":"",
11
+ "ip":"",
12
+ "mac":"",
13
+ "time_created":"1394899227",
14
+ "plugin":"1328",
15
+ "states":[
16
+ {
17
+ "id":2,
18
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
19
+ "variable":"DevicesRegistered",
20
+ "value":"1"
21
+ },
22
+ {
23
+ "id":3,
24
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
25
+ "variable":"GotKey",
26
+ "value":"1"
27
+ },
28
+ {
29
+ "id":4,
30
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
31
+ "variable":"UserDataVersion",
32
+ "value":"0"
33
+ },
34
+ {
35
+ "id":5,
36
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
37
+ "variable":"OutsideTS",
38
+ "value":""
39
+ },
40
+ {
41
+ "id":6,
42
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
43
+ "variable":"InsideTS",
44
+ "value":""
45
+ },
46
+ {
47
+ "id":17,
48
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
49
+ "variable":"GatewayRegistered",
50
+ "value":"1"
51
+ },
52
+ {
53
+ "id":34,
54
+ "service":"urn:micasaverde-com:serviceId:EnergyMetering1",
55
+ "variable":"IpFeature",
56
+ "value":"0"
57
+ },
58
+ {
59
+ "id":36,
60
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
61
+ "variable":"EMDeviceList",
62
+ "value":"16;17;3;5;12;14;15"
63
+ },
64
+ {
65
+ "id":37,
66
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
67
+ "variable":"TSDeviceList",
68
+ "value":"17;17;17;17;3;3;3;3;3;3"
69
+ }
70
+ ],
71
+ "invisible":"1",
72
+ "impl_file":"I_EchoEnergyManager.xml",
73
+ "name":"Ergy",
74
+ "ControlURLs":{
75
+ "service_39":{
76
+ "service":"urn:micasaverde-com:serviceId:EEM-Plugin1",
77
+ "ControlURL":"/upnp/control/dev_39",
78
+ "EventURL":"/upnp/event/dev_39",
79
+ "serviceType":"urn:schemas-micasaverde-com:service:EEM-Plugin:1"
80
+ }
81
+ },
82
+ "device_type":"urn:schemas-micasaverde-com:device:EnergyCalculator:1",
83
+ "local_udn":"uuid:4d494342-5342-5645-0011-000002161961"
84
+ }
@@ -0,0 +1,84 @@
1
+ {
2
+ "id":"15",
3
+ "device_type":"urn:schemas-micasaverde-com:device:PowerMeter:1",
4
+ "room":"0",
5
+ "id_parent":14,
6
+ "disabled":0,
7
+ "device_file":"D_PowerMeter1.xml",
8
+ "impl_file":"",
9
+ "manufacturer":"",
10
+ "model":"",
11
+ "altid":"e1",
12
+ "ip":"",
13
+ "mac":"",
14
+ "time_created":"1394899070",
15
+ "states":[
16
+ {
17
+ "service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
18
+ "variable":"VariablesGet",
19
+ "value":"",
20
+ "id":0
21
+ },
22
+ {
23
+ "service":"urn:micasaverde-com:serviceId:EnergyMetering1",
24
+ "variable":"Watts",
25
+ "id":1,
26
+ "value":"501"
27
+ },
28
+ {
29
+ "service":"urn:micasaverde-com:serviceId:EnergyMetering1",
30
+ "variable":"Log",
31
+ "id":2,
32
+ "value":"501,493,516,1395006325,926"
33
+ },
34
+ {
35
+ "service":"urn:micasaverde-com:serviceId:EnergyMetering1",
36
+ "variable":"ActualUsage",
37
+ "value":"1",
38
+ "id":3
39
+ },
40
+ {
41
+ "service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
42
+ "variable":"ManufacturerInfo",
43
+ "value":"0,0,0",
44
+ "id":4
45
+ },
46
+ {
47
+ "service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
48
+ "variable":"Capabilities",
49
+ "value":"82,92,0,4,33,1,R,B,RS,W1,|49,50,",
50
+ "id":5
51
+ },
52
+ {
53
+ "id":29,
54
+ "service":"urn:micasaverde-com:serviceId:EnergyMetering1",
55
+ "variable":"KWH",
56
+ "value":"22.1990"
57
+ },
58
+ {
59
+ "id":30,
60
+ "service":"urn:micasaverde-com:serviceId:EnergyMetering1",
61
+ "variable":"KWHReading",
62
+ "value":"1395006325"
63
+ }
64
+ ],
65
+ "category_num":21,
66
+ "subcategory_num":0,
67
+ "embedded":"1",
68
+ "ControlURLs":{
69
+ "service_35":{
70
+ "service":"urn:micasaverde-com:serviceId:EnergyMetering1",
71
+ "ControlURL":"/upnp/control/dev_35",
72
+ "EventURL":"/upnp/event/dev_35",
73
+ "serviceType":"urn:schemas-micasaverde-com:service:EnergyMetering:1"
74
+ },
75
+ "service_36":{
76
+ "service":"urn:micasaverde-com:serviceId:HaDevice1",
77
+ "ControlURL":"/upnp/control/dev_36",
78
+ "EventURL":"/upnp/event/dev_36",
79
+ "serviceType":"urn:schemas-micasaverde-com:service:HaDevice:1"
80
+ }
81
+ },
82
+ "name":"_Home Energy Monitor Clamp 1",
83
+ "local_udn":"uuid:4d494342-5342-5645-000f-000002161961"
84
+ }