Skip to content

Home Information - Your home, your data, organized.

Python

Cleanup and refactoring after settings redesign.

Anthony Cassandraa415e4968883
diff --git a/src/hi/apps/attribute/models.py b/src/hi/apps/attribute/models.py
index f1a063e2..50351a50 100644
--- a/src/hi/apps/attribute/models.py
+++ b/src/hi/apps/attribute/models.py
@@ -4,7 +4,7 @@ import logging
from django.core.files.storage import default_storage
from django.db import models
-from hi.apps.attribute.enum_attributes import PredefinedEnumAttributes
+from hi.apps.attribute.value_ranges import PredefinedValueRanges
from hi.apps.common.file_utils import generate_unique_filename
from hi.integrations.core.integration_key import IntegrationKey
@@ -119,7 +119,7 @@ class AttributeModel(models.Model):
def choices(self):
# First check predefined ids
- choice_list = PredefinedEnumAttributes.get_choices( self.value_range_str )
+ choice_list = PredefinedValueRanges.get_choices( self.value_range_str )
if choice_list:
return choice_list
if not self.value_range_str:
diff --git a/src/hi/apps/attribute/enum_attributes.py b/src/hi/apps/attribute/value_ranges.py
similarity index 86%
rename from src/hi/apps/attribute/enum_attributes.py
rename to src/hi/apps/attribute/value_ranges.py
index 489398af..49b04087 100644
--- a/src/hi/apps/attribute/enum_attributes.py
+++ b/src/hi/apps/attribute/value_ranges.py
@@ -2,12 +2,11 @@ from typing import List, Tuple
from hi.apps.console.audio_file import AudioFile
from hi.apps.console.enums import Theme
-from hi.apps.security.enums import SecurityState
from hi.constants import TIME_OF_DAY_CHOICES, TIMEZONE_NAME_LIST
-class PredefinedEnumAttributes:
+class PredefinedValueRanges:
"""
For attributes of type AttributeValueType.ENUM. There are some
predefined common defaults that can be used. Instead of putting all
@@ -23,14 +22,12 @@ class PredefinedEnumAttributes:
THEME_CHOICES_ID = 'hi.theme'
AUDIO_FILE_CHOICES_ID = 'hi.audio.file'
TIME_OF_DAY_CHOICES_ID = 'hi.datetime.time-of-day'
- SECURITY_STATE_CHOICES_ID = 'hi.security.state'
ID_TO_CHOICES = {
TIME_OF_DAY_CHOICES_ID: TIME_OF_DAY_CHOICES,
TIMEZONE_CHOICES_ID: [ ( x, x ) for x in TIMEZONE_NAME_LIST ],
THEME_CHOICES_ID: Theme.choices(),
AUDIO_FILE_CHOICES_ID: AudioFile.choices(),
- SECURITY_STATE_CHOICES_ID: SecurityState.choices(),
}
@classmethod
diff --git a/src/hi/apps/console/settings.py b/src/hi/apps/console/settings.py
index b0f50f07..c768c92e 100644
--- a/src/hi/apps/console/settings.py
+++ b/src/hi/apps/console/settings.py
@@ -1,5 +1,6 @@
from hi.apps.config.setting_enums import SettingEnum, SettingDefinition
from hi.apps.attribute.enums import AttributeValueType
+from hi.apps.attribute.value_ranges import PredefinedValueRanges
from .audio_file import AudioFile
from .enums import Theme
@@ -13,7 +14,7 @@ class ConsoleSetting( SettingEnum ):
label = 'Timezone',
description = 'Timezone to use for display',
value_type = AttributeValueType.ENUM,
- value_range_str = 'hi.timezone',
+ value_range_str = PredefinedValueRanges.TIMEZONE_CHOICES_ID,
is_editable = True,
is_required = True,
initial_value = 'America/Chicago',
@@ -22,7 +23,7 @@ class ConsoleSetting( SettingEnum ):
label = 'Theme',
description = 'Overall look and feel of interfaces',
value_type = AttributeValueType.ENUM,
- value_range_str = 'hi.theme',
+ value_range_str = PredefinedValueRanges.THEME_CHOICES_ID,
is_editable = True,
is_required = True,
initial_value = str( Theme.default() ),
@@ -31,7 +32,7 @@ class ConsoleSetting( SettingEnum ):
label = 'Info Alert Sound',
description = 'The sound to play when an INFO level alert arrives.',
value_type = AttributeValueType.ENUM,
- value_range_str = 'hi.audio.file',
+ value_range_str = PredefinedValueRanges.AUDIO_FILE_CHOICES_ID,
is_editable = True,
is_required = False,
initial_value = AudioFile.INFO,
@@ -40,7 +41,7 @@ class ConsoleSetting( SettingEnum ):
label = 'Warning Alert Sound',
description = 'The sound to play when an WARNING level alert arrives.',
value_type = AttributeValueType.ENUM,
- value_range_str = 'hi.audio.file',
+ value_range_str = PredefinedValueRanges.AUDIO_FILE_CHOICES_ID,
is_editable = True,
is_required = False,
initial_value = AudioFile.WARNING,
@@ -49,7 +50,7 @@ class ConsoleSetting( SettingEnum ):
label = 'Critical Alert Sound',
description = 'The sound to play when an CRITICAL level alert arrives.',
value_type = AttributeValueType.ENUM,
- value_range_str = 'hi.audio.file',
+ value_range_str = PredefinedValueRanges.AUDIO_FILE_CHOICES_ID,
is_editable = True,
is_required = False,
initial_value = AudioFile.CRITICAL,
diff --git a/src/hi/apps/security/settings.py b/src/hi/apps/security/settings.py
index 3300e2f7..119e98f7 100644
--- a/src/hi/apps/security/settings.py
+++ b/src/hi/apps/security/settings.py
@@ -1,5 +1,6 @@
from hi.apps.config.setting_enums import SettingEnum, SettingDefinition
from hi.apps.attribute.enums import AttributeValueType
+from hi.apps.attribute.value_ranges import PredefinedValueRanges
Label = 'Security'
@@ -10,7 +11,7 @@ class SecuritySetting( SettingEnum ):
label = 'Security Day Start',
description = 'Determines what time of day to switch to the "Day" security posture.',
value_type = AttributeValueType.ENUM,
- value_range_str = 'hi.datetime.time-of-day',
+ value_range_str = PredefinedValueRanges.TIME_OF_DAY_CHOICES_ID,
is_editable = True,
is_required = True,
initial_value = '08:00',
@@ -20,7 +21,7 @@ class SecuritySetting( SettingEnum ):
label = 'Security Night Start',
description = 'Determines what time of day to switch to the "Night" security posture.',
value_type = AttributeValueType.ENUM,
- value_range_str = 'hi.datetime.time-of-day',
+ value_range_str = PredefinedValueRanges.TIME_OF_DAY_CHOICES_ID,
is_editable = True,
is_required = True,
initial_value = '23:00',