Class: RubyHome::Characteristic
- Inherits:
-
Object
- Object
- RubyHome::Characteristic
- 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
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#instance_id ⇒ Object
Returns the value of attribute instance_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #accessory ⇒ Object
- #accessory_id ⇒ Object
- #after_update(&block) ⇒ Object
-
#initialize(uuid:, name:, description:, format:, unit:, properties:, constraints:, service:, value_object:) ⇒ Characteristic
constructor
A new instance of Characteristic.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, *args) ⇒ Boolean
- #service_iid ⇒ Object
- #unsubscribe(*listeners) ⇒ Object
- #valid_values ⇒ Object
- #value ⇒ Object
- #value=(new_value) ⇒ Object
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
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
40 41 42 |
# File 'lib/ruby_home/characteristic.rb', line 40 def constraints @constraints end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
40 41 42 |
# File 'lib/ruby_home/characteristic.rb', line 40 def description @description end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
40 41 42 |
# File 'lib/ruby_home/characteristic.rb', line 40 def format @format end |
#instance_id ⇒ Object
Returns the value of attribute instance_id.
40 41 42 |
# File 'lib/ruby_home/characteristic.rb', line 40 def instance_id @instance_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
40 41 42 |
# File 'lib/ruby_home/characteristic.rb', line 40 def name @name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
40 41 42 |
# File 'lib/ruby_home/characteristic.rb', line 40 def properties @properties end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
40 41 42 |
# File 'lib/ruby_home/characteristic.rb', line 40 def service @service end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
40 41 42 |
# File 'lib/ruby_home/characteristic.rb', line 40 def unit @unit end |
#uuid ⇒ Object (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
#accessory ⇒ Object
59 60 61 |
# File 'lib/ruby_home/characteristic.rb', line 59 def accessory service.accessory end |
#accessory_id ⇒ Object
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
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_iid ⇒ Object
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_values ⇒ Object
71 72 73 |
# File 'lib/ruby_home/characteristic.rb', line 71 def valid_values constraints.fetch('ValidValues', {}).keys.map(&:to_i) end |
#value ⇒ Object
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 |