Notification rework - Apprise v1 - working

This commit is contained in:
Jokob-sk
2023-10-08 14:52:22 +11:00
parent 79c47015f4
commit be4e0acdfc
11 changed files with 152 additions and 182 deletions

View File

@@ -244,27 +244,24 @@ def write_file(pPath, pText):
# Return whole setting touple
def get_setting(key):
settingsFile = apiPath + '/table_settings.json'
settingsFile = apiPath + 'table_settings.json'
try:
with open(settingsFile, 'r') as json_file:
data = json.load(json_file)
# if not isinstance(data, list):
# mylog('minimal', [f' [Settings] Data is not a list of dictionaries (file: {settingsFile})'])
for item in data.get("data",[]):
if item.get("Code_Name") == key:
return item
mylog('minimal', [f'[Settings] Error - setting_missing - Setting not found for key: {key} in file {settingsFile}'])
mylog('debug', [f'[Settings] Error - setting_missing - Setting not found for key: {key} in file {settingsFile}'])
return None
except (FileNotFoundError, json.JSONDecodeError, ValueError) as e:
# Handle the case when the file is not found, JSON decoding fails, or data is not in the expected format
mylog('minimal', [f'[Settings] Error - JSONDecodeError or FileNotFoundError for file {settingsFile}'])
mylog('none', [f'[Settings] Error - JSONDecodeError or FileNotFoundError for file {settingsFile}'])
return None
@@ -274,19 +271,32 @@ def get_setting(key):
# Return setting value
def get_setting_value(key):
set = get_setting(key)
setting = get_setting(key)
if get_setting(key) is not None:
if setting is not None:
setVal = set["Value"] # setting value
setTyp = set["Type"] # setting type
set_value = setting["Value"] # Setting value
set_type = setting["Type"] # Setting type
return setVal
# Handle different types of settings
if set_type in ['text', 'string', 'password', 'readonly', 'text.select']:
return str(set_value)
elif set_type in ['boolean', 'integer.checkbox']:
return bool(set_value)
elif set_type in ['integer.select', 'integer']:
return int(set_value)
elif set_type in ['text.multiselect', 'list', 'subnets']:
# Assuming set_value is a list in this case
return set_value
elif set_type == '.template':
# Assuming set_value is a JSON object in this case
return json.loads(set_value)
return ''
#-------------------------------------------------------------------------------
# IP validation methods
#-------------------------------------------------------------------------------