class

import json


class DeviceConfigManager:

    _deviceConfig = None

    def __init__(self):
        if self._deviceConfig is None:
            self._deviceConfig = self.load()

    def get(self, *inherit_keys):
        if inherit_keys is None or 0 == len(inherit_keys):
            return self._deviceConfig
        sc = self._deviceConfig
        for key in inherit_keys:
            sc = sc[key]
        return sc

    def update(self, value, *inherit_keys):
        pass
        # if inherit_keys is None or 0 == len(inherit_keys):
        #     raise 'inherit_keys can\'t empty'
        # current_key_config = self._deviceConfig
        # for i in range(0, len(inherit_keys)):
        #     key = inherit_keys[i]
        #     if type(current_key_config) == dict and key not in current_key_config:
        #         if i == len(inherit_keys) - 1:
        #             current_key_config[key] = value
        #         else:
        #             current_key_config[key] = {}
        #     else:
        #     current_key_config = current_key_config[key]


    def load(self):
        device_config = None
        with open('learn/demo_class/device_config.json', 'r') as device_config_file:
            device_config = json.load(device_config_file)
        return device_config

if __name__ == '__main__':
    device_config_manager = DeviceConfigManager()
    print(device_config_manager)
    print(device_config_manager.get())
    print(device_config_manager.get('wifi_config'))
    print(device_config_manager.get('wifi_config', 'ssid'))
    print(device_config_manager.get('wifi_config', 'password'))
    print(DeviceConfigManager.get('wifi_config', 'password'))