ten_hs_server 0.1.3 → 0.2.0

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/lib/ten_hs_server.rb CHANGED
@@ -1,8 +1,35 @@
1
+ # This is a ruby wrapper around the tenHsServer Homeseer API
2
+ #
3
+ # Author: Espen Høgbakk
4
+ # Email: espen@hogbakk.no
5
+
1
6
  require "ten_hs_server/version"
2
7
 
3
8
  module TenHsServer
9
+ def self.new host
10
+ @host = host
11
+ self
12
+ end
13
+
14
+ def self.host
15
+ @host
16
+ end
17
+
4
18
  autoload :Adapter, "ten_hs_server/adapter"
5
19
  autoload :Device, "ten_hs_server/device"
6
20
  autoload :Event, "ten_hs_server/event"
7
21
  autoload :Room, "ten_hs_server/room"
22
+
23
+ def self.event
24
+ return TenHsServer::Event
25
+ end
26
+
27
+ def self.device
28
+ return TenHsServer::Device
29
+ end
30
+
31
+ def self.room
32
+ return TenHsServer::Room
33
+ end
34
+
8
35
  end
@@ -8,7 +8,7 @@ module TenHsServer
8
8
  class Adapter
9
9
  include HTTParty
10
10
 
11
- base_uri "10.0.0.71/tenHsServer/tenHsServer.aspx"
11
+ base_uri "#{TenHsServer.host}/tenHsServer/tenHsServer.aspx"
12
12
 
13
13
  private
14
14
 
@@ -1,3 +1,3 @@
1
1
  module TenHsServer
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,6 +3,8 @@ require "active_support/all"
3
3
  require 'ten_hs_server'
4
4
 
5
5
  class DeviceTest < ActiveSupport::TestCase
6
+ client = TenHsServer.new '10.0.0.71'
7
+
6
8
  test "should load all devices" do
7
9
  TenHsServer::Device.expects(:get).with(
8
10
  "?t=99&f=GetDevices",
@@ -10,7 +12,7 @@ class DeviceTest < ActiveSupport::TestCase
10
12
  stub body: fixture("devices_result.html")
11
13
  )
12
14
 
13
- devices = TenHsServer::Device.all
15
+ devices = client.device.all
14
16
 
15
17
  assert_equal 13, devices.count
16
18
  end
@@ -22,7 +24,7 @@ class DeviceTest < ActiveSupport::TestCase
22
24
  stub body: fixture("device_result.html")
23
25
  )
24
26
 
25
- device = TenHsServer::Device.new "Q12"
27
+ device = client.device.new "Q12"
26
28
  assert_equal "Chandelier", device.name
27
29
  end
28
30
 
@@ -33,7 +35,7 @@ class DeviceTest < ActiveSupport::TestCase
33
35
  stub body: fixture("insteon_device_result.html")
34
36
  )
35
37
 
36
- device = TenHsServer::Device.new "\\15"
38
+ device = client.device.new "\\15"
37
39
  assert_equal "Chandelier", device.name
38
40
  end
39
41
 
@@ -44,7 +46,7 @@ class DeviceTest < ActiveSupport::TestCase
44
46
  stub body: fixture("toggle_device_result.html")
45
47
  )
46
48
 
47
- device = TenHsServer::Device.new "Q12"
49
+ device = client.device.new "Q12"
48
50
  assert_equal 2, device.toggle[:status]
49
51
  end
50
52
 
@@ -55,7 +57,7 @@ class DeviceTest < ActiveSupport::TestCase
55
57
  stub body: fixture("device_on_result.html")
56
58
  )
57
59
 
58
- device = TenHsServer::Device.new "Q12"
60
+ device = client.device.new "Q12"
59
61
  assert_equal 2, device.on[:status]
60
62
  end
61
63
 
@@ -66,7 +68,7 @@ class DeviceTest < ActiveSupport::TestCase
66
68
  stub body: fixture("device_off_result.html")
67
69
  )
68
70
 
69
- device = TenHsServer::Device.new "Q12"
71
+ device = client.device.new "Q12"
70
72
  assert_equal 3, device.off[:status]
71
73
  end
72
74
 
@@ -82,7 +84,7 @@ class DeviceTest < ActiveSupport::TestCase
82
84
  stub body: fixture("set_device_value_result.html")
83
85
  )
84
86
 
85
- device = TenHsServer::Device.new "Q12"
87
+ device = client.device.new "Q12"
86
88
  assert_equal 70, device.dim(70)
87
89
  end
88
90
 
@@ -93,7 +95,7 @@ class DeviceTest < ActiveSupport::TestCase
93
95
  stub body: fixture("device_result.html")
94
96
  )
95
97
 
96
- device = TenHsServer::Device.new "Q12"
98
+ device = client.device.new "Q12"
97
99
  assert_equal false, device.on?
98
100
  assert_equal true, device.off?
99
101
  end
@@ -3,6 +3,8 @@ require "active_support/all"
3
3
  require 'ten_hs_server'
4
4
 
5
5
  class EventTest < ActiveSupport::TestCase
6
+ client = TenHsServer.new '10.0.0.71'
7
+
6
8
  test "should load all events" do
7
9
  TenHsServer::Event.expects(:get).with(
8
10
  "?t=99&f=GetEvents",
@@ -10,7 +12,7 @@ class EventTest < ActiveSupport::TestCase
10
12
  stub body: fixture("events_result.html")
11
13
  )
12
14
 
13
- events = TenHsServer::Event.all
15
+ events = client.event.all
14
16
 
15
17
  assert_equal 8, events.count
16
18
  end
@@ -22,7 +24,7 @@ class EventTest < ActiveSupport::TestCase
22
24
  stub body: fixture("events_result.html")
23
25
  )
24
26
 
25
- event = TenHsServer::Event.find "All on"
27
+ event = client.event.find "All on"
26
28
  assert_equal "All on", event
27
29
  end
28
30
 
@@ -33,7 +35,7 @@ class EventTest < ActiveSupport::TestCase
33
35
  stub body: fixture("runevent_result.html")
34
36
  )
35
37
 
36
- status = TenHsServer::Event.run "All on"
38
+ status = client.event.run "All on"
37
39
  assert_equal true, status
38
40
  end
39
41
 
@@ -3,6 +3,8 @@ require "active_support/all"
3
3
  require 'ten_hs_server'
4
4
 
5
5
  class RoomTest < ActiveSupport::TestCase
6
+ client = TenHsServer.new '10.0.0.71'
7
+
6
8
  test "should load all rooms" do
7
9
  TenHsServer::Device.expects(:get).with(
8
10
  "?t=99&f=GetDevices",
@@ -10,7 +12,7 @@ class RoomTest < ActiveSupport::TestCase
10
12
  stub body: fixture("devices_result.html")
11
13
  )
12
14
 
13
- rooms = TenHsServer::Room.all
15
+ rooms = client.room.all
14
16
 
15
17
  assert_equal 5, rooms.count
16
18
  end
@@ -22,7 +24,7 @@ class RoomTest < ActiveSupport::TestCase
22
24
  stub body: fixture("devices_result.html")
23
25
  )
24
26
 
25
- room = TenHsServer::Room.new "Dining room"
27
+ room = client.room.new "Dining room"
26
28
  assert_equal "Dining room", room.name
27
29
  assert_equal 2, room.devices.count
28
30
  end
@@ -34,7 +36,7 @@ class RoomTest < ActiveSupport::TestCase
34
36
  stub body: fixture("devices_result.html")
35
37
  )
36
38
 
37
- room = TenHsServer::Room.new "Foobar"
39
+ room = client.room.new "Foobar"
38
40
  assert_equal nil, room.floor
39
41
  end
40
42
 
@@ -50,7 +52,7 @@ class RoomTest < ActiveSupport::TestCase
50
52
  stub body: fixture("dining_room_on_result.html")
51
53
  )
52
54
 
53
- room = TenHsServer::Room.new "Dining room"
55
+ room = client.room.new "Dining room"
54
56
  assert_equal true, room.on
55
57
  end
56
58
 
@@ -66,7 +68,7 @@ class RoomTest < ActiveSupport::TestCase
66
68
  stub body: fixture("dining_room_off_result.html")
67
69
  )
68
70
 
69
- room = TenHsServer::Room.new "Dining room"
71
+ room = client.room.new "Dining room"
70
72
  assert_equal true, room.off
71
73
  end
72
74
 
@@ -2,8 +2,8 @@ require 'test/unit'
2
2
  require "active_support/all"
3
3
 
4
4
  class TenHsServerTest < ActiveSupport::TestCase
5
- def test_example
6
- assert_equal "foo",
7
- "foo"
8
- end
5
+ test "initializing the client" do
6
+ client = TenHsServer.new '10.0.0.71'
7
+ assert_equal "10.0.0.71", client.host
8
+ end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ten_hs_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: