Class: Sappho::Heatmiser::Proxy::HeatmiserStatus

Inherits:
Object
  • Object
show all
Includes:
LogUtilities, Singleton
Defined in:
lib/sappho-heatmiser-proxy/heatmiser_status.rb

Defined Under Namespace

Classes: Schedule, TimedTemperature

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeatmiserStatus

Returns a new instance of HeatmiserStatus.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 60

def initialize
  @mutex = Mutex.new
  @log = Sappho::ApplicationAutoFlushLog.instance
  @valid = false
  @raw = []
  @timestamp = Time.now
  @sampleTime = 0.0
  @timeSinceLastValid = 0.0
  @sensedTemperature = 0.0
  @requestedTemperature = 0
  @holidayReturnTime = Time.now
  @holdMinutes = 0
  @heatOn = false
  @keyLockOn = false
  @frostProtectOn = false
  @holidayOn = false
  @deviceTimeOffset = 0.0
  @dayOfWeek = 0
  @schedule = {}
end

Instance Attribute Details

#dayOfWeekObject (readonly)

Returns the value of attribute dayOfWeek.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def dayOfWeek
  @dayOfWeek
end

#deviceTimeOffsetObject (readonly)

Returns the value of attribute deviceTimeOffset.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def deviceTimeOffset
  @deviceTimeOffset
end

#frostProtectOnObject (readonly)

Returns the value of attribute frostProtectOn.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def frostProtectOn
  @frostProtectOn
end

#heatOnObject (readonly)

Returns the value of attribute heatOn.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def heatOn
  @heatOn
end

#keyLockOnObject (readonly)

Returns the value of attribute keyLockOn.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def keyLockOn
  @keyLockOn
end

#requestedTemperatureObject (readonly)

Returns the value of attribute requestedTemperature.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def requestedTemperature
  @requestedTemperature
end

#sampleTimeObject (readonly)

Returns the value of attribute sampleTime.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def sampleTime
  @sampleTime
end

#scheduleObject (readonly)

Returns the value of attribute schedule.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def schedule
  @schedule
end

#sensedTemperatureObject (readonly)

Returns the value of attribute sensedTemperature.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def sensedTemperature
  @sensedTemperature
end

#timeSinceLastValidObject (readonly)

Returns the value of attribute timeSinceLastValid.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def timeSinceLastValid
  @timeSinceLastValid
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def timestamp
  @timestamp
end

#validObject (readonly)

Returns the value of attribute valid.



18
19
20
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 18

def valid
  @valid
end

Instance Method Details

#getObject



85
86
87
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 85

def get
  @mutex.synchronize { yield }
end

#invalidateObject



128
129
130
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 128

def invalidate
  @mutex.synchronize { @valid = false }
end

#rawObject



81
82
83
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 81

def raw
  @raw.dup
end

#set(raw, timestamp, sampleTime) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/sappho-heatmiser-proxy/heatmiser_status.rb', line 89

def set raw, timestamp, sampleTime
  @mutex.synchronize do
    @valid = true
    begin
      @raw = raw.dup
      @sensedTemperature = ((raw[44] & 0xFF) | ((raw[45] << 8) & 0xFF00)) / 10.0
      @holdMinutes = (raw[38] & 0xFF) | ((raw[39] << 8) & 0xFF00)
      @heatOn = raw[47] == 1
      @keyLockOn = raw[29] == 1
      @frostProtectOn = raw[30] == 1
      @holidayOn = raw[37] == 1
      @holidayReturnTime = Time.local(2000 + (raw[32] & 0xFF), raw[33], raw[34], raw[35], raw[36], 0)
      @requestedTemperature = @frostProtectOn ? raw[24] & 0xFF : raw[25] & 0xFF
      @deviceTimeOffset = Time.local(2000 + (raw[48] & 0xFF), raw[49], raw[50],
                                     raw[52], raw[53], raw[54]) - timestamp
      dayOfWeek = raw[51]
      @dayOfWeek = dayOfWeek == 7 ? 0 : dayOfWeek
      @schedule = {
          :weekday => Schedule.new(@raw, 55),
          :weekend => Schedule.new(@raw, 67)
      }
      @timeSinceLastValid = timestamp - @timestamp
      @timestamp = timestamp
      @sampleTime = sampleTime
      if @log.debug?
        @log.debug "#{hexString raw}"
        @log.debug "#{@requestedTemperature} #{@holdMinutes / 60}:#{@holdMinutes % 60} #{@sensedTemperature} #{@heatOn} #{@keyLockOn} #{@frostProtectOn} #{@timeSinceLastValid} #{@dayOfWeek} #{@deviceTimeOffset} #{sampleTime} #{@holidayOn} #{@holidayReturnTime}"
        @log.debug "weekday: #{@schedule[:weekday].description} weekend: #{@schedule[:weekend].description}"
      else
        @log.info "received status: heating is #{@heatOn ? "on" : "off"} because required temperature is #{@requestedTemperature} and actual is #{@sensedTemperature}"
      end
      yield
    rescue => error
      @log.error error
      @valid = false
    end
  end
end