Skip to content

Commit bcc7229

Browse files
add thermal line 2 to Idle
1 parent dd20410 commit bcc7229

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

src/ui_state/main_menu.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
The file for the MainMenu class
33
"""
44

5+
import time
6+
57
from src.devices.library import Keypad
68
from src.ui_state.set_menu.set_chill_or_heat import SetChillOrHeat
79
from src.ui_state.set_menu.set_google_mins import SetGoogleSheetInterval
@@ -220,7 +222,27 @@ def idle(self):
220222
"""
221223
lcd = self.titrator.lcd
222224
lcd.print("Idle Line 1", line=1)
223-
lcd.print("Idle Line 2", line=2)
225+
226+
thermal_control = self.titrator.thermal_control
227+
temperature = self.titrator.thermal_probe.get_running_average()
228+
status = "h" if thermal_control.get_heat(True) else "c"
229+
230+
output = [" "] * 20
231+
output[0] = "T"
232+
output[1] = "=" if int(time.monotonic()) % 2 == 0 else " "
233+
234+
buffer = f"{temperature:5.2f}"
235+
output[2:7] = list(buffer[:5])
236+
237+
output[7] = " "
238+
output[8] = status
239+
output[9] = " "
240+
241+
thermal_target = thermal_control.get_current_thermal_target()
242+
buffer = f"{thermal_target:5.2f}"
243+
output[10:15] = list(buffer[:5])
244+
245+
self.titrator.lcd.print("".join(output), line=2)
224246

225247
def loop(self):
226248
"""

tests/ui_state/main_menu_test.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ def test_view_list(print_mock):
145145
"""
146146
main_menu = MainMenu(Titrator())
147147

148-
main_menu.loop()
149-
print_mock.assert_any_call("Idle Line 1", line=1)
150-
print_mock.assert_any_call("Idle Line 2", line=2)
151-
print_mock.reset_mock()
152-
153148
main_menu.handle_key("6")
154149
main_menu.loop()
155150
print_mock.assert_any_call("View settings", line=1)
@@ -172,11 +167,6 @@ def test_change_list(print_mock):
172167
"""
173168
main_menu = MainMenu(Titrator())
174169

175-
main_menu.loop()
176-
print_mock.assert_any_call("Idle Line 1", line=1)
177-
print_mock.assert_any_call("Idle Line 2", line=2)
178-
print_mock.reset_mock()
179-
180170
main_menu.handle_key("6")
181171
main_menu.handle_key("8")
182172
main_menu.loop()
@@ -191,3 +181,28 @@ def test_change_list(print_mock):
191181
main_menu.handle_key("8")
192182
main_menu.loop()
193183
print_mock.assert_any_call(label, line=1)
184+
185+
186+
@mock.patch("src.devices.library.LiquidCrystal.print")
187+
@mock.patch("src.titrator.ThermalControl.get_current_thermal_target")
188+
@mock.patch("src.titrator.ThermalControl.get_heat")
189+
@mock.patch("src.titrator.ThermalProbe.get_running_average")
190+
def test_idle_thermal_display(
191+
mock_get_running_average,
192+
mock_get_heat,
193+
mock_get_current_thermal_target,
194+
mock_lcd_print,
195+
):
196+
"""
197+
Test that the thermal portion of the idle method displays the correct information.
198+
"""
199+
main_menu = MainMenu(Titrator())
200+
201+
mock_get_running_average.return_value = 22.75
202+
mock_get_heat.return_value = True
203+
mock_get_current_thermal_target.return_value = 25.50
204+
205+
main_menu.loop()
206+
mock_lcd_print.assert_any_call(
207+
"T=22.75 h 25.50 " or "T 22.75 h 25.50 ", line=2
208+
)

0 commit comments

Comments
 (0)