Class: Proliphix::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/pdp/network.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip, user, passwd) ⇒ Network

Returns a new instance of Network.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pdp/network.rb', line 11

def initialize(ip, user, passwd)
    @buffer = ""
    @debug = false
    @simulate = false
    @ip = ip
    @user = user
    @passwd = passwd
    @last = Time.now.to_i - 120
    @fetched = {}
    @sensors = [
                ThermHvacMode,
                ThermHvacState,
                ThermFanMode,
                ThermFanState,
                ThermSetbackHeat,
                ThermSetbackCool,
                ThermHeat1Usage,
                ThermCool1Usage,
                ThermFanUsage,
                ThermAverageTemp,
                ThermSystemTimeSecs,
                ThermAuxHeatMode,
                ThermAuxHeatOffset
               ]
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



9
10
11
# File 'lib/pdp/network.rb', line 9

def buffer
  @buffer
end

#debugObject

Returns the value of attribute debug.



9
10
11
# File 'lib/pdp/network.rb', line 9

def debug
  @debug
end

#queryObject

Returns the value of attribute query.



9
10
11
# File 'lib/pdp/network.rb', line 9

def query
  @query
end

#simulateObject

Returns the value of attribute simulate.



9
10
11
# File 'lib/pdp/network.rb', line 9

def simulate
  @simulate
end

#squeryObject

Returns the value of attribute squery.



9
10
11
# File 'lib/pdp/network.rb', line 9

def squery
  @squery
end

Instance Method Details

#[](reading) ⇒ Object



38
39
40
# File 'lib/pdp/network.rb', line 38

def [](reading)
    return @fetched[reading]
end

#get(name) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/pdp/network.rb', line 42

def get(name)
    if self[name] and up_to_date
        return self[name]
    else
        fetch_data
        # TODO: what if we don't manage to return values
        return self[name]
    end
end

#set(name, value) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/pdp/network.rb', line 52

def set(name, value)
    set_data(name, value)
    if not @simulate
        sleep 1
    end
    fetch_data
end