Class: MrMurano::Product1PDevice
- Inherits:
-
ProductBase
- Object
- ProductBase
- MrMurano::Product1PDevice
- Includes:
- ProductOnePlatformRpcShim
- Defined in:
- lib/MrMurano/Product-1P-Device.rb
Instance Method Summary collapse
-
#info(sn) ⇒ Object
- Get information about a device
sn -
Identifier for a device.
- Get information about a device
-
#initialize ⇒ Product1PDevice
constructor
A new instance of Product1PDevice.
-
#list(sn) ⇒ Object
- List resources on a device
sn -
Identifier for a device.
- List resources on a device
- #listing(sn) ⇒ Object
-
#read(sn, aliases) ⇒ Object
- Read the last value for resources on a device
sn - Identifier for a device
aliases -
Array of resource names.
- Identifier for a device
- Read the last value for resources on a device
-
#remove(sn) ⇒ Object
- Completely remove an identifier from the product
sn -
Identifier for a device.
- Completely remove an identifier from the product
-
#sn_rid(sn) ⇒ Object
- Get the internal protocol identifier for a device
sn -
Identifier for a device.
- Get the internal protocol identifier for a device
-
#twee(sn) ⇒ Object
Get a tree of info for a device and its resources.
Methods included from ProductOnePlatformRpcShim
Methods inherited from ProductBase
Methods included from Verbose
#debug, #error, #outf, #tabularize, #verbose, #warning
Methods included from Http
#curldebug, #delete, #get, #http, #http_reset, #isJSON, #json_opts, #post, #postf, #put, #set_def_headers, #showHttpError, #token, #workit
Constructor Details
#initialize ⇒ Product1PDevice
Returns a new instance of Product1PDevice.
7 8 9 10 11 12 13 14 15 |
# File 'lib/MrMurano/Product-1P-Device.rb', line 7 def initialize super @uriparts << :proxy @uriparts << 'onep:v1' @uriparts << :rpc @uriparts << :process @model_rid = nil @sn_rid = nil end |
Instance Method Details
#info(sn) ⇒ Object
Get information about a device
sn-
Identifier for a device
42 43 44 45 46 47 |
# File 'lib/MrMurano/Product-1P-Device.rb', line 42 def info(sn) do_rpc({:id=>1, :procedure=>:info, :arguments=>[sn_rid(sn), {}] }, sn_rid(sn)) end |
#list(sn) ⇒ Object
List resources on a device
sn-
Identifier for a device
51 52 53 54 55 56 |
# File 'lib/MrMurano/Product-1P-Device.rb', line 51 def list(sn) data = info(sn) dt = {} data[:aliases].each{|k,v| v.each{|a| dt[a] = k.to_s}} dt end |
#listing(sn) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/MrMurano/Product-1P-Device.rb', line 58 def listing(sn) do_rpc({:id=>1, :procedure=>:listing, :arguments=>[sn_rid(sn), [:dataport], {}] }, sn_rid(sn)) end |
#read(sn, aliases) ⇒ Object
Read the last value for resources on a device
sn-
Identifier for a device
aliases-
Array of resource names
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/MrMurano/Product-1P-Device.rb', line 68 def read(sn, aliases) aliases = [aliases] unless aliases.kind_of? Array calls = aliases.map do |a| { :procedure=>:read, :arguments=>[ {:alias=>a}, {} ] } end do_mrpc(calls, sn_rid(sn)).map do |i| if i.has_key?(:result) and i[:result].count > 0 and i[:result][0].count > 1 then i[:result][0][1] else nil end end end |
#remove(sn) ⇒ Object
Completely remove an identifier from the product
sn-
Identifier for a device
87 88 89 90 91 92 93 |
# File 'lib/MrMurano/Product-1P-Device.rb', line 87 def remove(sn) # First drop it from the 1P database do_rpc({:id=>1, :procedure=>:drop, :arguments=>[sn_rid(sn)]}, nil) # Then remove it from the provisioning databases psn = ProductSerialNumber.new psn.remove_sn(sn) end |
#sn_rid(sn) ⇒ Object
Get the internal protocol identifier for a device
sn-
Identifier for a device
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/MrMurano/Product-1P-Device.rb', line 19 def sn_rid(sn) return @sn_rid unless @sn_rid.nil? prd = Product.new() found = [] offset = 0 loop do listing = prd.list(offset) break if listing.empty? found = listing.select{|item| item[:sn] == sn} break unless found.empty? offset += 50 end raise "Identifier Not Found: #{sn}" if found.empty? @sn_rid = found.first[:rid] @sn_rid end |
#twee(sn) ⇒ Object
Get a tree of info for a device and its resources.
sn-
Identifier for a device
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/MrMurano/Product-1P-Device.rb', line 97 def twee(sn) inf = info(sn) aliases = inf[:aliases].keys # information for all info_calls = aliases.map do |rid| {:procedure=>:info, :arguments=>[rid, {}]} end limitkeys = [:basic, :description, :usage, :children, :storage] isubs = do_mrpc(info_calls, sn_rid(sn)) children = isubs.map{|i| i[:result].select{|k,v| limitkeys.include? k} } # most current value read_calls = aliases.map do |rid| {:procedure=>:read, :arguments=>[rid, {}]} end ivalues = do_mrpc(read_calls, sn_rid(sn)) rez = aliases.zip(children, ivalues).map do |d| dinf = d[1] dinf[:rid] = d[0] dinf[:alias] = inf[:aliases][d[0]].first iv = d[2] if iv.has_key?(:result) and iv[:result].count > 0 and iv[:result][0].count > 1 then dinf[:value] = iv[:result][0][1] else dinf[:value] = nil end dinf end inf[:children] = rez inf.select!{|k,v| limitkeys.include? k } inf end |