Class: LMC::DeviceConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/lmc/config/device_config.rb

Overview

Represents a device config in LMC

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cloud, account, device) ⇒ DeviceConfig

def url_stringtable

['cloud-service-config', 'configdsc', 'stringtable', dscui['stringtableId']]

end



32
33
34
35
36
37
38
39
40
# File 'lib/lmc/config/device_config.rb', line 32

def initialize(cloud, , device)
  @cloud = cloud
  @account = 
  @device = device
  @response = nil
  @ticket_id = nil
  # state returns an object with each requested device id pointing to a state object.
  @state = @cloud.get(url_state, deviceIds: @device.id.to_s).body[@device.id]
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/lmc/config/device_config.rb', line 6

def state
  @state
end

Instance Method Details

#confighashObject



46
47
48
# File 'lib/lmc/config/device_config.rb', line 46

def confighash
  items.to_h
end

#configjsonObject



42
43
44
# File 'lib/lmc/config/device_config.rb', line 42

def configjson
  confighash.to_json
end

#current_device_typeObject



98
99
100
# File 'lib/lmc/config/device_config.rb', line 98

def current_device_type
  OpenStruct.new JSON.parse state['currentDeviceType']
end

#descriptive_confighashObject

Returns a hash similar to #confighash but with the OIDs replaced with more meaningful descriptions.



54
55
56
57
58
59
# File 'lib/lmc/config/device_config.rb', line 54

def descriptive_confighash
  item_map = dscui.item_by_id_map
  confighash.map { |k, v|
    [item_map[k].description, v]
  }.to_h
end

#dscuiObject



65
66
67
# File 'lib/lmc/config/device_config.rb', line 65

def dscui
  @dscui ||= DeviceDSCUi.new @device
end

#feature_mask_lower32_hexString

Returns:

  • (String)


104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/lmc/config/device_config.rb', line 104

def feature_mask_lower32_hex
  feature_mask = 0
  lower_features = current_device_type.features.select { |feature| feature < 32 }
  lower_features.each do |feature_pos|
    feature = 2**feature_pos
    feature_mask = feature_mask | feature
  end
  if feature_mask == 0
    '0x00000000'
  else
    format '%#010x', feature_mask
  end
end

#itemsObject



61
62
63
# File 'lib/lmc/config/device_config.rb', line 61

def items
  response.items
end

#lcfObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/lmc/config/device_config.rb', line 69

def lcf
  # lfc format findings:
  # group headings in {} do not matter
  # indentation does not matter
  # table oids need to be enclosed in <>
  # table cell oids need to be enclosed in () and should follow table oids

  result = ''
  result += lcf_header
  items.each do |key, value|
    if value.instance_of? String
      result += "#{key} = #{value}\n"
    elsif value.instance_of? Hash
      rows = value['rows']
      col_ids = value['colIds']
      if rows.length > 0
        result += "<#{key}>\n"
        rows.each_with_index { |row, index|
          row.each_with_index { |col, col_index|
            result += "(#{key}.#{index + 1}.#{col_ids[col_index]}) = #{col}\n"}
        }
      end
    else
      raise 'Unexpected value in config items: ' + value.class.to_s
    end
  end
  result += lcf_footer
end

#lcf_device_versionObject



118
119
120
121
122
123
# File 'lib/lmc/config/device_config.rb', line 118

def lcf_device_version
  v = 'v'
  v += "#{@device.status['fwMajor']}."
  v += "#{@device.status['fwMinor']}."
  v + format('%04d', @device.status['fwBuild'])
end

#lcf_feature_id_stringString

Gives the feature IDs as a string like this: “IDs:2,3,f”

Returns:

  • (String)


128
129
130
131
# File 'lib/lmc/config/device_config.rb', line 128

def lcf_feature_id_string
  hex_features = current_device_type.features.map { |feature| feature.to_s 16 }
  "IDs:#{hex_features.join(',')}"
end

#url_configbuilderObject



8
9
10
11
# File 'lib/lmc/config/device_config.rb', line 8

def url_configbuilder
  ['cloud-service-config', 'configbuilder', 'accounts',
   @account.id, 'devices', @device.id, 'ui']
end

#url_stateObject



24
25
26
# File 'lib/lmc/config/device_config.rb', line 24

def url_state
  %W(cloud-service-config configdevice accounts #{@account.id} state)
end

#url_ticketObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/lmc/config/device_config.rb', line 13

def url_ticket
  ['cloud-service-config',
   'configbuilder',
   'accounts',
   @account.id,
   'devices',
   @device.id,
   'tickets',
   @ticket_id]
end