Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAN-8: Archivo de configuración #6

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"packet_period": 1,
"device_id": "97bebd21-a9c8-41a3-9a88-969cd3dd7bba",
"deviations": {
"temperature": 3,
"humidity": 5,
"light": 25,
"watering": 5
}
}
28 changes: 12 additions & 16 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'''

import time
import random
import logging
import json
import os
Expand Down Expand Up @@ -49,26 +48,23 @@ def simulate_packets(config):


def read_config_file(path):
'''
Reads the config file. At this moment, it is mocked.
'''
# TODO
return {
"packet_period": 1,
"device_id": str(random.getrandbits(128)),
"deviations": {
"temperature": 3,
"humidity": 5,
"light": 25,
"watering": 5
}
}
try:
with open(path, 'r') as file:
config_data = json.load(file)
return config_data
except FileNotFoundError:
logging.error(f"Config file not found at: {path}")
raise
except json.JSONDecodeError as json_err:
logging.error(f"Error decoding config file: {json_err}")
raise


def main():
logging_level = os.environ.get("LOGGING_LEVEL")
initialize_log(logging_level)
config = read_config_file("")
config_path = "config.json"
feijooso marked this conversation as resolved.
Show resolved Hide resolved
config = read_config_file(config_path)
simulate_packets(config)


Expand Down
Loading