thermostat 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 1.1.0 2010-03-10
2
+ * relatively complete unit test coverage
3
+ * add a simulation mode to the network layer so it's easier to test
4
+ * include usage methods in the main thermostat object
5
+
1
6
  === 1.0.0 2010-03-09
2
7
 
3
8
  * major enhancements:
@@ -5,7 +5,6 @@ README.rdoc
5
5
  Rakefile
6
6
  account.yaml.example
7
7
  config/website.yml
8
- config/website.yml.sample
9
8
  docs/PDP_API_R1_11.pdf
10
9
  examples/test-fan-off.rb
11
10
  examples/test-fan-on.rb
@@ -20,6 +19,7 @@ script/destroy
20
19
  script/generate
21
20
  script/txt2html
22
21
  test/test_helper.rb
22
+ test/test_network.rb
23
23
  test/test_oid.rb
24
24
  test/test_thermostat.rb
25
25
  website/index.html
@@ -32,7 +32,16 @@ request and subsequent get request.
32
32
 
33
33
  == SYNOPSIS:
34
34
 
35
- FIX (code sample of usage)
35
+ thermostat = Thermostate.new("hostname", "admin", "password")
36
+
37
+ # get the current temperature
38
+ current_temp = thermostat.temp
39
+
40
+ # get the current setback heat value
41
+ current_target_temp = thermostat.heat_to
42
+
43
+ # set the thermostat to 69F (units are set in the thermost)
44
+ thermostat.heat_to = 69
36
45
 
37
46
  == REQUIREMENTS:
38
47
 
@@ -44,7 +53,7 @@ sudo gem install thermostat
44
53
 
45
54
  (The MIT License)
46
55
 
47
- Copyright (c) 2010 Sean Dague
56
+ Copyright (c) 2008-2010 Sean Dague
48
57
 
49
58
  Permission is hereby granted, free of charge, to any person obtaining
50
59
  a copy of this software and associated documentation files (the
@@ -6,11 +6,16 @@ module Proliphix
6
6
  require "open-uri"
7
7
 
8
8
  class Network
9
+ attr_accessor :debug, :simulate, :query, :squery, :buffer
10
+
9
11
  def initialize(ip, user, passwd)
12
+ @buffer = ""
13
+ @debug = false
14
+ @simulate = false
10
15
  @ip = ip
11
16
  @user = user
12
17
  @passwd = passwd
13
- @last = Time.now.to_i
18
+ @last = Time.now.to_i - 120
14
19
  @fetched = {}
15
20
  @sensors = [
16
21
  ThermHvacMode,
@@ -43,7 +48,9 @@ module Proliphix
43
48
 
44
49
  def set(name, value)
45
50
  set_data(name, value)
46
- sleep 1
51
+ if not @simulate
52
+ sleep 1
53
+ end
47
54
  fetch_data
48
55
  end
49
56
 
@@ -60,34 +67,41 @@ module Proliphix
60
67
  end
61
68
 
62
69
  def get_query_url
63
- query = ""
64
- for item in @sensors
65
- if query != ""
66
- query += "&"
67
- end
68
- query += "OID#{item.oid}="
70
+ @query = url + "/get?" + @sensors.map {|item| "OID#{item.oid}="}.join("&")
71
+ if @debug
72
+ puts @query
69
73
  end
70
- query = url + "/get?" + query
74
+ return @query
71
75
  end
72
76
 
73
77
  def set_query_url(mod, value)
74
- query = "OID#{mod.oid}=#{value}"
75
- query = url + "/pdp?" + query + "&sumbit=Submit"
78
+ @squery = url + "/pdp?OID#{mod.oid}=#{value}&sumbit=Submit"
79
+ if @debug
80
+ puts @squery
81
+ end
82
+ return @squery
76
83
  end
77
84
 
78
85
  # Because of the timing issues with the thermostat we want to
79
86
  # get all the data we can in one packet.
80
87
  def fetch_data()
81
- open(get_query_url, :http_basic_authentication => [@user, @passwd]) do |line|
82
- parse_data(line.read)
88
+ url = get_query_url
89
+ if not simulate
90
+ open(url, :http_basic_authentication => [@user, @passwd]) do |line|
91
+ @buffer = line.read
92
+ end
83
93
  end
94
+ parse_data(@buffer)
84
95
  return self
85
96
  end
86
97
 
87
98
  def set_data(mod, value)
88
99
  unless mod.ro?
89
- open(set_query_url(mod, value), :http_basic_authentication => [@user, @passwd]) do |line|
90
- parse_data(line.read)
100
+ url = set_query_url(mod, value)
101
+ if not simulate
102
+ open(url, :http_basic_authentication => [@user, @passwd]) do |line|
103
+ @buffer = line.read
104
+ end
91
105
  end
92
106
  end
93
107
  return self
@@ -97,6 +111,10 @@ module Proliphix
97
111
  # includes oids = values in what looks like a uri string. So
98
112
  # split twice to get values.
99
113
  def parse_data(raw_data)
114
+ if @debug
115
+ puts raw_data
116
+ end
117
+
100
118
  results = raw_data.split('&')
101
119
  results.each do |r|
102
120
  (oid, value) = r.split('=')
@@ -4,12 +4,14 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  # This is the main class for controlling the Proliphix Thermostat.
5
5
  # You must first initialize it with the control point credentials
6
6
  class Thermostat
7
- VERSION = '1.0.0'
7
+ VERSION = '1.1.0'
8
8
 
9
9
  require 'pdp/oid'
10
10
  require 'pdp/constants'
11
11
  require 'pdp/network'
12
12
 
13
+ attr :network
14
+
13
15
  include Proliphix
14
16
 
15
17
  # create a new thermostat object. It needs
@@ -89,6 +91,21 @@ class Thermostat
89
91
  self[ThermHvacState] == "Cool"
90
92
  end
91
93
 
94
+ # The number of minutes of active heating since last reset of the counters.
95
+ def heat_usage
96
+ self[ThermHeat1Usage]
97
+ end
98
+
99
+ # The number of minutes of active cooling since last reset of the counters.
100
+ def cool_usage
101
+ self[ThermCool1Usage]
102
+ end
103
+
104
+ # The number of minutes the fan was running since last reset of the counters.
105
+ def fan_usage
106
+ self[ThermFanUsage]
107
+ end
108
+
92
109
  # Is the fan currently on. It doesn't matter why it's on, just
93
110
  # that it's on.
94
111
  def fan_on?
@@ -3,14 +3,14 @@ require 'test/unit'
3
3
  require File.dirname(__FILE__) + '/../lib/thermostat'
4
4
 
5
5
  @@values = {}
6
- module Proliphix
7
- class Network
8
- def get(name)
9
- @@values[name]
10
- end
6
+ # module Proliphix
7
+ # class Network
8
+ # def get(name)
9
+ # @@values[name]
10
+ # end
11
11
 
12
- def set(name, value)
13
- @@values[name] = value
14
- end
15
- end
16
- end
12
+ # def set(name, value)
13
+ # @@values[name] = value
14
+ # end
15
+ # end
16
+ # end
@@ -0,0 +1,78 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestThermostatNetwork < Test::Unit::TestCase
4
+ include Proliphix
5
+
6
+ def squery
7
+ @@t.network.squery
8
+ end
9
+ def query
10
+ @@t.network.query
11
+ end
12
+
13
+ def setup
14
+ @@t = Thermostat.new("foo", "me", "go")
15
+ @@t.network.simulate = 1
16
+ # this is some real data
17
+ @@t.network.buffer = "OID4.1.1=2&OID4.1.2=3&OID4.1.3=1&OID4.1.4=2&OID4.1.5=690&OID4.1.6=760&OID4.5.1=87337&OID4.5.3=47835&OID4.5.5=36826&OID4.1.13=686&"
18
+ end
19
+
20
+ def test_get_query_generate
21
+ base_query = "http://foo/get?OID4.1.1=&OID4.1.2=&OID4.1.3=&OID4.1.4=&OID4.1.5=&OID4.1.6=&OID4.5.1=&OID4.5.3=&OID4.5.5=&OID4.1.13="
22
+
23
+ @@t.heat_to
24
+ assert_equal(base_query, query)
25
+
26
+ @@t.cool_to
27
+ assert_equal(base_query, query)
28
+
29
+ @@t.temp
30
+ assert_equal(base_query, query)
31
+
32
+ @@t.fan_on?
33
+ assert_equal(base_query, query)
34
+ end
35
+
36
+ def test_set_query_generate
37
+ @@t.heat_to = 68
38
+ assert_equal("http://foo/pdp?OID4.1.5=680&sumbit=Submit", squery)
39
+
40
+ @@t.heat_to = 68.0
41
+ assert_equal("http://foo/pdp?OID4.1.5=680&sumbit=Submit", squery)
42
+
43
+ @@t.heat_to = 68.01
44
+ assert_equal("http://foo/pdp?OID4.1.5=680&sumbit=Submit", squery)
45
+
46
+ @@t.heat_to = 68.095
47
+ assert_equal("http://foo/pdp?OID4.1.5=680&sumbit=Submit", squery)
48
+
49
+
50
+ @@t.cool_to = 76.5
51
+ assert_equal("http://foo/pdp?OID4.1.6=765&sumbit=Submit", squery)
52
+
53
+ @@t.cool_to = 76.51
54
+ assert_equal("http://foo/pdp?OID4.1.6=765&sumbit=Submit", squery)
55
+
56
+ @@t.cool_to = 76.519
57
+ assert_equal("http://foo/pdp?OID4.1.6=765&sumbit=Submit", squery)
58
+
59
+ @@t.fan_off!
60
+ assert_equal("http://foo/pdp?OID4.1.3=1&sumbit=Submit", squery)
61
+
62
+ @@t.fan_on!
63
+ assert_equal("http://foo/pdp?OID4.1.3=2&sumbit=Submit", squery)
64
+
65
+ @@t.network.squery = ""
66
+
67
+ # we have some safety measures in here
68
+ @@t.cool_to = 45
69
+ assert_equal("", squery)
70
+
71
+ @@t.cool_to = -100
72
+ assert_equal("", squery)
73
+
74
+ @@t.heat_to = 90
75
+ assert_equal("", squery)
76
+ end
77
+
78
+ end
@@ -1,12 +1,19 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- require "pp"
4
-
5
- class TestThermostat < Test::Unit::TestCase
6
- include Proliphix
7
-
8
- def test_therm
9
- puts ThermSetbackHeat[680]
10
- end
11
-
12
- end
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "pp"
4
+
5
+ class TestThermostat < Test::Unit::TestCase
6
+ include Proliphix
7
+
8
+ def test_oid_values
9
+ assert_equal(68, ThermSetbackHeat[680])
10
+ assert_equal(68.0, ThermSetbackHeat[680])
11
+
12
+ assert_equal(68, ThermSetbackCool[680])
13
+ assert_equal(68.0, ThermSetbackCool[680])
14
+
15
+ assert_equal(68, ThermAverageTemp[680])
16
+ assert_equal(68.0, ThermAverageTemp[680])
17
+ end
18
+
19
+ end
@@ -4,23 +4,50 @@ class TestThermostat < Test::Unit::TestCase
4
4
  include Proliphix
5
5
 
6
6
  def setup
7
- @@thermostat = Thermostat.new("foo", "me", "go")
7
+ @@t = Thermostat.new("foo", "me", "go")
8
+ @@t.network.simulate = true
8
9
  end
9
10
 
10
11
  def test_scenario_one
11
- @@values[ThermHvacMode] = "Heat"
12
- @@values[ThermSetbackHeat] = 69.0
13
- @@values[ThermSetbackCool] = 79.0
14
- @@values[ThermAverageTemp] = 68.5
12
+ @@t.network.buffer = "OID4.1.1=2&OID4.1.2=3&OID4.1.3=1&OID4.1.4=2&OID4.1.5=690&OID4.1.6=760&OID4.5.1=87337&OID4.5.3=47835&OID4.5.5=36826&OID4.1.13=686&"
15
13
 
16
- assert_equal @@thermostat.mode, "Heat"
17
- assert_equal @@thermostat.temp, 68.5
18
- assert_equal @@thermostat.heat_to, 69.0
19
- assert_equal @@thermostat.cool_to, nil
14
+ assert_equal "Heat", @@t.mode
15
+ assert_equal 68.6, @@t.temp
16
+ assert_equal 69.0, @@t.heat_to
17
+ assert_equal true, @@t.heating?
18
+ assert_equal true, @@t.fan_on?
19
+ assert_equal false, @@t.cooling?
20
+ assert_equal nil, @@t.cool_to
21
+ assert_equal 87337, @@t.heat_usage
22
+ assert_equal 47835, @@t.cool_usage
23
+ assert_equal 36826, @@t.fan_usage
20
24
  end
21
25
 
22
26
  def test_scenario_two
27
+ @@t.network.buffer = "OID4.1.1=1&OID4.1.2=2&OID4.1.3=1&OID4.1.4=1&OID4.1.5=690&OID4.1.6=760&OID4.5.1=87337&OID4.5.3=47835&OID4.5.5=36826&OID4.1.13=686&"
28
+
29
+ assert_equal "Off", @@t.mode
30
+ assert_equal 68.6, @@t.temp
31
+ assert_equal nil, @@t.heat_to
32
+ assert_equal false, @@t.heating?
33
+ assert_equal false, @@t.fan_on?
34
+ assert_equal false, @@t.cooling?
35
+ assert_equal nil, @@t.cool_to
23
36
 
24
37
  end
25
-
38
+
39
+ def test_scenario_three
40
+ @@t.network.buffer = "OID4.1.1=3&OID4.1.2=2&OID4.1.3=1&OID4.1.4=1&OID4.1.5=690&OID4.1.6=760&OID4.5.1=87337&OID4.5.3=47835&OID4.5.5=36826&OID4.1.13=686&"
41
+
42
+ assert_equal "Cool", @@t.mode
43
+ assert_equal 68.6, @@t.temp
44
+ assert_equal nil, @@t.heat_to
45
+ assert_equal false, @@t.heating?
46
+ assert_equal false, @@t.fan_on?
47
+ assert_equal false, @@t.cooling?
48
+ assert_equal 76, @@t.cool_to
49
+ assert_equal 76.0, @@t.cool_to
50
+
51
+ end
52
+
26
53
  end
@@ -34,7 +34,7 @@
34
34
  <div class="sidebar">
35
35
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/sdaguegems"; return false'>
36
36
  <p>Get Version</p>
37
- <a href="http://rubyforge.org/projects/sdaguegems" class="numbers">1.0</a>
37
+ <a href="http://rubyforge.org/projects/sdaguegems" class="numbers">1.0.0</a>
38
38
  </div>
39
39
  </div>
40
40
  <h2>What</h2>
@@ -63,7 +63,7 @@ rake install_gem</pre>
63
63
  <h2>Contact</h2>
64
64
  <p>Comments are welcome. Send an email to <a href="mailto:sean@dague.net">Sean Dague</a></p>
65
65
  <p class="coda">
66
- <a href="FIXME email">FIXME full name</a>, 6th March 2010<br>
66
+ <a href="FIXME email">FIXME full name</a>, 7th March 2010<br>
67
67
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
68
68
  </p>
69
69
  </div>
@@ -12,9 +12,21 @@ h2. Installing
12
12
 
13
13
  h2. The basics
14
14
 
15
-
16
15
  h2. Demonstration of usage
17
16
 
17
+ <pre syntax="ruby">
18
+ thermostat = Thermostate.new("hostname", "admin", "password")
19
+
20
+ # get the current temperature
21
+ current_temp = thermostat.temp
22
+
23
+ # get the current setback heat value
24
+ current_target_temp = thermostat.heat_to
25
+
26
+ # set the thermostat to 69F (units are set in the thermost)
27
+ thermostat.heat_to = 69
28
+ </pre>
29
+
18
30
  h2. Documentation
19
31
 
20
32
  Full module level documentat can be found here:http://sdaguegems.rubyforge.org/thermostat/rdoc
@@ -22,7 +34,7 @@ Full module level documentat can be found here:http://sdaguegems.rubyforge.org/t
22
34
 
23
35
  h2. How to submit patches
24
36
 
25
- Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
37
+ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/
26
38
 
27
39
  You can fetch the source from
28
40
 
@@ -30,13 +42,16 @@ You can fetch the source from
30
42
 
31
43
  <pre>git clone git://github.com/sdague/thermostat.rb.git</pre>
32
44
 
45
+ To send me code updates, fork the tree on github, make your changes,
46
+ then send me a pull request. That will make it easy for me to
47
+ integrate your patches.
48
+
33
49
  h3. Build and test instructions
34
50
 
35
51
  <pre>cd thermostat
36
52
  rake test
37
53
  rake install_gem</pre>
38
54
 
39
-
40
55
  h2. License
41
56
 
42
57
  This code is free to use under the terms of the MIT license.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thermostat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Dague
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-03-09 00:00:00 -05:00
12
+ date: 2010-03-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -79,7 +79,6 @@ files:
79
79
  - Rakefile
80
80
  - account.yaml.example
81
81
  - config/website.yml
82
- - config/website.yml.sample
83
82
  - docs/PDP_API_R1_11.pdf
84
83
  - examples/test-fan-off.rb
85
84
  - examples/test-fan-on.rb
@@ -94,6 +93,7 @@ files:
94
93
  - script/generate
95
94
  - script/txt2html
96
95
  - test/test_helper.rb
96
+ - test/test_network.rb
97
97
  - test/test_oid.rb
98
98
  - test/test_thermostat.rb
99
99
  - website/index.html
@@ -131,6 +131,7 @@ signing_key:
131
131
  specification_version: 3
132
132
  summary: Thermostat.rb is an attempt to build an easy to use ruby api around the web services provided by the Proliphix line of network thermostats
133
133
  test_files:
134
+ - test/test_network.rb
134
135
  - test/test_thermostat.rb
135
136
  - test/test_oid.rb
136
137
  - test/test_helper.rb
@@ -1,2 +0,0 @@
1
- host: unknown@rubyforge.org
2
- remote_dir: /var/www/gforge-projects/thermostat