Class: SAAL::OWSensor
- Inherits:
-
SensorUnderlying
- Object
- SensorUnderlying
- SAAL::OWSensor
- Defined in:
- lib/owsensor.rb
Instance Attribute Summary collapse
-
#sensor_type ⇒ Object
readonly
Returns the value of attribute sensor_type.
-
#serial ⇒ Object
readonly
Returns the value of attribute serial.
Instance Method Summary collapse
-
#initialize(defs, opts = {}) ⇒ OWSensor
constructor
A new instance of OWSensor.
- #read(uncached = false) ⇒ Object
Methods inherited from SensorUnderlying
Constructor Details
#initialize(defs, opts = {}) ⇒ OWSensor
Returns a new instance of OWSensor.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/owsensor.rb', line 4 def initialize(defs, opts={}) @serial = defs['serial'] @connect_opts = {} @connect_opts[:server] = defs['server'] if defs['server'] @connect_opts[:port] = defs['port'] if defs['port'] @owconn = opts[:owconn] basename = File.basename(@serial) @sensor_type = basename.to_sym if ['pressure','temperature','humidity'].include?(basename) end |
Instance Attribute Details
#sensor_type ⇒ Object (readonly)
Returns the value of attribute sensor_type.
3 4 5 |
# File 'lib/owsensor.rb', line 3 def sensor_type @sensor_type end |
#serial ⇒ Object (readonly)
Returns the value of attribute serial.
3 4 5 |
# File 'lib/owsensor.rb', line 3 def serial @serial end |
Instance Method Details
#read(uncached = false) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/owsensor.rb', line 15 def read(uncached = false) @owconn ||= OWNet::Connection.new(@connect_opts) begin @owconn.read((uncached ? '/uncached' : '')+@serial) rescue Exception nil end end |