Class: SAAL::OWSensor

Inherits:
SensorUnderlying show all
Defined in:
lib/owsensor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SensorUnderlying

writeable!, #writeable?

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_typeObject (readonly)

Returns the value of attribute sensor_type.



3
4
5
# File 'lib/owsensor.rb', line 3

def sensor_type
  @sensor_type
end

#serialObject (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