Class: Subaru::Definitions::Xytronix::WebRelay10

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/subaru/d-xytronix.rb

Instance Attribute Summary

Attributes included from Common

#options

Instance Method Summary collapse

Methods included from Common

#generate_query, #initialize, #send_request, #state_from_xml

Instance Method Details

#parse_xml(xml) ⇒ Hash

Parse XML document response.

Parameters:

  • xml (Object)

    XML document.

Returns:

  • (Hash)

138
139
140
141
142
143
144
145
146
147
# File 'lib/subaru/d-xytronix.rb', line 138

def parse_xml(xml)
  results = {}
  (1..10).each do |ch|
    results["relay#{ch}"] = state_from_xml(xml, 'relay', ch)
  end
  return results
rescue => e
  puts e.message
  return nil
end

#readHash

Read resources from device.

Returns:

  • (Hash)

    resources and their state.


119
120
121
# File 'lib/subaru/d-xytronix.rb', line 119

def read
  return parse_xml(send_request)
end

#write(data) ⇒ Hash

Set resource state of a device.

Parameters:

  • data (String)

    POST/PUT data.

Returns:

  • (Hash)

    resulting resources and their state.


126
127
128
129
130
131
132
133
# File 'lib/subaru/d-xytronix.rb', line 126

def write(data)
  q = generate_query(JSON.parse(data))
  return nil unless q
  return parse_xml(send_request(q))
rescue => e
  puts e.message
  return nil
end