Class: RubyHome::AccessoryInfo
- Inherits:
-
Object
- Object
- RubyHome::AccessoryInfo
- Defined in:
- lib/ruby_home/accessory_info.rb
Constant Summary collapse
- PERSISTABLE =
[ :device_id, :paired_clients, :password, :signature_key, :username ].freeze
- @@accessory_info =
AccessoryInfo.new(YAML::Store.new 'accessory_info.yml')
Instance Attribute Summary collapse
-
#device_id ⇒ Object
Returns the value of attribute device_id.
-
#paired_clients ⇒ Object
Returns the value of attribute paired_clients.
-
#password ⇒ Object
Returns the value of attribute password.
-
#signature_key ⇒ Object
Returns the value of attribute signature_key.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
- .add_paired_client(admin: false, identifier:, public_key:) ⇒ Object
- .paired? ⇒ Boolean
- .pstore=(new_storage) ⇒ Object
- .remove_paired_client(identifier) ⇒ Object
- .save ⇒ Object
- .signing_key ⇒ Object
Instance Method Summary collapse
-
#initialize(store) ⇒ AccessoryInfo
constructor
A new instance of AccessoryInfo.
- #read ⇒ Object
- #save ⇒ Object
- #signing_key ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(store) ⇒ AccessoryInfo
Returns a new instance of AccessoryInfo.
9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby_home/accessory_info.rb', line 9 def initialize(store) @store = store read @device_id ||= DeviceID.generate @paired_clients ||= [] @signature_key ||= Ed25519::SigningKey.generate.to_bytes.unpack1('H*') end |
Instance Attribute Details
#device_id ⇒ Object
Returns the value of attribute device_id.
20 21 22 |
# File 'lib/ruby_home/accessory_info.rb', line 20 def device_id @device_id end |
#paired_clients ⇒ Object
Returns the value of attribute paired_clients.
20 21 22 |
# File 'lib/ruby_home/accessory_info.rb', line 20 def paired_clients @paired_clients end |
#password ⇒ Object
Returns the value of attribute password.
20 21 22 |
# File 'lib/ruby_home/accessory_info.rb', line 20 def password @password end |
#signature_key ⇒ Object
Returns the value of attribute signature_key.
20 21 22 |
# File 'lib/ruby_home/accessory_info.rb', line 20 def signature_key @signature_key end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
19 20 21 |
# File 'lib/ruby_home/accessory_info.rb', line 19 def store @store end |
#username ⇒ Object
Returns the value of attribute username.
20 21 22 |
# File 'lib/ruby_home/accessory_info.rb', line 20 def username @username end |
Class Method Details
.add_paired_client(admin: false, identifier:, public_key:) ⇒ Object
88 89 90 91 |
# File 'lib/ruby_home/accessory_info.rb', line 88 def add_paired_client(admin: false, identifier: , public_key: ) @@accessory_info.paired_clients << { admin: admin, identifier: identifier, public_key: public_key } save end |
.paired? ⇒ Boolean
84 85 86 |
# File 'lib/ruby_home/accessory_info.rb', line 84 def paired? @@accessory_info.paired_clients.any? end |
.pstore=(new_storage) ⇒ Object
58 59 60 |
# File 'lib/ruby_home/accessory_info.rb', line 58 def self.pstore=(new_storage) @@accessory_info = AccessoryInfo.new(new_storage) end |
.remove_paired_client(identifier) ⇒ Object
93 94 95 96 |
# File 'lib/ruby_home/accessory_info.rb', line 93 def remove_paired_client(identifier) @@accessory_info.paired_clients.delete_if { |h| h[:identifier] == identifier } save end |
.save ⇒ Object
76 77 78 |
# File 'lib/ruby_home/accessory_info.rb', line 76 def save @@accessory_info.save end |
.signing_key ⇒ Object
80 81 82 |
# File 'lib/ruby_home/accessory_info.rb', line 80 def signing_key @@accessory_info.signing_key end |
Instance Method Details
#read ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/ruby_home/accessory_info.rb', line 44 def read store.transaction(true) do store.fetch(:accessory_info, {}).each do |key, value| send("#{key}=", value) end end end |
#save ⇒ Object
52 53 54 55 56 |
# File 'lib/ruby_home/accessory_info.rb', line 52 def save store.transaction do store[:accessory_info] = to_hash end end |
#signing_key ⇒ Object
28 29 30 |
# File 'lib/ruby_home/accessory_info.rb', line 28 def signing_key @signing_key ||= Ed25519::SigningKey.new([signature_key].pack('H*')) end |
#to_hash ⇒ Object
40 41 42 |
# File 'lib/ruby_home/accessory_info.rb', line 40 def to_hash Hash[*PERSISTABLE.flat_map { |attribute| [attribute, send(attribute)] }] end |