Class: Fritzbox::Smarthome::Actor

Inherits:
Resource
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/fritzbox/smarthome/actor.rb

Direct Known Subclasses

Heater, SmokeDetector, Switch

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Resource

get

Instance Attribute Details

#ainObject

Returns the value of attribute ain.



6
7
8
# File 'lib/fritzbox/smarthome/actor.rb', line 6

def ain
  @ain
end

#group_membersObject

Returns the value of attribute group_members.



6
7
8
# File 'lib/fritzbox/smarthome/actor.rb', line 6

def group_members
  @group_members
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/fritzbox/smarthome/actor.rb', line 6

def id
  @id
end

#manufacturerObject

Returns the value of attribute manufacturer.



6
7
8
# File 'lib/fritzbox/smarthome/actor.rb', line 6

def manufacturer
  @manufacturer
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/fritzbox/smarthome/actor.rb', line 6

def name
  @name
end

#presentObject

Returns the value of attribute present.



6
7
8
# File 'lib/fritzbox/smarthome/actor.rb', line 6

def present
  @present
end

#typeObject

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