Class: Zaptec::Constants

Inherits:
Object
  • Object
show all
Defined in:
lib/zaptec/constants.rb

Class Method Summary collapse

Class Method Details

.charger_operation_mode_name_to_mode(operation_mode_name) ⇒ Object



18
19
20
21
22
23
# File 'lib/zaptec/constants.rb', line 18

def charger_operation_mode_name_to_mode(operation_mode_name)
  constants
    .fetch("ChargerOperationModes")
    .detect { |name, _mode| name == operation_mode_name.to_s }
    .then { |_name, mode| mode }
end

.charger_operation_mode_to_name(operation_mode) ⇒ Object



11
12
13
14
15
16
# File 'lib/zaptec/constants.rb', line 11

def charger_operation_mode_to_name(operation_mode)
  constants
    .fetch("ChargerOperationModes")
    .detect { |_name, mode| mode == operation_mode }
    .then { |name, _mode| name }
end

.command_to_command_id(command) ⇒ Object



25
26
27
28
29
# File 'lib/zaptec/constants.rb', line 25

def command_to_command_id(command)
  constants
    .fetch("Commands")
    .fetch(command.to_s) { raise "Unknown command '#{command}'" }
end

.country_id_to_country_code(country_id) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/zaptec/constants.rb', line 31

def country_id_to_country_code(country_id)
  return if country_id.nil?

  constants
    .fetch("Countries")
    .fetch(country_id)
    .fetch("Code")
end

.network_type_to_name(network_type) ⇒ Object



40
41
42
43
44
45
# File 'lib/zaptec/constants.rb', line 40

def network_type_to_name(network_type)
  constants
    .fetch("NetworkTypes")
    .detect { |_name, type| type == network_type }
    .then { |name, _type| name }
end

.observation_state_id_to_name(state_id:, device_type:) ⇒ Object



4
5
6
7
8
9
# File 'lib/zaptec/constants.rb', line 4

def observation_state_id_to_name(state_id:, device_type:)
  device_type_observation_ids(device_type)
    .fetch(state_id)
rescue KeyError
  "Unknown state id '#{state_id}' (device type '#{device_type}')"
end