mios 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.rubocop.yml +769 -0
  2. data/README.md +21 -3
  3. data/lib/mios/action.rb +25 -18
  4. data/lib/mios/category.rb +14 -0
  5. data/lib/mios/category_collection.rb +38 -0
  6. data/lib/mios/client.rb +35 -0
  7. data/lib/mios/device.rb +47 -55
  8. data/lib/mios/interface.rb +53 -37
  9. data/lib/mios/job.rb +33 -34
  10. data/lib/mios/room.rb +14 -0
  11. data/lib/mios/scene.rb +22 -0
  12. data/lib/mios/services/camera1.rb +4 -5
  13. data/lib/mios/services/dimmable_light1.rb +5 -6
  14. data/lib/mios/services/door_lock1.rb +12 -13
  15. data/lib/mios/services/energy_metering1.rb +5 -6
  16. data/lib/mios/services/generic_sensor1.rb +4 -4
  17. data/lib/mios/services/ha_device1.rb +7 -8
  18. data/lib/mios/services/humidity_sensor1.rb +4 -5
  19. data/lib/mios/services/hvac_fan_operating_mode1.rb +3 -4
  20. data/lib/mios/services/hvac_operating_state1.rb +3 -4
  21. data/lib/mios/services/hvac_user_operating_mode1.rb +3 -4
  22. data/lib/mios/services/light_sensor1.rb +4 -12
  23. data/lib/mios/services/scene_controller1.rb +4 -4
  24. data/lib/mios/services/security_sensor1.rb +11 -12
  25. data/lib/mios/services/switch_power1.rb +7 -8
  26. data/lib/mios/services/temperature_sensor1.rb +3 -4
  27. data/lib/mios/services/temperature_setpoint1_cool.rb +3 -4
  28. data/lib/mios/services/temperature_setpoint1_heat.rb +3 -4
  29. data/lib/mios/services/window_covering1.rb +5 -6
  30. data/lib/mios/services/zwave_device1.rb +3 -3
  31. data/lib/mios/services/zwave_network1.rb +3 -3
  32. data/lib/mios/type_conversion.rb +21 -0
  33. data/lib/mios/version.rb +1 -1
  34. data/lib/mios.rb +12 -6
  35. data/mios.gemspec +2 -3
  36. data/spec/integration/lights_spec.rb +17 -0
  37. data/spec/lib/mios/category_collection_spec.rb +37 -0
  38. data/spec/lib/mios/category_spec.rb +15 -0
  39. data/spec/lib/mios/client_spec.rb +28 -0
  40. data/spec/lib/mios/device_spec.rb +69 -6
  41. data/spec/lib/mios/interface_spec.rb +123 -7
  42. data/spec/lib/mios/job_spec.rb +54 -0
  43. data/spec/lib/mios/room_spec.rb +26 -0
  44. data/spec/lib/mios/scene_spec.rb +27 -0
  45. data/spec/lib/mios/services/energy_metering1_spec.rb +1 -1
  46. data/spec/lib/mios/services/hvac_fan_operating_mode1_spec.rb +1 -1
  47. data/spec/lib/mios/services/hvac_operating_state1_spec.rb +1 -1
  48. data/spec/lib/mios/services/hvac_user_operating_mode1_spec.rb +1 -1
  49. data/spec/lib/mios/services/temperature_setpoint1_cool_spec.rb +1 -1
  50. data/spec/lib/mios/services/temperature_setpoint1_heat_spec.rb +1 -1
  51. data/spec/spec_helper.rb +18 -0
  52. data/spec/support/device_data/category_filter.json +75 -0
  53. data/spec/support/device_data/data_request.json +7814 -0
  54. data/spec/support/device_data/device_attributes.json +21 -0
  55. data/spec/support/vcr_cassettes/data_request_failure.yml +28 -0
  56. data/spec/support/vcr_cassettes/run_scene.yml +28 -0
  57. data/spec/support/vcr_cassettes/turn_off_light.yml +2648 -0
  58. data/spec/support/vcr_cassettes/turn_on_light.yml +2647 -0
  59. metadata +57 -39
data/README.md CHANGED
@@ -16,6 +16,10 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install mios
18
18
 
19
+ ## Requirements
20
+
21
+ Ruby 1.9 or greater
22
+
19
23
  ## Usage
20
24
 
21
25
  MiOS works on a job queue. If you wish to change an attribute or the status of a particular device, you must submit a
@@ -29,13 +33,13 @@ occur if used improperly.
29
33
 
30
34
  ### Devices could be anything of course, assuming here the first is a switch
31
35
  switch = mios.devices[0]
32
-
36
+
33
37
  ### Turn the switch off (light switch or outlet or anything classed as a switch)
34
38
  switch.off!
35
-
39
+
36
40
  ### The job object is returned from calls that require API calls
37
41
  job = switch.on!
38
-
42
+
39
43
  ### Execute some code once the job has finished
40
44
  switch.off! { |obj|
41
45
  puts "The #{obj.name} is now off"
@@ -49,6 +53,20 @@ occur if used improperly.
49
53
  puts "This will output immediately"
50
54
  sleep(5) # Sleep to wait for the thread to finish, will clean this up later
51
55
 
56
+ ### List Defined Rooms
57
+ mios.rooms
58
+
59
+ ### List Defined Scenes
60
+ mios.scenes
61
+
62
+ ### Run a scene
63
+ mios.scenes[0].run # => 'OK'
64
+
65
+ ## Additional information
66
+
67
+ http://wiki.micasaverde.com/index.php/Category:Development
68
+ http://wiki.micasaverde.com/index.php/Luup_Requests
69
+
52
70
  ## Contributing
53
71
 
54
72
  1. Fork it
data/lib/mios/action.rb CHANGED
@@ -1,25 +1,32 @@
1
- require 'cgi'
2
-
3
1
  module MiOS
4
2
  class Action
5
- def initialize(device, service_id, action, parameters={})
6
- @device, @service_id, @action, @parameters = device, service_id, action, parameters
3
+ def initialize(interface, service_id, action, parameters = {})
4
+ @interface = interface
5
+ @service_id = service_id
6
+ @action = action
7
+ @parameters = parameters
7
8
  end
8
-
9
- def take(async=false, &block)
10
- response = MultiJson.load(@device.client.get("#{@device.base_uri}/data_request", url_params).content)
11
- # Are there ever more than one jobs from a device action?
12
- Job.new(@device, response.values.first['JobID'], async, &block)
9
+
10
+ def take(async = false, &block)
11
+ response = @interface.action(@action, @service_id, @parameters)
12
+ # Is there ever more than one job from a device action?
13
+
14
+ # Device actions return a response with a job ID. Scene actions
15
+ # do not. This is an attempt to abstract that knowledge away
16
+ # from the caller.
17
+ if has_job?(response)
18
+ Job.new(@interface, response.values.first['JobID'], async, &block)
19
+ else
20
+ yield if block_given?
21
+ end
22
+ response
13
23
  end
14
24
 
15
- def url_params
16
- {
17
- :id => 'action',
18
- :DeviceNum => @device.attributes["id"],
19
- :action => @action,
20
- :serviceId => @service_id,
21
- :output_format => :json,
22
- }.merge(@parameters)
25
+ private
26
+
27
+ def has_job?(response)
28
+ response.values.first.include? 'JobID'
23
29
  end
30
+
24
31
  end
25
- end
32
+ end
@@ -0,0 +1,14 @@
1
+ module MiOS
2
+ class Category
3
+ attr_reader :label, :ids
4
+
5
+ def initialize(label, ids)
6
+ @label = label
7
+ @ids = ids
8
+ end
9
+
10
+ def to_s
11
+ label
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ module MiOS
2
+ class CategoryCollection
3
+
4
+ def initialize(filters)
5
+ @filters = filters
6
+ @categories = @filters.each_with_object([]) do |filter, categories|
7
+ categories << Category.new(label_for(filter), category_nums_for(filter))
8
+ end
9
+ end
10
+
11
+ def all
12
+ @categories
13
+ end
14
+
15
+ def find_by_id(id)
16
+ @categories.find { |c| c.ids.include? id }
17
+ end
18
+
19
+ def find_by_label(label)
20
+ @categories.find { |c| c.label == label }
21
+ end
22
+
23
+ def to_s
24
+ @categories.to_s
25
+ end
26
+
27
+ private
28
+
29
+ def label_for(filter)
30
+ filter['Label']['text']
31
+ end
32
+
33
+ def category_nums_for(filter)
34
+ filter['categories'].map {|cat_num| cat_num.to_i }
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ module MiOS
2
+ class Client
3
+ attr_reader :base_uri
4
+
5
+ def initialize(base_uri)
6
+ @base_uri = base_uri
7
+ @client = HTTPClient.new
8
+ end
9
+
10
+ def data_request(params)
11
+ default_params = { output_format: :json }
12
+ params = default_params.merge(params)
13
+ response = @client.get("#{@base_uri}/data_request", params)
14
+ return JSON.parse(response.content) if response.ok?
15
+ fail 'Device not available'
16
+ end
17
+
18
+ def device_status(device_id)
19
+ result = data_request(id: 'status', DeviceNum: device_id)
20
+ result["Device_Num_#{device_id}"]
21
+ end
22
+
23
+ def action(action, service_id, params = {})
24
+ data_request({
25
+ id: 'action',
26
+ action: action,
27
+ serviceId: service_id,
28
+ }.merge(params))
29
+ end
30
+
31
+ def job_status(job_id)
32
+ data_request(id: 'jobstatus', job: job_id, plugin: 'zwave')['status']
33
+ end
34
+ end
35
+ end
data/lib/mios/device.rb CHANGED
@@ -1,88 +1,80 @@
1
1
  module MiOS
2
2
  class Device
3
- attr_reader :attributes, :client, :base_uri
3
+ attr_reader :interface, :category
4
4
 
5
- def initialize(client, base_uri, data)
6
- @client, @base_uri = client, base_uri
7
- parse(data)
8
- end
9
-
10
- def inspect
11
- "#<MiOS::Device:0x#{'%x' % (self.object_id << 1)} name=#{@attributes['name']}>"
5
+ def initialize(interface, status_info)
6
+ @interface = interface
7
+ @status_info = status_info
8
+ initialize_services!
12
9
  end
13
10
 
14
11
  def method_missing(method, *args)
15
- if @attributes.has_key?(method.to_s)
16
- @attributes[method.to_s]
17
- else
18
- super
19
- end
12
+ attributes[method.to_s] || super
20
13
  end
21
14
 
22
15
  def reload
23
- parse(MultiJson.load(@client.get("#{@base_uri}/data_request", {:id => 'status', :DeviceNum => attributes['id'], :output_format => :json}).content)["Device_Num_#{attributes['id']}"], true)
24
-
16
+ @status_info = @interface.device_status(id)
25
17
  self
26
18
  end
27
-
28
- private
29
-
30
- def set(urn, action, params, async=false, &block)
31
- MiOS::Action.new(self, urn, action, params).take(async, &block)
19
+
20
+ def attributes
21
+ @attributes ||= @status_info.select do |key, val|
22
+ !val.kind_of?(Hash) && !val.kind_of?(Array)
23
+ end
32
24
  end
33
-
34
- def timestamp_for(urn, key)
35
- Time.at integer_for(urn, key)
25
+
26
+ def states
27
+ @status_info['states']
36
28
  end
37
-
38
- def boolean_for(urn, key)
39
- integer_for(urn, key) == 1
29
+
30
+ def category
31
+ @category ||= @interface.categories.find_by_id(category_num)
40
32
  end
41
-
42
- def integer_for(urn, key)
43
- value_for(urn, key).to_i
33
+
34
+ def room
35
+ @room ||= @interface.rooms.find { |r| r.id == attributes['room'].to_i }
44
36
  end
45
37
 
46
- def float_for(urn, key)
47
- value_for(urn, key).to_f
38
+ private
39
+
40
+ def category_num
41
+ attributes['category_num'] || 0
48
42
  end
49
43
 
50
- def time_for(urn, key)
51
- Time.at(value_for(urn, key).to_i)
44
+ def set(urn, action, params, async = false, &block)
45
+ params.merge!('DeviceNum' => id)
46
+ Action.new(interface, urn, action, params).take(async) do
47
+ yield reload if block_given?
48
+ end
52
49
  end
53
50
 
54
- def value_for(urn, key)
55
- @states.each do |state_hash|
56
- if state_hash['service'] == urn
57
- if state_hash['variable'] == key
58
- return state_hash['value']
51
+ def value_for(urn, key, type = { as: nil })
52
+ states.each do |state|
53
+ if state['service'] == urn
54
+ if state['variable'] == key
55
+ return MiOS.cast(state['value'], type[:as])
59
56
  end
60
57
  end
61
58
  end
62
-
63
59
  nil
64
60
  end
65
-
66
- def parse(data, skip_attributes=false)
67
61
 
68
- @attributes = Hash[
69
- data.select { |k, v|
70
- !data[k].kind_of?(Hash) and !data[k].kind_of?(Array)
71
- }.to_a
72
- ] unless skip_attributes
73
- @states = data['states']
74
- @states.map { |state|
75
- state['service'].split(":").last
76
- }.uniq.each { |service|
77
- service.gsub!(/[^a-zA-Z0-9]/, '')
62
+ def services
63
+ states.map { |state|
64
+ state['service'].split(':').last.gsub(/[^a-zA-Z0-9]/, '')
65
+ }.uniq
66
+ end
67
+
68
+ def initialize_services!
69
+ services.each do |service|
78
70
  if MiOS::Services.const_defined?(service)
79
71
  extend MiOS::Services.const_get(service)
80
72
  else
81
73
  $stderr.puts "WARNING: #{service} not yet supported"
82
74
  end
83
- }
84
-
85
- true
75
+ end
76
+ nil
86
77
  end
78
+
87
79
  end
88
- end
80
+ end
@@ -1,55 +1,71 @@
1
1
  module MiOS
2
+
2
3
  class Interface
3
- attr_reader :attributes, :base_uri
4
+ extend Forwardable
5
+
6
+ def_delegator :@client, :device_status
7
+ def_delegator :@client, :action
8
+ def_delegator :@client, :job_status
4
9
 
5
10
  def initialize(base_uri)
6
- @base_uri = base_uri
7
- @client = HTTPClient.new
8
- refresh!
11
+ @client = Client.new(base_uri)
12
+ end
13
+
14
+ def refresh!
15
+ @raw_data, @devices, @attributes, @categories, @rooms, @scenes = nil
16
+ end
17
+
18
+ def categories
19
+ @categories ||= CategoryCollection.new(raw_data['category_filter'])
20
+ end
21
+
22
+ def devices
23
+ @devices ||= raw_data['devices'].collect { |d| Device.new(self, d) }
24
+ end
25
+
26
+ def devices_for_label(label)
27
+ devices.select { |device| device.category && device.category.label == label }
28
+ end
29
+
30
+ def rooms
31
+ @rooms ||= raw_data['rooms'].collect { |r| Room.new(r['id'], r['name']) }
32
+ end
33
+
34
+ def scenes
35
+ @scenes ||= raw_data['scenes'].collect { |s| Scene.new(self, s['id'], s['name']) }
36
+ end
37
+
38
+ def device_names
39
+ devices.map(&:name)
40
+ end
41
+
42
+ def attributes
43
+ @attributes ||= load_attributes
9
44
  end
10
45
 
11
46
  def method_missing(method, *args)
12
- if @attributes.has_key?(method.to_s)
13
- @attributes[method.to_s]
14
- else
15
- super
16
- end
47
+ attributes[method.to_s] || super
17
48
  end
18
49
 
19
- def inspect
20
- "#<MiOS::Interface:0x#{'%x' % (self.object_id << 1)} @base_uri=#{@base_uri} @attributes=#{@attributes.inspect}>"
50
+ private
51
+
52
+ def raw_data
53
+ @raw_data ||= @client.data_request(id: 'user_data')
21
54
  end
22
55
 
23
- def refresh!
24
- data = MultiJson.load(@client.get("#{base_uri}/data_request", {:id => "user_data", :output_format => :json}).content)
25
- @attributes = Hash[
26
- data.select { |k, v|
27
- !data[k].kind_of?(Hash) and !data[k].kind_of?(Array)
28
- }.map { |k, v|
29
- [k.downcase, v]
30
- }
56
+ def load_attributes
57
+ attributes = Hash[
58
+ raw_data
59
+ .select { |k, v| !raw_data[k].kind_of?(Hash) && !raw_data[k].kind_of?(Array) }
60
+ .map { |k, v| [k.downcase, v] }
31
61
  ]
62
+
32
63
  # Convert some time objects
33
64
  ['loadtime', 'devicesync'].each do |attr|
34
- @attributes[attr] = Time.at(@attributes[attr].to_i)
65
+ attributes[attr] = MiOS.cast(attributes[attr], as: Time)
35
66
  end
36
- @devices = Hash[
37
- data['devices'].map { |device|
38
- [device['id'], Device.new(@client, @base_uri, device)]
39
- }
40
- ]
41
67
 
42
- true
68
+ attributes
43
69
  end
44
-
45
- def categories
46
- @devices.values.map { |device|
47
- device.category
48
- }.uniq.sort
49
- end
50
-
51
- def devices; @devices.values; end
52
-
53
- def device_names; devices.map(&:name); end
54
70
  end
55
- end
71
+ end
data/lib/mios/job.rb CHANGED
@@ -8,23 +8,32 @@ module MiOS
8
8
  class JobRequeue < StandardError; end
9
9
  class JobTimeout < StandardError; end
10
10
  end
11
-
11
+
12
12
  class Job
13
- Status = {
14
- -1 => "Nonexistent",
15
- 0 => "Waiting",
16
- 1 => "In progress",
17
- 2 => "Error",
18
- 3 => "Aborted",
19
- 4 => "Completed",
20
- 5 => "Waiting for callback",
21
- 6 => "Requeue",
22
- 7 => "In progress with pending data"
13
+ STATUS = {
14
+ -1 => 'Nonexistent',
15
+ 0 => 'Waiting',
16
+ 1 => 'In progress',
17
+ 2 => 'Error',
18
+ 3 => 'Aborted',
19
+ 4 => 'Completed',
20
+ 5 => 'Waiting for callback',
21
+ 6 => 'Requeue',
22
+ 7 => 'In progress with pending data'
23
23
  }
24
+
25
+ # Define a query method for each status (eg. waiting?, in_progress?)
26
+ STATUS.each do |status_id, method_name|
27
+ define_method("#{method_name.downcase.gsub(' ', '_')}?") do
28
+ status == status_id
29
+ end
30
+ end
31
+
24
32
  attr_reader :id
25
33
 
26
- def initialize(obj, id, async=false, &block)
27
- @obj, @id = obj, id
34
+ def initialize(interface, id, async = false, &block)
35
+ @interface = interface
36
+ @id = id
28
37
  reload_status!
29
38
 
30
39
  if block_given?
@@ -39,41 +48,31 @@ module MiOS
39
48
  end
40
49
 
41
50
  def when_complete(&block)
42
- raise Error::JobTimeout if !exists?
51
+ raise Error::JobTimeout if nonexistent?
43
52
  Timeout::timeout(20) do
44
53
  sleep_interval = 0.25
45
-
54
+
46
55
  # If the job is still processing, wait a bit and try again
47
56
  while waiting? || in_progress? || waiting_for_callback? || in_progress_with_pending_data? do
48
57
  sleep(sleep_interval += 0.25)
49
58
  reload_status!
50
59
  end
51
- raise JobError if error?
52
- raise JobAborted if aborted?
53
- raise JobRequeue if requeue?
60
+ raise Error::JobError if error?
61
+ raise Error::JobAborted if aborted?
62
+ raise Error::JobRequeue if requeue?
54
63
  end
55
- yield @obj.reload
64
+ yield
56
65
  rescue Timeout::Error
57
- $stderr.puts "Timed out waiting for job status to become complete"
66
+ $stderr.puts 'Timed out waiting for job status to become complete'
58
67
  raise Error::JobTimeout
59
68
  end
60
-
61
- def exists?; status != -1; end
62
- def waiting?; status == 0; end
63
- def in_progress?; status == 1; end
64
- def error?; status == 2; end
65
- def aborted?; status == 3; end
66
- def completed?; status == 4; end
67
- def waiting_for_callback?; status == 5; end
68
- def requeue?; status == 6; end
69
- def in_progress_with_pending_data?; status == 7; end
70
-
69
+
71
70
  def status
72
71
  @status || reload_status!
73
72
  end
74
-
73
+
75
74
  def reload_status!
76
- @status = MultiJson.load(@obj.client.get("#{@obj.base_uri}/data_request", {:id => 'jobstatus', :job => @id, :plugin => 'zwave', :output_format => :json}).content)['status']
75
+ @status = @interface.job_status(@id)
77
76
  end
78
77
  end
79
- end
78
+ end
data/lib/mios/room.rb ADDED
@@ -0,0 +1,14 @@
1
+ module MiOS
2
+ class Room
3
+ attr_reader :id, :name
4
+
5
+ def initialize(id, name)
6
+ @id = id.to_i
7
+ @name = name
8
+ end
9
+
10
+ def to_s
11
+ name
12
+ end
13
+ end
14
+ end
data/lib/mios/scene.rb ADDED
@@ -0,0 +1,22 @@
1
+ module MiOS
2
+ class Scene
3
+ attr_reader :id, :name
4
+
5
+ def initialize(interface, id, name)
6
+ @interface = interface
7
+ @id = id.to_i
8
+ @name = name
9
+ end
10
+
11
+ def to_s
12
+ name
13
+ end
14
+
15
+ def run
16
+ response = Action.new(@interface,
17
+ 'urn:micasaverde-com:serviceId:HomeAutomationGateway1',
18
+ 'RunScene', 'SceneNum' => @id).take
19
+ response.values.first.values.first
20
+ end
21
+ end
22
+ end
@@ -1,12 +1,11 @@
1
1
  module MiOS
2
2
  module Services
3
3
  module Camera1
4
- def self.extended(base)
5
- base.instance_variable_set("@camera1_urn", "urn:micasaverde-com:serviceId:Camera1")
6
- end
7
-
4
+
5
+ URN = 'urn:micasaverde-com:serviceId:Camera1'
6
+
8
7
  def url
9
- value_for(@camera1_urn, 'URL')
8
+ value_for(URN, 'URL')
10
9
  end
11
10
 
12
11
  def full_url
@@ -1,19 +1,18 @@
1
1
  module MiOS
2
2
  module Services
3
3
  module Dimming1
4
- def self.extended(base)
5
- base.instance_variable_set("@dimming1_urn", "urn:upnp-org:serviceId:Dimming1")
6
- end
4
+
5
+ URN = 'urn:upnp-org:serviceId:Dimming1'
7
6
 
8
7
  def level
9
- integer_for(@dimming1_urn, 'LoadLevelStatus')
8
+ value_for(URN, 'LoadLevelStatus', as: Integer)
10
9
  end
11
-
10
+
12
11
  def set_level!(new_level, async=false, &block)
13
12
  new_level = new_load_level.to_i
14
13
  new_level = 100 if new_load_level > 100
15
14
  new_level = 0 if new_load_level < 0
16
- set(@dimming1_urn, "SetLoadLevelTarget", {"newLoadlevelTarget" => new_level}, async, &block)
15
+ set(URN, 'SetLoadLevelTarget', { "newLoadlevelTarget" => new_level }, async, &block)
17
16
  end
18
17
  end
19
18
  end
@@ -1,20 +1,19 @@
1
1
  module MiOS
2
2
  module Services
3
3
  module DoorLock1
4
- def self.extended(base)
5
- base.instance_variable_set("@doorlock1_urn", "urn:micasaverde-com:serviceId:DoorLock1")
6
- end
4
+
5
+ URN = 'urn:micasaverde-com:serviceId:DoorLock1'
7
6
 
8
7
  def min_pin_size
9
- integer_for(@doorlock1_urn, 'MinPinSize')
8
+ value_for URN, 'MinPinSize', as: Integer
10
9
  end
11
10
 
12
11
  def max_pin_size
13
- integer_for(@doorlock1_urn, 'MaxPinSize')
12
+ value_for URN, 'MaxPinSize', as: Integer
14
13
  end
15
14
 
16
15
  def locked?
17
- boolean_for(@doorlock1_urn, 'Status')
16
+ value_for URN, 'Status', as: Boolean
18
17
  end
19
18
 
20
19
  def unlocked?
@@ -22,24 +21,24 @@ module MiOS
22
21
  end
23
22
 
24
23
  def pincodes
25
- tmp = value_for(@doorlock1_urn, 'PinCodes')
24
+ tmp = value_for(URN, 'PinCodes')
26
25
  tmp.gsub!(/^<[^>]+>/, '').split("\t")
27
26
  end
28
-
27
+
29
28
  def lock!(async=false, &block)
30
- set(@doorlock1_urn, "SetTarget", {"newTargetValue" => 1}, async, &block)
29
+ set(URN, 'SetTarget', { "newTargetValue" => 1 }, async, &block)
31
30
  end
32
31
 
33
32
  def unlock!(async=false, &block)
34
- set(@doorlock1_urn, "SetTarget", {"newTargetValue" => 0}, async, &block)
33
+ set(URN, 'SetTarget', { "newTargetValue" => 0 }, async, &block)
35
34
  end
36
-
35
+
37
36
  def set_pin(name, pin, index, async=false, &block)
38
- set(@doorlock1_urn, "SetPin", {"UserCodeName" => name, "newPin" => pin, "user" => index}, async, &block)
37
+ set(URN, 'SetPin', { "UserCodeName" => name, "newPin" => pin, "user" => index }, async, &block)
39
38
  end
40
39
 
41
40
  def clear_pin(index, async=false, &block)
42
- set(@doorlock1_urn, "ClearPin", {"UserCode" => index}, async, &block)
41
+ set(URN, 'ClearPin', { "UserCode" => index }, async, &block)
43
42
  end
44
43
  end
45
44
  end