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:, constraints:, service:, value_object:) ⇒ Characteristic

Returns a new instance of Characteristic.



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

def initialize(uuid:, name:, description:, format:, unit:, properties:, constraints:, service: , value_object: )
  @uuid = uuid
  @name = name
  @description = description
  @format = format
  @unit = unit
  @properties = properties
  @constraints = constraints
  @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



75
76
77
# File 'lib/ruby_home/characteristic.rb', line 75

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

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



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

def constraints
  @constraints
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#instance_idObject

Returns the value of attribute instance_id.



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

def instance_id
  @instance_id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

#serviceObject (readonly)

Returns the value of attribute service.



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

def service
  @service
end

#unitObject (readonly)

Returns the value of attribute unit.



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

def unit
  @unit
end

#uuidObject (readonly)

Returns the value of attribute uuid.



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

def uuid
  @uuid
end

Instance Method Details

#accessoryObject



59
60
61
# File 'lib/ruby_home/characteristic.rb', line 59

def accessory
  service.accessory
end

#accessory_idObject



63
64
65
# File 'lib/ruby_home/characteristic.rb', line 63

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)


79
80
81
# File 'lib/ruby_home/characteristic.rb', line 79

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

#service_iidObject



67
68
69
# File 'lib/ruby_home/characteristic.rb', line 67

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

#valid_valuesObject



71
72
73
# File 'lib/ruby_home/characteristic.rb', line 71

def valid_values
  constraints.fetch('ValidValues', {}).keys.map(&:to_i)
end

#valueObject



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

def value
  value_object.value
end

#value=(new_value) ⇒ Object



87
88
89
90
# File 'lib/ruby_home/characteristic.rb', line 87

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