Class: RubyHome::Characteristic

Inherits:
Object
  • Object
show all
Includes:
Wisper::Publisher
Defined in:
lib/ruby_home/hap/characteristic.rb

Constant Summary collapse

PROPERTIES =
{
  'cnotify' => 'ev',
  'read' => 'pr',
  'uncnotify' => nil,
  'write' => 'pw',
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid:, name:, description:, format:, unit:, properties:, service:, value: nil) ⇒ Characteristic

Returns a new instance of Characteristic.



14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_home/hap/characteristic.rb', line 14

def initialize(uuid:, name:, description:, format:, unit:, properties:, service: , value: nil)
  @uuid = uuid
  @name = name
  @description = description
  @format = format
  @unit = unit
  @properties = properties
  @service = service
  @value = value
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#instance_idObject

Returns the value of attribute instance_id.



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

def instance_id
  @instance_id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

#serviceObject (readonly)

Returns the value of attribute service.



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

def service
  @service
end

#unitObject (readonly)

Returns the value of attribute unit.



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

def unit
  @unit
end

#uuidObject (readonly)

Returns the value of attribute uuid.



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

def uuid
  @uuid
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#accessoryObject



28
29
30
# File 'lib/ruby_home/hap/characteristic.rb', line 28

def accessory
  service.accessory
end

#accessory_idObject



32
33
34
# File 'lib/ruby_home/hap/characteristic.rb', line 32

def accessory_id
  accessory.id
end

#inspectObject



45
46
47
48
49
50
51
52
53
# File 'lib/ruby_home/hap/characteristic.rb', line 45

def inspect
  {
    name: name,
    value: value,
    accessory_id: accessory_id,
    service_iid: service_iid,
    instance_id: instance_id
  }
end

#saveObject



55
56
57
58
# File 'lib/ruby_home/hap/characteristic.rb', line 55

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

#service_iidObject



36
37
38
# File 'lib/ruby_home/hap/characteristic.rb', line 36

def service_iid
  service.instance_id
end