Class: RubyHome::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/hap/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accessory:, primary: false, hidden: false, name:, description:, uuid:) ⇒ Service

Returns a new instance of Service.



6
7
8
9
10
11
12
13
14
# File 'lib/ruby_home/hap/service.rb', line 6

def initialize(accessory: , primary: false, hidden: false, name:, description:, uuid:)
  @accessory = accessory
  @primary = primary
  @hidden = hidden
  @name = name
  @description = description
  @uuid = uuid
  @characteristics = []
end

Instance Attribute Details

#accessoryObject (readonly)

Returns the value of attribute accessory.



16
17
18
# File 'lib/ruby_home/hap/service.rb', line 16

def accessory
  @accessory
end

#characteristicsObject (readonly)

Returns the value of attribute characteristics.



16
17
18
# File 'lib/ruby_home/hap/service.rb', line 16

def characteristics
  @characteristics
end

#descriptionObject (readonly)

Returns the value of attribute description.



16
17
18
# File 'lib/ruby_home/hap/service.rb', line 16

def description
  @description
end

#hiddenObject (readonly)

Returns the value of attribute hidden.



16
17
18
# File 'lib/ruby_home/hap/service.rb', line 16

def hidden
  @hidden
end

#instance_idObject

Returns the value of attribute instance_id.



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

def instance_id
  @instance_id
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/ruby_home/hap/service.rb', line 16

def name
  @name
end

#primaryObject (readonly)

Returns the value of attribute primary.



16
17
18
# File 'lib/ruby_home/hap/service.rb', line 16

def primary
  @primary
end

#uuidObject (readonly)

Returns the value of attribute uuid.



16
17
18
# File 'lib/ruby_home/hap/service.rb', line 16

def uuid
  @uuid
end

Instance Method Details

#characteristic(characteristic_name) ⇒ Object



19
20
21
22
23
# File 'lib/ruby_home/hap/service.rb', line 19

def characteristic(characteristic_name)
  characteristics.find do |characteristic|
    characteristic.name == characteristic_name
  end
end

#inspectObject



30
31
32
33
34
35
36
# File 'lib/ruby_home/hap/service.rb', line 30

def inspect
  {
    primary: primary,
    hidden: hidden,
    characteristics: characteristics
  }
end

#saveObject



25
26
27
28
# File 'lib/ruby_home/hap/service.rb', line 25

def save
  IdentifierCache.add_accessory(accessory)
  IdentifierCache.add_service(self)
end