Class: DeviceControl::Flexstat
- Inherits:
-
Thermostat
- Object
- Controller
- Thermostat
- DeviceControl::Flexstat
- 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
-
#cold_val ⇒ Object
readonly
Returns the value of attribute cold_val.
-
#hot_val ⇒ Object
readonly
Returns the value of attribute hot_val.
Attributes inherited from Controller
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(setpoint, hot_val: false, cold_val: nil) ⇒ Flexstat
constructor
A new instance of Flexstat.
- #output ⇒ Object
Methods inherited from Controller
Methods included from Updateable
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_val ⇒ Object (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_val ⇒ Object (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
#output ⇒ Object
153 154 155 |
# File 'lib/device_control.rb', line 153 def output super ? @cold_val : @hot_val end |