-
Notifications
You must be signed in to change notification settings - Fork 14
/
config.py
68 lines (58 loc) · 1.97 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Mercedes Me APIs
Author: G. Ravera
For more details about this component, please refer to the documentation at
https://github.com/xraver/mercedes_me_api/
"""
import logging
import os
from configobj import ConfigObj
from const import *
from oauth import MercedesMeOauth
# Logger
_LOGGER = logging.getLogger(__name__)
class MercedesMeConfig:
########################
# Init
########################
def __init__(self):
self.config_file = CONFIG_FILE
########################
# Read Configuration
########################
def ReadConfig(self):
# Read Config from file
if not os.path.isfile(self.config_file):
_LOGGER.error(f"Credential File {self.config_file} not found")
return False
try:
f = ConfigObj(self.config_file)
except Exception:
_LOGGER.error(f"Wrong {self.config_file} file found")
return False
# Client ID
self.client_id = f.get(CONF_CLIENT_ID)
if not self.client_id:
_LOGGER.error(f"No {CONF_CLIENT_ID} found in the configuration")
return False
# Client Secret
self.client_secret = f.get(CONF_CLIENT_SECRET)
if not self.client_secret:
_LOGGER.error(f"No {CONF_CLIENT_SECRET} found in the configuration")
return False
# Vehicle ID
self.vin = f.get(CONF_VEHICLE_ID)
if not self.vin:
_LOGGER.error(f"No {CONF_VEHICLE_ID} found in the configuration")
return False
# Enable Resources File (optional)
valueFromFile = f.get(CONF_ENABLE_RESOURCES_FILE)
if (valueFromFile == "true") | (valueFromFile == "True"):
self.enable_resources_file = True
else:
self.enable_resources_file = False
# Read Token
self.token = MercedesMeOauth(self.client_id, self.client_secret)
if not self.token.ReadToken():
return False
return True