Class: RubyHome::CharacteristicFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/factories/characteristic_factory.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(characteristic_name, service:, subtype: 'default', value: nil) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/ruby_home/factories/characteristic_factory.rb', line 3

def self.create(characteristic_name, service: , subtype: 'default' , value: nil)
  new(
    characteristic_name: characteristic_name,
    service: service,
    subtype: subtype,
    value: value
  ).create
end

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_home/factories/characteristic_factory.rb', line 12

def create
  characteristic = Characteristic.new(
    description: template.description,
    format: template.format,
    name: characteristic_name,
    properties: template.properties,
    constraints: template.constraints,
    service: service,
    unit: template.unit,
    uuid: template.uuid,
    value_object: value_object
  )

  if persisted_characteristic
    characteristic.instance_id = persisted_characteristic.instance_id
  else
    characteristic.instance_id = accessory.next_available_instance_id
    persist_characteristic(characteristic)
  end

  service.characteristics << characteristic

  characteristic
end