Home Information - Your home, your data, organized.
Python
Added audio test button to audio config settings page (#197)
cassandra-ai-agent29ebeb3f5ceb
diff --git a/src/hi/apps/attribute/templates/attribute/components/regular_attribute_list.html b/src/hi/apps/attribute/templates/attribute/components/regular_attribute_list.htmlindex 8395661e..671f46d9 100644--- a/src/hi/apps/attribute/templates/attribute/components/regular_attribute_list.html+++ b/src/hi/apps/attribute/templates/attribute/components/regular_attribute_list.html@@ -5,12 +5,14 @@<h6 class="attr-v2-section-title">{{ title }}</h6>{% endif %}+ {% if regular_attributes_formset.non_form_errors %}<div class="attr-v2-formset-errors"style="width: 450px; overflow: hidden; word-wrap: break-word;">{% for err in regular_attributes_formset.non_form_errors %}<div class="attr-v2-error-item" style="word-break: break-word;">{{ err }}</div>{% endfor %}</div>+ {% endif %}<div class="attr-v2-attribute-list">{% for attribute_form in regular_attributes_formset %}diff --git a/src/hi/apps/config/templates/config/panes/subsystem_edit_content_body.html b/src/hi/apps/config/templates/config/panes/subsystem_edit_content_body.htmlindex 33fa2d3e..05514e43 100644--- a/src/hi/apps/config/templates/config/panes/subsystem_edit_content_body.html+++ b/src/hi/apps/config/templates/config/panes/subsystem_edit_content_body.html@@ -61,7 +61,18 @@ This is what gets replaced on form submissionaria-labelledby="subsystem-{{ multi_edit_form_data.owner.id }}-tab"><!-- Subsystem content using existing attribute editing components -->- <div class="py-3">+ <div class="">+ {% if multi_edit_form_data.owner.subsystem_key == "hi.apps.audio" %}+ <!-- Audio Test Button - only shown for Audio subsystem -->+ <div class="mb-3 text-right">+ <button type="button"+ class="btn btn-outline-primary btn-xs"+ onclick="Hi.audio.testAudio();"+ title="Test audio playback">+ {% icon "play" size="xs" css_class="hi-icon-left" %}Test Audio+ </button>+ </div>+ {% endif %}{% include "attribute/components/regular_attribute_list.html" with regular_attributes_formset=multi_edit_form_data.formset attr_item_context=multi_edit_form_data.context %}</div>diff --git a/src/hi/apps/config/tests/test_views.py b/src/hi/apps/config/tests/test_views.pyindex 03b0c04e..c7f6407c 100644--- a/src/hi/apps/config/tests/test_views.py+++ b/src/hi/apps/config/tests/test_views.py@@ -150,4 +150,62 @@ class TestConfigSettingsView(DualModeViewTestCase):# There may be default system subsystems in addition to our test subsystemself.assertGreaterEqual(len(form_data_list), 1) # At least our test subsystem+ def test_audio_test_button_appears_only_for_audio_subsystem(self):+ """Test that audio test functionality appears only in audio subsystem context."""+ # Get or create an audio subsystem to trigger the audio test button display+ audio_subsystem, _ = Subsystem.objects.get_or_create(+ subsystem_key='hi.apps.audio',+ defaults={'name': 'Audio System'}+ )++ # Create a non-audio subsystem for comparison+ other_subsystem = Subsystem.objects.create(+ name='Other System',+ subsystem_key='hi.apps.other.test'+ )++ url = reverse('config_settings')+ response = self.client.get(url)++ self.assertSuccessResponse(response)+ self.assertHtmlResponse(response)++ # Verify structural elements for audio test functionality+ content = response.content.decode('utf-8')++ # Test that audio test functionality is present (structural check)+ # Look for button element with audio test trigger (using semantic HTML structure)+ self.assertIn('onclick="Hi.audio.testAudio()', content)+ self.assertIn('type="button"', content)++ # Verify the button appears in the correct subsystem context+ # Check that it appears within the audio subsystem panel+ audio_panel_id = f'subsystem-{audio_subsystem.id}-panel'+ self.assertIn(audio_panel_id, content)++ # Verify tab structure includes both subsystems+ audio_tab_id = f'subsystem-{audio_subsystem.id}-tab'+ other_tab_id = f'subsystem-{other_subsystem.id}-tab'+ self.assertIn(audio_tab_id, content)+ self.assertIn(other_tab_id, content)++ # Test accessibility: button should have descriptive title attribute+ self.assertIn('title=', content)++ # Ensure the audio test button only appears in audio subsystem context+ # This is the key structural behavior - conditional rendering based on subsystem_key+ audio_section_start = content.find(f'id="{audio_panel_id}"')+ audio_section_end = content.find('</div>', audio_section_start + len(audio_panel_id) + 20)+ audio_section = content[audio_section_start:audio_section_end] if audio_section_start != -1 else ""++ # Verify audio test function call exists within audio subsystem section+ self.assertIn('Hi.audio.testAudio()', audio_section)++ # Verify the non-audio subsystem doesn't have audio test functionality+ other_section_start = content.find(f'id="subsystem-{other_subsystem.id}-panel"')+ if other_section_start != -1:+ other_section_end = content.find('</div>', other_section_start + 50)+ other_section = content[other_section_start:other_section_end]+ self.assertNotIn('Hi.audio.testAudio()', other_section)+diff --git a/src/hi/static/js/audio.js b/src/hi/static/js/audio.jsindex c8e65133..cefa4e27 100644--- a/src/hi/static/js/audio.js+++ b/src/hi/static/js/audio.js@@ -25,6 +25,11 @@return _handleAudioButtonClick();},+ // Audio testing method for configuration pages+ testAudio: function() {+ _testAudio();+ },+// Initializationinit: function() {startAudioPolling();@@ -112,12 +117,12 @@return `${SignalAudioIdPrefix}-${signalName}`;}- function _startAudibleSignal( signalName ) {- if ( Hi.DEBUG ) { console.log( `Starting audio signal = ${signalName}` ); }+ function _startAudibleSignal( signalName, forcePlay = false ) {+ if ( Hi.DEBUG ) { console.log( `Starting audio signal = ${signalName}, forcePlay = ${forcePlay}` ); }try {stopAudio( );clearAudibleSignalTimer();- if ( ! Hi.settings.isAudioEnabled() ) {+ if ( ! forcePlay && ! Hi.settings.isAudioEnabled() ) {if ( Hi.DEBUG ) { console.log( `Audio disabled, not playing signal: ${signalName}` ); }return;}@@ -632,6 +637,26 @@}}+ /*+ AUDIO TESTING FOR CONFIGURATION PAGES++ - Provides a simple test function to play a soft audio signal+ - Uses existing audio infrastructure and error handling+ */++ function _testAudio() {+ if (Hi.DEBUG) { console.log('Testing audio with ConsoleInfo signal (bypassing audio enabled setting)'); }++ // Use forcePlay=true to bypass audio enabled setting for testing+ _startAudibleSignal('ConsoleInfo', true);++ // The _startAudibleSignal function handles:+ // - Missing audio elements+ // - Autoplay restrictions with user feedback+ // - All error cases with appropriate logging+ // - Audio enabled setting (bypassed with forcePlay=true)+ }+// Initialize systems when audio module loadswindow.addEventListener('load', function() {_startBaselineMonitoring();