Skip to content

Home Information - Your home, your data, organized.

Python

Added console sleep mode.

Anthony Cassandra4bba03c1dd2d
diff --git a/src/hi/apps/alert/alert_manager.py b/src/hi/apps/alert/alert_manager.py
index 67780796..e15f246d 100644
--- a/src/hi/apps/alert/alert_manager.py
+++ b/src/hi/apps/alert/alert_manager.py
@@ -83,7 +83,7 @@ class AlertManager( Singleton, NotificationMixin ):
return
async def add_alarm( self, alarm : Alarm ):
- notification_manager = await self._notification_manager_async()
+ notification_manager = await self.notification_manager_async()
logging.debug( f'Adding Alarm: {alarm}' )
security_state = SecurityManager().security_state
try:
diff --git a/src/hi/apps/attribute/enums.py b/src/hi/apps/attribute/enums.py
index b552f1b1..8e00740e 100644
--- a/src/hi/apps/attribute/enums.py
+++ b/src/hi/apps/attribute/enums.py
@@ -19,6 +19,7 @@ class AttributeValueType(LabeledEnum):
ENUM = ('Enum' , '' )
BOOLEAN = ('Boolean' , '' )
INTEGER = ('Integer' , '' )
+ FLOAT = ('Float' , '' )
@classmethod
def default(cls):
diff --git a/src/hi/apps/config/context_processors.py b/src/hi/apps/config/context_processors.py
index 17430ec3..bbbdffb3 100644
--- a/src/hi/apps/config/context_processors.py
+++ b/src/hi/apps/config/context_processors.py
@@ -5,4 +5,5 @@ def settings_context(request):
console_manager = ConsoleManager()
return {
'CONSOLE_AUDIO_MAP': console_manager.get_console_audio_map(),
+ 'SLEEP_OVERLAY_OPACITY': console_manager.get_sleep_overlay_opacity(),
}
diff --git a/src/hi/apps/console/console_manager.py b/src/hi/apps/console/console_manager.py
index 90215a55..bd0c8c9d 100644
--- a/src/hi/apps/console/console_manager.py
+++ b/src/hi/apps/console/console_manager.py
@@ -2,7 +2,6 @@ import logging
from typing import Dict
from django.http import HttpRequest
-from django.template.loader import get_template
from hi.apps.common.singleton import Singleton
from hi.apps.config.settings_manager import SettingsManager
@@ -10,6 +9,7 @@ from hi.apps.config.settings_manager import SettingsManager
from .audio_file import AudioFile
from .audio_signal import AudioSignal
from .constants import ConsoleConstants
+from .settings import ConsoleSetting
logger = logging.getLogger(__name__)
@@ -26,6 +26,9 @@ class ConsoleManager(Singleton):
def get_console_audio_map( self ) -> Dict[ str, str ]:
return self._console_audio_map
+
+ def get_sleep_overlay_opacity( self ) -> str:
+ return SettingsManager().get_setting_value( ConsoleSetting.SLEEP_OVERLAY_OPACITY )
def _reload_console_audio_map( self ) -> Dict[ str, str ]:
logger.debug( 'Reloading console audio map' )
diff --git a/src/hi/apps/console/settings.py b/src/hi/apps/console/settings.py
index 7935e6c5..546be5f9 100644
--- a/src/hi/apps/console/settings.py
+++ b/src/hi/apps/console/settings.py
@@ -28,6 +28,15 @@ class ConsoleSetting( SettingEnum ):
is_required = False,
initial_value = '',
)
+ SLEEP_OVERLAY_OPACITY = SettingDefinition(
+ label = 'Sleep Overlap Opacity',
+ description = 'Opacity to use for sleep mode: 0.0 for none to 1.0 for fully opaque.',
+ value_type = AttributeValueType.FLOAT,
+ value_range_str = '[ 0.0, 1.0 ]',
+ is_editable = True,
+ is_required = True,
+ initial_value = '0.95',
+ )
THEME = SettingDefinition(
label = 'Theme',
description = 'Overall look and feel of interfaces',
diff --git a/src/hi/apps/console/templates/console/panes/sleep_mode_control.html b/src/hi/apps/console/templates/console/panes/sleep_mode_control.html
new file mode 100644
index 00000000..0a0809e7
--- /dev/null
+++ b/src/hi/apps/console/templates/console/panes/sleep_mode_control.html
@@ -0,0 +1,4 @@
+<button class="btn btn-secondary btn-control" role="button"
+onclick="Hi.settings.enableSleepMode();">
+ SLEEP
+</button>
diff --git a/src/hi/apps/console/views.py b/src/hi/apps/console/views.py
index 1219fa82..cdcf3673 100644
--- a/src/hi/apps/console/views.py
+++ b/src/hi/apps/console/views.py
@@ -1,6 +1,4 @@
from django.core.exceptions import BadRequest
-from django.http import JsonResponse
-from django.shortcuts import render
from django.views.generic import View
from hi.apps.config.settings_manager import SettingsManager
diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.css
index bbaea638..bf094af4 100644
--- a/src/hi/static/css/main.css
+++ b/src/hi/static/css/main.css
@@ -367,3 +367,15 @@ div[status="low"] {
color: var(--on-error-color);
background-color: var(--error-color);
}
+
+#hi-sleep-overlay {
+ position: fixed;
+ display: none;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ background-color: black;
+ z-index: 9999;
+ transition: opacity 0.3s ease;
+}
diff --git a/src/hi/static/js/settings.js b/src/hi/static/js/settings.js
index c3d8291f..61b22652 100644
--- a/src/hi/static/js/settings.js
+++ b/src/hi/static/js/settings.js
@@ -12,9 +12,15 @@
},
isAudioEnabled: function() {
return _isAudioEnabled( );
+ },
+ enableSleepMode: function() {
+ return _enableSleepMode( );
+ },
+ disableSleepMode: function() {
+ return _disableSleepMode( );
}
};
-
+
window.Hi.settings = HiSettings;
/*
@@ -23,6 +29,7 @@
- Adjustable settings relevant for the console.
*/
+ const SleepOverlaySelector = '#hi-sleep-overlay';
const AudioStateSettingName = 'audioState';
const AudioStateEnabled = 'enabled';
const AudioStateDisabled = 'disabled';
@@ -51,5 +58,14 @@
return false;
return true;
}
+
+ function _enableSleepMode() {
+ let sleepOverlay = $(SleepOverlaySelector);
+ $(sleepOverlay).show();
+ $(sleepOverlay).off( 'click').on('click', Hi.settings.disableSleepMode );
+ }
+ function _disableSleepMode() {
+ $(SleepOverlaySelector).hide();
+ }
})();
diff --git a/src/hi/templates/pages/hi_grid.html b/src/hi/templates/pages/hi_grid.html
index 84fc2c35..838a0515 100644
--- a/src/hi/templates/pages/hi_grid.html
+++ b/src/hi/templates/pages/hi_grid.html
@@ -25,8 +25,10 @@
</div>
</div>
</div>
-{% endblock %}
+<div id="hi-sleep-overlay" style="opacity: {{ SLEEP_OVERLAY_OPACITY }};"></div>
+
+{% endblock %}
{% block footer_post_javascript %}
{% javascript 'js_hi_grid_content' %}
diff --git a/src/hi/templates/panes/bottom_buttons.html b/src/hi/templates/panes/bottom_buttons.html
index 296c11d3..f12f5f09 100644
--- a/src/hi/templates/panes/bottom_buttons.html
+++ b/src/hi/templates/panes/bottom_buttons.html
@@ -7,11 +7,7 @@
{% include "console/panes/audio_control.html" %}
</div>
<div>
- <a href="#"
- class="btn btn-secondary btn-control" role="button"
- data-async="true" >
- SLEEP
- </a>
+ {% include "console/panes/sleep_mode_control.html" %}
</div>
<div>
{% include "console/panes/console_lock_button.html" %}