"""
Data model for IoT sensors.
"""
import os, json

iot_data = {
  "ext_temp": 0,
  "int_temp": 0,
  "ext_hum": 0,
  "int_hum": 0,
  "rain": 0
}
DATA_FILE = "/home/nedi/iap1-labs/lab4/iot_data.json"

def load_data(path):
    if os.path.exists(path):
        with open(path, "r") as f:
            stored = json.load(f)
        for key in set(iot_data.keys()):
            if key in stored:
                iot_data[key] = stored[key]

load_data("/home/nedi/iap1-labs/lab4/iot_data.json")

def save_data(path):
    with open(path, "w") as f:
        json.dump(iot_data, f, indent=2)

def fetch_iot_data():
    return iot_data


def set_iot_data(data):
    # TODO: update the dictionary with the new data
    iot_data.update(data)
    pass
