guh 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d9c96fa741e8caf95a21bd27791fe42948d38e9
4
- data.tar.gz: 2b02f5eae38bd78c9c47b934d2480654843ddf3c
3
+ metadata.gz: fa6cbfff073870eabcc433d92c9f92d48cb8bd0e
4
+ data.tar.gz: 34762aeabd46d3c0f8d7aa0aaaf6710d5f5c779f
5
5
  SHA512:
6
- metadata.gz: 3d6e69e38dd6833f5a8f6df2bf9d1c2a9ce0513512655f67ea15fb91090df70eda1a75ed6bb34d1e3faf3bc25aedf6e4649babcc21f9fdf79e79ce0aca78700f
7
- data.tar.gz: b7534ed8453175c5d4886cafa03322d307d22ab89335571d9a6eef3e9e8d917e1a443b246e10bfe65d380d6cf93bdcf53a78f2fad86d43a5ba2deed80db830bc
6
+ metadata.gz: 476d41353de9a87a7ee4585d9317b005e5a837ceccd34f0341c929c1ed0942b7e152387ab35b8382e1db81bbb97fd66ddd6819f403e7ea3a3d622d0c5c7446cd
7
+ data.tar.gz: 97c5ff55e9855e436e411905e4c628fee5e66193f214742f102380ec721347403e82df861884f248401dd61dbdeb55077ac588ddb50a5c3825af727385d01f54
data/Rakefile CHANGED
@@ -14,4 +14,4 @@ task :console do
14
14
  require 'guh'
15
15
  ARGV.clear
16
16
  IRB.start
17
- end
17
+ end
data/guh.gemspec CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
-
20
+
21
21
  spec.add_dependency "json", "~> 1.8"
22
-
22
+
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake", "~> 10.3"
25
25
  spec.add_development_dependency "rspec", "~> 2.14"
data/lib/guh/action.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  module Guh
2
2
  ##
3
3
  # This class wraps everything related to Actions.
4
- #
4
+ #
5
5
  class Action < Base
6
-
6
+
7
7
  ##
8
- #
8
+ #
9
9
  # Executes a specific Action on a specific Device.
10
- #
10
+ #
11
11
  # To activate an "Elro Power Switch":
12
- #
12
+ #
13
13
  # Guh::Action.execute("TODO find specific device id", "{31c9758e-6567-4f89-85bb-29e1a7c55d44}", {power: true})
14
- #
14
+ #
15
15
  def self.execute(device_id, action_type_id, params={})
16
16
  response = get({
17
17
  id: generate_request_id,
@@ -19,16 +19,16 @@ module Guh
19
19
  params: {
20
20
  deviceId: device_id,
21
21
  actionTypeId: action_type_id,
22
- params: convert_map_to_list_of_maps(params)
22
+ params: params
23
23
  }
24
24
  })
25
-
25
+
26
26
  if response['success']==true
27
27
  return response
28
28
  else
29
29
  raise Guh::ArgumentError, response['errorMessage']
30
30
  end
31
31
  end
32
-
32
+
33
33
  end
34
34
  end
@@ -3,14 +3,14 @@ module Guh
3
3
  # This class wraps everything related to ActionTypes.
4
4
  #
5
5
  class ActionType < Base
6
-
6
+
7
7
  ##
8
8
  # Retrieves all known ActionTypes for a specific Device identified by its +device_id+.
9
9
  #
10
10
  # Example:
11
- #
11
+ #
12
12
  # Guh::ActionType.all("{308ae6e6-38b3-4b3a-a513-3199da2764f8}")
13
- #
13
+ #
14
14
  def self.all(device_class_id)
15
15
  response = get({
16
16
  id: generate_request_id,
@@ -19,9 +19,9 @@ module Guh
19
19
  deviceClassId: device_class_id
20
20
  }
21
21
  })
22
-
22
+
23
23
  response['actionTypes']
24
24
  end
25
-
25
+
26
26
  end
27
27
  end
data/lib/guh/base.rb CHANGED
@@ -1,149 +1,149 @@
1
1
  module Guh
2
2
  ##
3
3
  # The base class which all the specific wrapper classes inherit from. It provides some shared code to make development easier.
4
- #
4
+ #
5
5
  class Base
6
-
6
+
7
7
  # Getter/Setter for the guh_ip_address attribute
8
8
  def self.guh_ip_address #:nodoc:
9
- @@guh_ip_address
9
+ @@guh_ip_address
10
10
  end
11
11
  def self.guh_ip_address=(hia) #:nodoc:
12
12
  @@guh_ip_address=hia
13
- end
13
+ end
14
14
  @@guh_ip_address = "127.0.0.1"
15
-
15
+
16
16
  # Getter/Setter for the guh_port attribute
17
- def self.guh_port #:nodoc:
17
+ def self.guh_port #:nodoc:
18
18
  @@guh_port
19
19
  end
20
20
  def self.guh_port=(hia) #:nodoc:
21
21
  @@guh_port=hia
22
22
  end
23
23
  @@guh_port = 1234
24
-
24
+
25
25
  ##
26
- #
26
+ #
27
27
  # Returns everything that is going on inside guh Core
28
- #
28
+ #
29
29
  # Example:
30
- #
30
+ #
31
31
  # Guh::Base.introspect
32
- #
32
+ #
33
33
  def self.introspect
34
34
  get({
35
35
  id: generate_request_id,
36
36
  method: "JSONRPC.Introspect",
37
37
  })
38
38
  end
39
-
39
+
40
40
  ##
41
- #
41
+ #
42
42
  # <b>Don't use this unless you know what you are doing!</b>
43
- #
43
+ #
44
44
  # Send a request to guh Core and fetch the Response. This is a utility method used by the subclasses.
45
- #
45
+ #
46
46
  def self.get(request_hash)
47
47
  request_string = hash_to_json(request_hash)
48
-
48
+
49
49
  response = nil
50
50
  client do |c|
51
51
  c.puts(request_string)
52
-
52
+
53
53
  response = fetch_message(c)
54
54
  end
55
-
55
+
56
56
  if response['status']=='success'
57
57
  return response['params']
58
58
  else
59
59
  raise Guh::ResponseError, "The Request was not successful"
60
60
  end
61
61
  end
62
-
62
+
63
63
  ##
64
- #
64
+ #
65
65
  # Configuration DSL helper method.
66
- #
67
- # The default values are:
66
+ #
67
+ # The default values are:
68
68
  # * +guh_ip_address+: 127.0.0.1
69
69
  # * +guh_port+: 1234
70
- #
70
+ #
71
71
  # Example:
72
- #
72
+ #
73
73
  # Guh.configure do |config|
74
74
  # config.guh_ip_address = 10.0.0.1
75
75
  # config.guh_port = 6789
76
76
  # end
77
- #
77
+ #
78
78
  def self.configure(&block)
79
79
  yield self
80
80
  end
81
-
81
+
82
82
  private
83
-
83
+
84
84
  def self.generate_request_id
85
85
  999999
86
86
  end
87
-
87
+
88
88
  def self.client(&block)
89
89
  client = TCPSocket.open(@@guh_ip_address, @@guh_port)
90
-
90
+
91
91
  connection_message = fetch_message(client)
92
-
92
+
93
93
  # TODO check guh-core version and raise error if incompatible with this gem's version
94
94
  # TODO look for timeout or connection refused errors
95
-
95
+
96
96
  yield client
97
97
  end
98
-
98
+
99
99
  def self.fetch_message(client)
100
100
  end_of_message = false
101
-
101
+
102
102
  message = ""
103
103
  while (line = client.gets)
104
104
  message << line
105
-
105
+
106
106
  end_of_message = true if line.match(/^\}\n/)
107
-
107
+
108
108
  break if end_of_message
109
109
  end
110
-
110
+
111
111
  return JSON::parse(message)
112
112
  end
113
-
113
+
114
114
  ##
115
115
  #
116
116
  # Converts a regular hash into a list of hashes.
117
- #
118
- # Example:
119
- #
117
+ #
118
+ # Example:
119
+ #
120
120
  # convert_map_to_list_of_maps({
121
121
  # power: true,
122
122
  # pin: 1,
123
123
  # family_code: 'A'
124
124
  # })
125
125
  #
126
- # Returns:
127
- #
126
+ # Returns:
127
+ #
128
128
  # [
129
129
  # {power: true},
130
130
  # {pin: 1},
131
131
  # {family_code: 'A'}
132
132
  # ]
133
- #
133
+ #
134
134
  def self.convert_map_to_list_of_maps(map)
135
135
  # make sure we have an array to work with
136
136
  map ||= []
137
-
137
+
138
138
  # do the conversion work
139
139
  list = []
140
140
  map.each do |key, value|
141
141
  list << {key => value}
142
142
  end
143
-
143
+
144
144
  return list
145
145
  end
146
-
146
+
147
147
  def self.hash_to_json(hash)
148
148
  JSON::dump(hash) + "\n"
149
149
  end
data/lib/guh/device.rb CHANGED
@@ -3,39 +3,39 @@ module Guh
3
3
  # This class wraps everything related to configured Devices.
4
4
  #
5
5
  class Device < Base
6
-
7
-
6
+
7
+
8
8
  ##
9
9
  #
10
10
  def self.find(id)
11
11
  device = self.all.detect{|d| d['id']==id}
12
-
12
+
13
13
  return device
14
14
  end
15
-
15
+
16
16
  ##
17
- #
17
+ #
18
18
  # Returns a list of all configured Devices.
19
- #
19
+ #
20
20
  # Example:
21
- #
21
+ #
22
22
  # Guh::Device.all
23
- #
23
+ #
24
24
  def self.all
25
25
  response = get({
26
26
  id: generate_request_id,
27
27
  method: "Devices.GetConfiguredDevices"
28
28
  })
29
-
29
+
30
30
  return response['devices']
31
31
  end
32
-
32
+
33
33
  ##
34
- #
34
+ #
35
35
  # Creates a configured device and returns it's ID.
36
- #
36
+ #
37
37
  # Example for the "Elro Power Switch":
38
- #
38
+ #
39
39
  # Guh::Device.add("{308ae6e6-38b3-4b3a-a513-3199da2764f8}", {
40
40
  # channel1: true,
41
41
  # channel2: false,
@@ -48,7 +48,7 @@ module Guh
48
48
  # channel9: false,
49
49
  # channel10: false
50
50
  # })
51
- #
51
+ #
52
52
  def self.add(device_class_id, params)
53
53
  response = get({
54
54
  id: generate_request_id,
@@ -64,17 +64,17 @@ module Guh
64
64
  raise Guh::ArgumentError, response['errorMessage']
65
65
  end
66
66
  end
67
-
67
+
68
68
  ##
69
- #
69
+ #
70
70
  # Removes a configured device.
71
- #
71
+ #
72
72
  # Example:
73
73
  #
74
74
  # device_id = Guh::Device.add("{ab73ad2f-6594-45a3-9063-8f72d365c5e5}", {familyCode: 'A'})
75
- #
75
+ #
76
76
  # Guh::Device.remove(device_id)
77
- #
77
+ #
78
78
  def self.remove(device_id)
79
79
  response = get({
80
80
  id: generate_request_id,
@@ -89,16 +89,16 @@ module Guh
89
89
  raise Guh::ResponseError, response['errorMessage']
90
90
  end
91
91
  end
92
-
92
+
93
93
  ##
94
- #
94
+ #
95
95
  # Returns current number of configured devices
96
- #
96
+ #
97
97
  # Example: Guh::Device.count_configured
98
- #
98
+ #
99
99
  def self.count
100
100
  self.all.length
101
101
  end
102
-
102
+
103
103
  end
104
104
  end
@@ -3,68 +3,68 @@ module Guh
3
3
  # This class wraps everything related to available Devices.
4
4
  #
5
5
  class DeviceClass < Base
6
-
6
+
7
7
  ##
8
- #
8
+ #
9
9
  # Returns a list of all supported Devices.
10
- #
10
+ #
11
11
  # Example:
12
- #
12
+ #
13
13
  # Guh::DeviceClass.all
14
14
  # # => a list of all supported devices
15
- #
15
+ #
16
16
  def self.all(options={})
17
17
  params = {}
18
18
  params['vendorId'] = options[:vendor_id] unless options[:vendor_id].nil?
19
-
19
+
20
20
  response = get({
21
21
  id: generate_request_id,
22
22
  method: "Devices.GetSupportedDevices",
23
23
  params: params
24
24
  })
25
-
25
+
26
26
  return response['deviceClasses']
27
27
  end
28
-
28
+
29
29
  ##
30
30
  #
31
31
  # Finds a DeviceClass with a specific ID
32
- #
33
- # Example:
34
- #
32
+ #
33
+ # Example:
34
+ #
35
35
  # Guh::DeviceClass.find("{2062d64d-3232-433c-88bc-0d33c0ba2ba6}")
36
36
  # # => a list of all supported devices of a specific vendor
37
- #
37
+ #
38
38
  def self.find(id)
39
39
  device_classes = self.all
40
-
40
+
41
41
  device_class = device_classes.detect{|dc| dc['id']==id}
42
-
42
+
43
43
  if device_class
44
44
  return device_class
45
45
  else
46
46
  raise DeviceClassNotFound, "Could not find a DeviceClass with the id #{id}"
47
47
  end
48
48
  end
49
-
49
+
50
50
  ##
51
51
  #
52
52
  def self.discover(id, options={})
53
53
  params = {deviceClassId: id}
54
54
  params['discoveryParams'] = options
55
-
55
+
56
56
  response = get({
57
57
  id: generate_request_id,
58
58
  method: "Devices.GetDiscoveredDevices",
59
59
  params: params
60
60
  })
61
-
61
+
62
62
  if response['success']
63
63
  return response['deviceDescriptors']
64
64
  else
65
65
  raise ResponseError, response['errorMessage']
66
66
  end
67
67
  end
68
-
68
+
69
69
  end
70
70
  end
data/lib/guh/event.rb CHANGED
@@ -3,7 +3,7 @@ module Guh
3
3
  # This class wraps everything related to Events.
4
4
  #
5
5
  class Event < Base
6
-
6
+
7
7
  end
8
-
9
- end
8
+
9
+ end
@@ -1,17 +1,17 @@
1
1
  module Guh
2
2
  ##
3
3
  # This class wraps everything related to EventTypes.
4
- #
4
+ #
5
5
  class EventType < Base
6
-
6
+
7
7
  ##
8
- #
8
+ #
9
9
  # Returns a list of all available EventTypes.
10
- #
10
+ #
11
11
  # Example:
12
- #
12
+ #
13
13
  # Guh::EventType.all(device_class_id)
14
- #
14
+ #
15
15
  def self.all(device_class_id)
16
16
  response = get({
17
17
  id: generate_request_id,
@@ -20,9 +20,9 @@ module Guh
20
20
  deviceClassId: device_class_id
21
21
  }
22
22
  })
23
-
23
+
24
24
  response['eventTypes']
25
25
  end
26
-
26
+
27
27
  end
28
28
  end
data/lib/guh/plugin.rb CHANGED
@@ -1,34 +1,34 @@
1
1
  module Guh
2
2
  ##
3
3
  # This class wraps everything related to Plugins.
4
- #
4
+ #
5
5
  class Plugin < Base
6
-
6
+
7
7
  ##
8
- #
8
+ #
9
9
  # Returns a list of all installed plugins.
10
- #
10
+ #
11
11
  # Example:
12
- #
12
+ #
13
13
  # Guh::Plugin.all
14
- #
14
+ #
15
15
  def self.all
16
16
  response = get({
17
17
  id: generate_request_id,
18
18
  method: "Devices.GetPlugins"
19
19
  })
20
-
20
+
21
21
  response['plugins']
22
22
  end
23
-
23
+
24
24
  ##
25
- #
25
+ #
26
26
  # Set some params on a plugin.
27
- #
27
+ #
28
28
  # Example:
29
- #
29
+ #
30
30
  # HiveRpcWrapper::Plugin.set_params("TODO get proper plugin id", {foo: "bar"})
31
- #
31
+ #
32
32
  # def self.set_config(plugin_id, params)
33
33
  # get({
34
34
  # id: generate_request_id,
@@ -39,6 +39,6 @@ module Guh
39
39
  # }
40
40
  # })
41
41
  # end
42
-
42
+
43
43
  end
44
44
  end
data/lib/guh/rule.rb CHANGED
@@ -1,58 +1,60 @@
1
1
  module Guh
2
2
  ##
3
3
  # This class wraps everything related to Rules.
4
- #
4
+ #
5
5
  class Rule < Base
6
-
6
+
7
7
  ##
8
- #
8
+ #
9
9
  # Returns a list of all Rules.
10
- #
10
+ #
11
11
  # Example:
12
- #
12
+ #
13
13
  # Guh::Rule.all
14
- #
14
+ #
15
15
  def self.all
16
16
  response = get({
17
17
  id: generate_request_id,
18
18
  method: "Rules.GetRules"
19
19
  })
20
-
21
- response['rules']
20
+
21
+ response['ruleIds']
22
22
  end
23
-
23
+
24
24
  ##
25
- #
25
+ #
26
26
  # Creates a new Rule.
27
- #
27
+ #
28
28
  # Example:
29
- #
29
+ #
30
30
  # Guh::Rule.add(event, action)
31
- #
32
- def self.add(event, actions)
31
+ #
32
+ def self.add(event_descriptor_list, actions)
33
33
  unless actions.is_a?(Array)
34
34
  actions = [actions]
35
35
  end
36
-
36
+
37
37
  get({
38
38
  id: generate_request_id,
39
39
  method: "Rules.AddRule",
40
- event: event,
41
- actions: actions
40
+ params: {
41
+ eventDescriptorList: event_descriptor_list,
42
+ actions: actions
43
+ }
42
44
  })
43
45
  end
44
-
46
+
45
47
  ##
46
- #
48
+ #
47
49
  # Removes a Rule.
48
- #
50
+ #
49
51
  # Example:
50
- #
52
+ #
51
53
  # Guh::Rule.remove(rule_id)
52
- #
54
+ #
53
55
  def self.remove(rule_id)
54
-
56
+
55
57
  end
56
-
58
+
57
59
  end
58
60
  end
data/lib/guh/vendor.rb CHANGED
@@ -1,25 +1,25 @@
1
1
  module Guh
2
2
  ##
3
3
  # This class wraps everything related to Vendors.
4
- #
4
+ #
5
5
  class Vendor < Base
6
-
6
+
7
7
  ##
8
- #
8
+ #
9
9
  # Retrieves a list of all supported vendors
10
- #
10
+ #
11
11
  # Example:
12
- #
12
+ #
13
13
  # Guh::Vendor.all
14
- #
14
+ #
15
15
  def self.all
16
16
  response = get({
17
17
  id: generate_request_id,
18
18
  method: "Devices.GetSupportedVendors"
19
19
  })
20
-
20
+
21
21
  return response['vendors']
22
22
  end
23
-
23
+
24
24
  end
25
25
  end
data/lib/guh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Guh
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/guh.rb CHANGED
@@ -16,9 +16,9 @@ require "guh/vendor"
16
16
 
17
17
  module Guh
18
18
  # Your code goes here...
19
-
19
+
20
20
  class ConnectionError < Exception; end
21
21
  class ResponseError < Exception; end
22
22
  class ArgumentError < Exception; end
23
-
23
+
24
24
  end
data/spec/helper.rb CHANGED
@@ -3,29 +3,43 @@ require 'rspec'
3
3
 
4
4
  require 'guh'
5
5
 
6
- puts "\n\n---------------------------------------------------"
7
- puts "Please make sure that Guh is running"
8
- puts "---------------------------------------------------\n\n"
6
+ TEST_HOME = File.expand_path('../tmp/test_home')
9
7
 
10
8
  RSpec.configure do |config|
9
+
11
10
  config.before(:all) do
12
11
  Guh::Base.configure do |c|
13
12
  c.guh_ip_address = "127.0.0.1"
14
13
  c.guh_port = 1234
15
14
  end
16
-
15
+
17
16
  # Remove all devices & rules from Guh Core
18
17
  purge_configuration()
18
+
19
+ start_guh()
20
+ sleep(1)
21
+ end
22
+
23
+ config.after(:all) do
24
+ stop_guh()
19
25
  end
20
26
  end
21
27
 
28
+ def start_guh
29
+ @guh_pipe = IO.popen("export HOME=#{TEST_HOME}; guh 2>&1")
30
+ end
31
+
32
+ def stop_guh
33
+ Process.kill 'INT', @guh_pipe.pid
34
+ end
35
+
22
36
  def purge_devices
23
- path = File.expand_path('~/.config/guh/guh.conf')
37
+ path = File.join(TEST_HOME, '.config/guh/guh.conf')
24
38
  File.unlink(path) if File.exist?(path)
25
39
  end
26
40
 
27
41
  def purge_rules
28
- path = File.expand_path('~/.config/guh/rules.conf')
42
+ path = File.join(TEST_HOME, '.config/guh/rules.conf')
29
43
  File.unlink(path) if File.exist?(path)
30
44
  end
31
45
 
@@ -45,7 +59,7 @@ end
45
59
  def create_configured_device(device_class_id, params)
46
60
  # Create a device
47
61
  device_id = Guh::Device.add(device_class_id, params)
48
-
62
+
49
63
  # Get the newly configured device
50
64
  return Guh::Device.all.detect{|d| d['id']==device_id}
51
65
  end
@@ -1,42 +1,42 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::Action do
4
-
4
+
5
5
  before :all do
6
6
  # Elro Switch
7
7
  device_class_id = "{308ae6e6-38b3-4b3a-a513-3199da2764f8}"
8
-
9
- @device = create_configured_device(device_class_id, {
10
- channel1: true,
11
- channel2: false,
12
- channel3: false,
13
- channel4: false,
14
- channel5: false,
15
- channel6: false,
16
- channel7: false,
17
- channel8: false,
18
- channel9: false,
19
- channel10: false
20
- })
21
-
8
+
9
+ @device = create_configured_device(device_class_id, [
10
+ {name: 'channel1', value: true},
11
+ {name: 'channel2', value: false},
12
+ {name: 'channel3', value: false},
13
+ {name: 'channel4', value: false},
14
+ {name: 'channel5', value: false},
15
+ {name: 'A', value: false},
16
+ {name: 'B', value: false},
17
+ {name: 'C', value: false},
18
+ {name: 'D', value: false},
19
+ {name: 'E', value: false}
20
+ ])
21
+
22
22
  # Get all the possible actions for the device
23
23
  actions = Guh::ActionType.all(device_class_id)
24
-
24
+
25
25
  # Just use the first action
26
26
  @action = actions.first
27
27
  end
28
-
28
+
29
29
  it "should execute a single action" do
30
30
  -> {
31
- response = Guh::Action.execute(@device['id'], @action['id'], {power: true})
31
+ response = Guh::Action.execute(@device['id'], @action['id'], [{name: 'power', value: true}])
32
32
  }.should_not raise_error
33
33
  end
34
-
34
+
35
35
  it 'should fail if the wrong params are provided' do
36
-
36
+
37
37
  -> {
38
- response = Guh::Action.execute(@device['id'], @action['id'], {})
38
+ response = Guh::Action.execute(@device['id'], @action['id'], [])
39
39
  }.should raise_error
40
40
  end
41
-
41
+
42
42
  end
@@ -1,11 +1,11 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::ActionType do
4
-
4
+
5
5
  it "should return the supported actions for a device" do
6
6
  response = Guh::ActionType.all("{308ae6e6-38b3-4b3a-a513-3199da2764f8}")
7
-
7
+
8
8
  response.should be_an_instance_of(Array)
9
9
  end
10
-
10
+
11
11
  end
@@ -1,18 +1,18 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::Device do
4
-
4
+
5
5
  it 'should raise an exception if Guh Core is not running' do
6
6
  Guh::Base.configure do |c|
7
7
  c.guh_ip_address = "0.0.0.0"
8
8
  c.guh_port = 7890 # <---- wrong port to provoke excpetion
9
9
  end
10
-
10
+
11
11
  expect { Guh::Base.introspect }.to raise_error(Errno::ECONNREFUSED)
12
12
  end
13
-
13
+
14
14
  it 'should raise an exception if Guh Core does not respond with success on connect' do
15
15
  pending("TODO: Find a way to provoke this.")
16
16
  end
17
-
18
- end
17
+
18
+ end
@@ -1,50 +1,48 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::DeviceClass do
4
-
4
+
5
5
  it "should get the supported devices" do
6
6
  response = Guh::DeviceClass.all
7
-
7
+
8
8
  response.should be_an_instance_of(Array)
9
9
  end
10
-
10
+
11
11
  it "should find a specific DeviceClass" do
12
12
  device_class_id = "{ab73ad2f-6594-45a3-9063-8f72d365c5e5}"
13
-
13
+
14
14
  -> {
15
15
  Guh::DeviceClass.find("bogus")
16
16
  }.should raise_error
17
-
17
+
18
18
  -> {
19
19
  device_class = Guh::DeviceClass.find(device_class_id)
20
20
  device_class['id'].should eq(device_class_id)
21
21
  }.should_not raise_error
22
22
  end
23
-
23
+
24
24
  it "should get the supported devices of a specific vendor" do
25
25
  response = Guh::Vendor.all
26
-
26
+
27
27
  vendor_id = response.first['id']
28
-
28
+
29
29
  devices = Guh::DeviceClass.all(vendor_id: vendor_id)
30
-
30
+
31
31
  if devices.length > 0
32
32
  devices.first['vendorId'].should eq(vendor_id)
33
33
  end
34
34
  end
35
-
35
+
36
36
  it "should discover the openweathermap" do
37
-
37
+
38
38
  device_class_id = "{985195aa-17ad-4530-88a4-cdd753d747d7}"
39
-
40
- # pending "TODO wait until issue #13 is fixed"
41
-
42
- device_descriptors = Guh::DeviceClass.discover(device_class_id, location: '')
43
-
44
- puts "--"
45
- puts device_descriptors.inspect
46
- puts "--"
47
-
39
+
40
+ pending "TODO wait until issue #13 is fixed"
41
+
42
+ # device_descriptors = Guh::DeviceClass.discover(device_class_id, [
43
+ # {name: 'location', value: ''}
44
+ # ])
45
+
48
46
  end
49
-
47
+
50
48
  end
@@ -1,64 +1,64 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::Device do
4
-
4
+
5
5
  it "should get the configured device" do
6
6
  response = Guh::Device.all
7
-
7
+
8
8
  response.should be_an_instance_of(Array)
9
9
  end
10
-
10
+
11
11
  it "should tell us the number of configured devices" do
12
12
  count = Guh::Device.count
13
-
13
+
14
14
  count.should be_a(Integer)
15
15
  end
16
-
16
+
17
17
  it "should let us configure a device" do
18
18
  configured_count = Guh::Device.count
19
-
19
+
20
20
  -> {
21
- response = Guh::Device.add("{308ae6e6-38b3-4b3a-a513-3199da2764f8}", {
22
- channel1: true,
23
- channel2: false,
24
- channel3: false,
25
- channel4: false,
26
- channel5: false,
27
- channel6: false,
28
- channel7: false,
29
- channel8: false,
30
- channel9: false,
31
- channel10: false
32
- })
21
+ response = Guh::Device.add("{308ae6e6-38b3-4b3a-a513-3199da2764f8}", [
22
+ {name: 'channel1', value: true},
23
+ {name: 'channel2', value: false},
24
+ {name: 'channel3', value: false},
25
+ {name: 'channel4', value: false},
26
+ {name: 'channel5', value: false},
27
+ {name: 'A', value: false},
28
+ {name: 'B', value: false},
29
+ {name: 'C', value: false},
30
+ {name: 'D', value: false},
31
+ {name: 'E', value: false}
32
+ ])
33
33
  }.should_not raise_error
34
-
34
+
35
35
  Guh::Device.count.should eq(configured_count+1)
36
36
  end
37
-
37
+
38
38
  it "should fail if we omit the params" do
39
39
  configured_count = Guh::Device.count
40
-
40
+
41
41
  -> {
42
42
  response = Guh::Device.add("{308ae6e6-38b3-4b3a-a513-3199da2764f8}", {})
43
43
  }.should raise_error
44
-
44
+
45
45
  Guh::Device.count.should eq(configured_count)
46
46
  end
47
-
47
+
48
48
  it "should create a new device, return its ID and remove it successfully" do
49
- device_id = Guh::Device.add("{ab73ad2f-6594-45a3-9063-8f72d365c5e5}", {familyCode: 'A'})
50
-
49
+ device_id = Guh::Device.add("{ab73ad2f-6594-45a3-9063-8f72d365c5e5}", [{name: 'familyCode', value: 'A'}])
50
+
51
51
  device_id.should match(/^\{[a-z0-9\-]+\}$/i)
52
-
52
+
53
53
  Guh::Device.remove(device_id).should be_true
54
-
54
+
55
55
  Guh::Device.find(device_id).should be_nil
56
56
  end
57
-
57
+
58
58
  it "should raise an error if we try to delete a non-existing device" do
59
59
  -> {
60
60
  Guh::Device.remove("abc").should
61
61
  }.should raise_error
62
62
  end
63
-
63
+
64
64
  end
@@ -1,17 +1,17 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::EventType do
4
-
4
+
5
5
  it "should get something back" do
6
6
  # Elro Switch
7
7
  device_class_id = "{308ae6e6-38b3-4b3a-a513-3199da2764f8}"
8
-
8
+
9
9
  # Get all the possible events for the device
10
10
  response = Guh::EventType.all(device_class_id)
11
-
11
+
12
12
  response.should be_an_instance_of(Array)
13
-
13
+
14
14
  pending "Right now we get empty responses for all events"
15
15
  end
16
-
16
+
17
17
  end
@@ -1,15 +1,15 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::Plugin do
4
-
4
+
5
5
  it "should return a list of all loaded plugins" do
6
6
  response = Guh::Plugin.all
7
-
7
+
8
8
  response.should be_an_instance_of(Array)
9
9
  end
10
-
10
+
11
11
  it "should add params to the Plugin config" do
12
12
  pending("Implement after difference between PluginConfig & PluginParams is clear")
13
13
  end
14
-
14
+
15
15
  end
@@ -1,53 +1,56 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::Rule do
4
-
4
+
5
5
  before :all do
6
6
  # Intertechno Remote
7
- @sender = create_configured_device("{ab73ad2f-6594-45a3-9063-8f72d365c5e5}", {
8
- familyCode: 'A'
9
- })
10
-
7
+ @sender = create_configured_device("{ab73ad2f-6594-45a3-9063-8f72d365c5e5}", [
8
+ {name: 'familyCode', value: 'A'}
9
+ ])
10
+
11
11
  # Intertechno Switch
12
- @receiver = create_configured_device("{324219e8-7c53-41b5-b314-c2900cd15252}", {
13
- familyCode: 'A',
14
- buttonCode: 1
15
- })
16
-
12
+ @receiver = create_configured_device("{324219e8-7c53-41b5-b314-c2900cd15252}", [
13
+ {name: 'familyCode', value: 'A'},
14
+ {name: 'buttonCode', value: 1}
15
+ ])
16
+
17
17
  end
18
-
18
+
19
19
  it "should return a list of all rules" do
20
20
  response = Guh::Rule.all
21
-
21
+
22
22
  response.should be_an_instance_of(Array)
23
23
  end
24
-
24
+
25
25
  it "should create a new rule" do
26
26
  senderDeviceClass = Guh::DeviceClass.all.detect{|d| d['id']==@sender['deviceClassId']}
27
- eventId = senderDeviceClass['events'].first['id']
28
-
27
+
28
+ eventTypeId = senderDeviceClass['eventTypes'].first['id']
29
+
29
30
  actionId = Guh::ActionType.all(@receiver['deviceClassId']).first['id']
30
-
31
+
31
32
  event = {
32
- eventTypeId: eventId,
33
+ eventTypeId: eventTypeId,
33
34
  deviceId: @sender['id'],
34
- params: {inRange: true}
35
+ params: [
36
+ {name: 'inRange', value: true}
37
+ ]
35
38
  }
36
-
39
+
37
40
  action = {
38
41
  actionTypeId: actionId,
39
42
  deviceId: @receiver['id'],
40
- params: {
41
- power: true
42
- }
43
+ params: [
44
+ {name: 'power', value: true}
45
+ ]
43
46
  }
44
-
47
+
45
48
  -> {
46
- # response = Guh::Rule.add(event, action)
49
+ response = Guh::Rule.add(event, action)
47
50
  }.should_not raise_error
48
-
51
+
49
52
  pending "TODO How do we know we were successful?"
50
-
53
+
51
54
  end
52
-
55
+
53
56
  end
@@ -1,17 +1,17 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Guh::Vendor do
4
-
4
+
5
5
  it "should return a list of available vendors" do
6
-
6
+
7
7
  response = Guh::Vendor.all
8
-
8
+
9
9
  response.length.should be > 0
10
-
10
+
11
11
  end
12
-
12
+
13
13
  it "should return information about a specific vendor" do
14
14
  pending "TODO: Implement Guh::Vendor.find('{abc}')"
15
15
  end
16
-
17
- end
16
+
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Edthofer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-16 00:00:00.000000000 Z
12
+ date: 2014-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json