Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4c8c7d9
WIP bus servo management
danic85 Jul 12, 2025
d18189c
Update config
danic85 Jul 12, 2025
60d524a
Added SC servo examples + compatibility
danic85 Jul 13, 2025
3e4dfc0
Configure initial positions
danic85 Jul 14, 2025
0be65a3
Allow other poses to be stored and accessed
danic85 Jul 14, 2025
91fac95
Added change_id script
danic85 Aug 3, 2025
69f2d7c
Calibrate servos on boot
danic85 Oct 4, 2025
9a57f8a
adjustments
danic85 Oct 4, 2025
0cf906e
Dynamic servo calibration + center on change_id
danic85 Oct 5, 2025
8d62b54
Controller support and WIP recording
danic85 Dec 13, 2025
f02d0db
Working with Pi
danic85 Dec 13, 2025
b052ed0
Adjust config
danic85 Dec 13, 2025
6841f63
Cleanup
danic85 Dec 14, 2025
c1ed384
Working input recorder
danic85 Dec 14, 2025
5e503e5
Support servo control (WIP - calibration needed)
danic85 Dec 14, 2025
008c369
Callibration + allow modules to be disabled on test environments
danic85 Dec 15, 2025
af0fdb2
Disable test
danic85 Dec 15, 2025
40040c8
Add documentation and tests
danic85 Dec 16, 2025
f645caa
Fix test
danic85 Dec 16, 2025
8a22781
Timeout controller connection after 30 seconds
danic85 Dec 16, 2025
d81c07c
Enable on robot
danic85 Dec 16, 2025
6a84d43
Fix for environment input to resolve pi issue
danic85 Dec 17, 2025
4803d58
Calibrate new leg position
danic85 Dec 17, 2025
dc4cb27
Improvements to gamepad controller modules. Temperature alert in disp…
danic85 Dec 18, 2025
d48ccd8
Fix tests
danic85 Dec 18, 2025
4a5a0ee
Fixes and improvements to loop and temperature management
danic85 Dec 21, 2025
5349956
Fix tests
danic85 Dec 21, 2025
cd4331b
Resolve PR comments
danic85 Dec 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
danic85 committed Dec 21, 2025
commit 5349956751720a6050f7b8ea6eedbd7f9cc9f731
4 changes: 2 additions & 2 deletions modules/pitemperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ class PiTemperature(BaseModule):
MIN_TEMP = 15
MONITOR_INTERVAL = 60 # seconds

def __init__(self):
self.debug = False

def setup_messaging(self):
"""No longer subscribes to system/loop/60; starts background thread instead."""
self._stop_event = threading.Event()
self._thread = threading.Thread(target=self._monitor_thread, daemon=True)
self._thread.start()
self.debug = True
self._start_time = time.time() # For debug
self._min_temp = None # For debug
self._max_temp = None # For debug


def _monitor_thread(self):
while not getattr(self, '_stop_event', threading.Event()).is_set():
Expand Down
35 changes: 29 additions & 6 deletions tests/test_pitemperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,64 @@

class TestPiTemperature(unittest.TestCase):


@mock.patch('modules.pitemperature.os.popen')
def test_monitor_critical_temp(self, mock_popen):
mock_popen.return_value.readline.return_value = "temp=86'C"
temp_module = PiTemperature()
temp_module.messaging_service = mock.MagicMock()

with mock.patch.object(temp_module, 'publish') as mock_publish, \
mock.patch.object(temp_module, 'log') as mock_log:
temp_module.monitor()
mock_publish.assert_called_with('system/temperature', value='86')
# Should publish temperature and system/sleep
mock_publish.assert_any_call('system/temperature', value='86')
mock_publish.assert_any_call('system/sleep', requestor='PiTemperature')
# Should log only the critical message
mock_log.assert_called_with('Temperature is critical: 86°C', 'critical')


@mock.patch('modules.pitemperature.os.popen')
def test_monitor_high_temp(self, mock_popen):
mock_popen.return_value.readline.return_value = "temp=81'C"
temp_module = PiTemperature()
temp_module.messaging_service = mock.MagicMock()

with mock.patch.object(temp_module, 'publish') as mock_publish, \
mock.patch.object(temp_module, 'log') as mock_log:
temp_module.monitor()
mock_publish.assert_called_with('system/temperature', value='81')
# Should publish temperature and system/throttle
mock_publish.assert_any_call('system/temperature', value='81')
mock_publish.assert_any_call('system/throttle', requestor='PiTemperature')
# Should log only the warning message
mock_log.assert_called_with('Temperature is high: 81°C', 'warning')


@mock.patch('modules.pitemperature.os.popen')
def test_monitor_normal_temp(self, mock_popen):
mock_popen.return_value.readline.return_value = "temp=50'C"
temp_module = PiTemperature()
temp_module.messaging_service = mock.MagicMock()

with mock.patch.object(temp_module, 'publish') as mock_publish, \
mock.patch.object(temp_module, 'log') as mock_log:
temp_module.monitor()
mock_publish.assert_called_with('system/temperature', value='50')
# Should publish temperature and system/wake
mock_publish.assert_any_call('system/temperature', value='50')
mock_publish.assert_any_call('system/wake', requestor='PiTemperature')
# Should log only the debug message
mock_log.assert_called_with('Temperature: 50°C', 'debug')

@mock.patch('modules.pitemperature.os.popen')
@mock.patch('modules.pitemperature.sys.exit')
def test_monitor_shutdown_temp(self, mock_exit, mock_popen):
mock_popen.return_value.readline.return_value = "temp=91'C"
temp_module = PiTemperature()
temp_module.messaging_service = mock.MagicMock()
with mock.patch.object(temp_module, 'publish') as mock_publish, \
mock.patch.object(temp_module, 'log') as mock_log:
temp_module.monitor()
mock_publish.assert_any_call('system/temperature', value='91')
# Should log only the critical message
mock_log.assert_called_with('Temperature is too high exiting script: 91°C', 'critical')
mock_exit.assert_called_once_with(1)

if __name__ == '__main__':
unittest.main()
18 changes: 0 additions & 18 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,5 @@ def test_read(self):
self.assertFalse(sensor.read())
self.assertFalse(sensor.value)

def test_loop(self):
sensor = Sensor(pin=17)
with mock.patch.object(sensor, 'read', return_value=True):
with mock.patch.object(sensor, 'publish') as mock_publish:
sensor.loop()
mock_publish.assert_called_with('gpio/motion')

with mock.patch.object(sensor, 'read', return_value=False):
with mock.patch.object(sensor, 'publish') as mock_publish:
sensor.loop()
mock_publish.assert_not_called()

def test_setup_messaging(self):
sensor = Sensor(pin=17)
with mock.patch.object(sensor, 'subscribe') as mock_subscribe:
sensor.setup_messaging()
mock_subscribe.assert_called_with('system/loop/1', sensor.loop)

if __name__ == '__main__':
unittest.main()