Class: DeviceControl::Flexstat

Inherits:
Thermostat show all
Defined in:
lib/device_control.rb

Overview

now consider e.g. h = Heater.new(1000) ht = Thermostat.new(20) c = Cooler.new(1000) ct = Thermostat.new(25) temp = 26.4 heat_knob = ht.update(temp) ? 1 : 0 heating_watts = h.update(heat_knob) cool_knob = ct.update(temp) ? 0 : 1 cooling_watts = c.update(cool_knob) etc

Instance Attribute Summary collapse

Attributes inherited from Controller

#measure, #setpoint

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Controller

#input=, #to_s

Methods included from Updateable

#update

Constructor Details

#initialize(setpoint, hot_val: false, cold_val: nil) ⇒ Flexstat

Returns a new instance of Flexstat.



146
147
148
149
150
151
# File 'lib/device_control.rb', line 146

def initialize(setpoint, hot_val: false, cold_val: nil)
  super(setpoint)

  @hot_val = hot_val
  @cold_val = cold_val.nil? ? self.class.cold_val(hot_val) : cold_val
end

Instance Attribute Details

#cold_valObject (readonly)

Returns the value of attribute cold_val.



144
145
146
# File 'lib/device_control.rb', line 144

def cold_val
  @cold_val
end

#hot_valObject (readonly)

Returns the value of attribute hot_val.



144
145
146
# File 'lib/device_control.rb', line 144

def hot_val
  @hot_val
end

Class Method Details

.cold_val(hot_val) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/device_control.rb', line 129

def self.cold_val(hot_val)
  case hot_val
  when true, false
    !hot_val
  when 0,1
    hot_val == 0 ? 1 : 0
  when Numeric
    0
  when :on, :off
    hot_val == :on ? :off : :on
  else
    raise "#{hot_val.inspect} not recognized"
  end
end

Instance Method Details

#outputObject



153
154
155
# File 'lib/device_control.rb', line 153

def output
  super ? @cold_val : @hot_val
end