Class: Fritzbox::Smarthome::Actor
- Includes:
- ActiveModel::Model
- Defined in:
- lib/fritzbox/smarthome/actor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ain ⇒ Object
Returns the value of attribute ain.
-
#group_members ⇒ Object
Returns the value of attribute group_members.
-
#id ⇒ Object
Returns the value of attribute id.
-
#manufacturer ⇒ Object
Returns the value of attribute manufacturer.
-
#name ⇒ Object
Returns the value of attribute name.
-
#present ⇒ Object
Returns the value of attribute present.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Methods inherited from Resource
Instance Attribute Details
#ain ⇒ Object
Returns the value of attribute ain.
6 7 8 |
# File 'lib/fritzbox/smarthome/actor.rb', line 6 def ain @ain end |
#group_members ⇒ Object
Returns the value of attribute group_members.
6 7 8 |
# File 'lib/fritzbox/smarthome/actor.rb', line 6 def group_members @group_members end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/fritzbox/smarthome/actor.rb', line 6 def id @id end |
#manufacturer ⇒ Object
Returns the value of attribute manufacturer.
6 7 8 |
# File 'lib/fritzbox/smarthome/actor.rb', line 6 def manufacturer @manufacturer end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/fritzbox/smarthome/actor.rb', line 6 def name @name end |
#present ⇒ Object
Returns the value of attribute present.
6 7 8 |
# File 'lib/fritzbox/smarthome/actor.rb', line 6 def present @present end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/fritzbox/smarthome/actor.rb', line 6 def type @type end |
Class Method Details
.all(types: ['group', 'device']) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fritzbox/smarthome/actor.rb', line 16 def all(types: ['group', 'device']) response = get(command: 'getdevicelistinfos') xml = nori.parse(response.body) Array.wrap(types.map { |type| xml.dig('devicelist', type) }.flatten).compact.map do |data| klass = Actor.descendants.find { |k| k.match?(data) } self.in?([klass, Actor]) ? klass.new_from_api(data) : nil end.compact end |
.new_from_api(data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fritzbox/smarthome/actor.rb', line 25 def new_from_api(data) new( id: data.dig('@id').to_s, type: data.dig('groupinfo').present? ? :group : :device, ain: data.dig('@identifier').to_s, present: data.dig('present') == '1', name: data.dig('name').to_s, manufacturer: data.dig('manufacturer').to_s, group_members: data.dig('groupinfo', 'members').to_s.split(',').presence ) end |