Class: RubyHome::Characteristic

Inherits:
Object
  • Object
show all
Includes:
Wisper::Publisher
Defined in:
lib/ruby_home/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_object:) ⇒ Characteristic

Returns a new instance of Characteristic.



28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_home/characteristic.rb', line 28

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



69
70
71
# File 'lib/ruby_home/characteristic.rb', line 69

def method_missing(method_name, *args, &block)
  value.send(method_name, *args, &block)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



39
40
41
# File 'lib/ruby_home/characteristic.rb', line 39

def description
  @description
end

#formatObject (readonly)

Returns the value of attribute format.



39
40
41
# File 'lib/ruby_home/characteristic.rb', line 39

def format
  @format
end

#instance_idObject

Returns the value of attribute instance_id.



39
40
41
# File 'lib/ruby_home/characteristic.rb', line 39

def instance_id
  @instance_id
end

#nameObject (readonly)

Returns the value of attribute name.



39
40
41
# File 'lib/ruby_home/characteristic.rb', line 39

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



39
40
41
# File 'lib/ruby_home/characteristic.rb', line 39

def properties
  @properties
end

#serviceObject (readonly)

Returns the value of attribute service.



39
40
41
# File 'lib/ruby_home/characteristic.rb', line 39

def service
  @service
end

#unitObject (readonly)

Returns the value of attribute unit.



39
40
41
# File 'lib/ruby_home/characteristic.rb', line 39

def unit
  @unit
end

#uuidObject (readonly)

Returns the value of attribute uuid.



39
40
41
# File 'lib/ruby_home/characteristic.rb', line 39

def uuid
  @uuid
end

Instance Method Details

#accessoryObject



57
58
59
# File 'lib/ruby_home/characteristic.rb', line 57

def accessory
  service.accessory
end

#accessory_idObject



61
62
63
# File 'lib/ruby_home/characteristic.rb', line 61

def accessory_id
  accessory.id
end

#after_update(&block) ⇒ Object



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

def after_update(&block)
  on(:after_update, &block)
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/ruby_home/characteristic.rb', line 73

def respond_to_missing?(method_name, *args)
  value.respond_to?(method_name, *args) || super
end

#service_iidObject



65
66
67
# File 'lib/ruby_home/characteristic.rb', line 65

def service_iid
  service.instance_id
end

#unsubscribe(*listeners) ⇒ Object



11
12
13
14
15
# File 'lib/ruby_home/characteristic.rb', line 11

def unsubscribe(*listeners)
  local_registrations.delete_if do |registration|
    listeners.include?(registration.listener)
  end
end

#valueObject



77
78
79
# File 'lib/ruby_home/characteristic.rb', line 77

def value
  value_object.value
end

#value=(new_value) ⇒ Object



81
82
83
84
# File 'lib/ruby_home/characteristic.rb', line 81

def value=(new_value)
  value_object.value = new_value
  broadcast(:after_update, value)
end