Module: RubyHome::DeviceID

Defined in:
lib/ruby_home/device_id.rb

Constant Summary collapse

DELIMITER =
':'

Class Method Summary collapse

Class Method Details

.generate(digits = 12) ⇒ Object

Device ID of the accessory must be a unique random number generated at every factory reset and must persist across reboots



9
10
11
12
13
14
15
# File 'lib/ruby_home/device_id.rb', line 9

def generate(digits=12)
  random_hexadecimals(digits)
    .map(&:upcase)
    .each_slice(2)
    .map(&:join)
    .join(DELIMITER)
end

.random_hexadecimalObject



17
18
19
# File 'lib/ruby_home/device_id.rb', line 17

def random_hexadecimal
  rand(15).to_s(16)
end

.random_hexadecimals(digits = 12) ⇒ Object



21
22
23
24
25
# File 'lib/ruby_home/device_id.rb', line 21

def random_hexadecimals(digits=12)
  digits
    .times
    .map { random_hexadecimal }
end