msg-chumby-display 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mathias Dalheimer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = msg-chumby-display
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Mathias Dalheimer. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "msg-chumby-display"
8
+ gem.summary = %Q{Displays various information from the mySmartGrid project on your Chumby}
9
+ gem.description = %Q{The mySmartGrid project provides means to manage your household energy consumption. This gem provides the runtime environment for the Chumby: it queries the mySmartGrid webservice and forwards that information to a Flash application running on the Chumby.}
10
+ gem.email = "md@gonium.net"
11
+ gem.homepage = "http://github.com/gonium/msg-chumby-display"
12
+ gem.authors = ["Mathias Dalheimer"]
13
+ gem.add_dependency "flukso4r", ">= 0.3.1"
14
+ gem.add_dependency "mongrel", ">= 1.1.5"
15
+ gem.bindir='bin'
16
+ gem.executables=['msg-chumby-daemon']
17
+ gem.default_executable = 'msg-chumby-daemon'
18
+ gem.files = FileList["[A-Z]*", "{bin,widget,lib,test}/**/*"]
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.pattern = 'test/**/test_*.rb'
30
+ test.verbose = true
31
+ end
32
+
33
+ begin
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ end
40
+ rescue LoadError
41
+ task :rcov do
42
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
+ end
44
+ end
45
+
46
+ task :test => :check_dependencies
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "msg-chumby-display #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ libpath=File.join(File.dirname(__FILE__), '..', 'lib')
4
+ $:.unshift << libpath
5
+ #puts "Using library path #{$:.join(":")}"
6
+ require 'rubygems'
7
+ require 'lib/msg-chumby-daemon.rb'
8
+
9
+ reading_cache=MSG_Chumby::Reading_Cache.new();
10
+ $demo_importer=MSG_Chumby::DemoReadingImporter.new(reading_cache, 400);
11
+ $importer_thread=nil;
12
+ $server=MSG_Chumby::HTTP_XML_Server.new("127.0.0.1", 3000, reading_cache);
13
+
14
+ def startAll
15
+ $server.start();
16
+ $importer_thread=Thread.new() {
17
+ $demo_importer.doWork();
18
+ }
19
+ $server.join();
20
+ $importer_thread.join();
21
+ end
22
+
23
+ def stopAll
24
+ $server.stop()
25
+ $importer_thread.stop() unless $importer_thread.stop?;
26
+ exit;
27
+ end
28
+
29
+ trap("INT") {stopAll();}
30
+ trap("KILL") {stopAll();}
31
+ startAll();
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'xmlsimple'
3
+ require 'mongrel'
4
+
5
+ module MSG_Chumby
6
+ $counter=0;
7
+
8
+ class TimeHandler < Mongrel::HttpHandler
9
+ def process(request, response)
10
+ response.start(200) do |head,out|
11
+ # puts "Request for time received."
12
+ head["Content-Type"] = "text/xml"
13
+ current_time={'time' => [ Time.now.strftime("%H:%M:%S")], 'counter' => [$counter]}
14
+ out.write(XmlSimple.xml_out( current_time,{'RootName' => "current_time"}));
15
+ $counter+=1
16
+ end
17
+ end
18
+ end
19
+
20
+ class ResetHandler < Mongrel::HttpHandler
21
+ def process(request, response)
22
+ response.start(200) do |head,out|
23
+ puts "Received Reset Request."
24
+ puts "Params: #{request.params}"
25
+ puts "Body: #{request.body}"
26
+ head["Content-Type"] = "text/xml"
27
+ $counter=0
28
+ current_time={'time' => [ Time.now.to_i ], 'counter' => [$counter]}
29
+ out.write(XmlSimple.xml_out( current_time,{'RootName' => "current_time"}));
30
+ end
31
+ end
32
+ end
33
+
34
+ class LastReadingHandler < Mongrel::HttpHandler
35
+ def initialize(reading_cache)
36
+ @reading_cache=reading_cache;
37
+ end
38
+ def process(request, response)
39
+ response.start(200) do |head,out|
40
+ head["Content-Type"] = "text/xml"
41
+ reading=(@reading_cache.last_reading())
42
+ reading = Flukso::UTCReading.new(Time.now.to_i, 0.0) if reading==nil;
43
+ time=Time.at(reading.utc_timestamp);
44
+ current_reading=
45
+ {'time' => [ time.strftime("%H:%M:%S")], 'reading' => [reading.value]};
46
+ out.write(XmlSimple.xml_out( current_reading,{'RootName' => "current_reading"}));
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ class HTTP_XML_Server
53
+ def initialize(host, port, reading_cache)
54
+ @server = Mongrel::HttpServer.new(host, port)
55
+ @server.register("/time", TimeHandler.new)
56
+ @server.register("/reset", ResetHandler.new)
57
+ @server.register("/last_reading", LastReadingHandler.new(reading_cache))
58
+ end
59
+ def start
60
+ @threads=@server.run
61
+ end
62
+ def join
63
+ @threads.join();
64
+ end
65
+ def stop
66
+ @server.stop
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,23 @@
1
+ require 'flukso'
2
+
3
+ module MSG_Chumby
4
+ class Reading_Cache
5
+ def initialize
6
+ @last_reading=nil;
7
+ @last_reading_mutex=Mutex.new();
8
+ end
9
+ def update_last_reading(reading)
10
+ raise "Please provide a UTCReading instance" if reading.class != Flukso::UTCReading
11
+ @last_reading_mutex.synchronize do
12
+ @last_reading=reading
13
+ end
14
+ end
15
+ def last_reading
16
+ retval=nil
17
+ @last_reading_mutex.synchronize do
18
+ retval=@last_reading
19
+ end
20
+ return retval
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'flukso'
3
+ if __FILE__ == $0
4
+ require File.join(File.dirname(__FILE__), 'reading-cache.rb');
5
+ end
6
+
7
+ module MSG_Chumby
8
+ class DemoReadingImporter
9
+ def initialize(reading_cache, max_reading)
10
+ @reading_cache=reading_cache
11
+ @max_reading=max_reading
12
+ end
13
+ def doWork
14
+ loop do
15
+ value=rand(@max_reading)
16
+ reading=Flukso::UTCReading.new(Time.now.to_i, value)
17
+ #puts "generated random reading #{reading}"
18
+ @reading_cache.update_last_reading(reading);
19
+ sleep(3);
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ if __FILE__ == $0
26
+ reading_cache=MSG_Chumby::Reading_Cache.new();
27
+ demo_importer=MSG_Chumby::DemoReadingImporter.new(reading_cache, 400);
28
+ demo_importer.doWork();
29
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'flukso'
3
+ require 'lib/msg-chumby-daemon/http-xml-server.rb'
4
+ require 'lib/msg-chumby-daemon/reading-cache.rb'
5
+ require 'lib/msg-chumby-daemon/reading-importer.rb'
6
+
File without changes
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'msg-chumby-display'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMsgChumbyDisplay < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: msg-chumby-display
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mathias Dalheimer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-05-31 00:00:00 +02:00
13
+ default_executable: msg-chumby-daemon
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: flukso4r
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mongrel
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.5
34
+ version:
35
+ description: "The mySmartGrid project provides means to manage your household energy consumption. This gem provides the runtime environment for the Chumby: it queries the mySmartGrid webservice and forwards that information to a Flash application running on the Chumby."
36
+ email: md@gonium.net
37
+ executables:
38
+ - msg-chumby-daemon
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - LICENSE
46
+ - README.rdoc
47
+ - Rakefile
48
+ - VERSION
49
+ - bin/msg-chumby-daemon
50
+ - lib/msg-chumby-daemon.rb
51
+ - lib/msg-chumby-daemon/http-xml-server.rb
52
+ - lib/msg-chumby-daemon/reading-cache.rb
53
+ - lib/msg-chumby-daemon/reading-importer.rb
54
+ - lib/msg-chumby-display.rb
55
+ - test/helper.rb
56
+ - test/test_msg-chumby-display.rb
57
+ - widget/currentpower/currentpower.fla
58
+ - widget/currentpower/currentpower.swf
59
+ has_rdoc: true
60
+ homepage: http://github.com/gonium/msg-chumby-display
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Displays various information from the mySmartGrid project on your Chumby
87
+ test_files:
88
+ - test/helper.rb
89
+ - test/test_msg-chumby-display.rb