-
Notifications
You must be signed in to change notification settings - Fork 14
/
mercedes_me_api.py
110 lines (90 loc) · 2.66 KB
/
mercedes_me_api.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
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 argparse
import logging
import sys
from config import MercedesMeConfig
from const import *
from resources import MercedesMeResources
# Logger
_LOGGER = logging.getLogger(__name__)
class MercedesMeData:
def __init__(self):
# Configuration Data
self.mercedesConfig = MercedesMeConfig()
# Resource Data
self.mercedesResources = MercedesMeResources(self.mercedesConfig)
########################
# Parse Input
########################
def ParseInput():
parser = argparse.ArgumentParser()
parser.add_argument(
"-t",
"--token",
action="store_true",
help="Procedure to obtatin the Access Token",
)
parser.add_argument(
"-r",
"--refresh",
action="store_true",
help="Procedure to refresh the Access Token",
)
parser.add_argument(
"-s",
"--status",
action="store_true",
help="Retrieve the Status of your Vehicle",
)
parser.add_argument(
"-R",
"--resources",
action="store_true",
help="Retrieve the list of available resources of your Vehicle",
)
parser.add_argument(
"-v", "--version", action="version", version="%(prog)s " + VERSION
)
if len(sys.argv) == 1:
parser.print_help(sys.stderr)
exit(1)
return parser.parse_args()
########################
# Main
########################
if __name__ == "__main__":
# Reading Arguments
args = ParseInput()
# Creating Data Structure
data = MercedesMeData()
# Reading Configuration
if not data.mercedesConfig.ReadConfig():
_LOGGER.error("Error initializing configuration")
exit(1)
# Create Token
if args.token == True:
if not data.mercedesConfig.token.CreateToken():
_LOGGER.error("Error creating token")
exit(1)
# Refresh Token
if args.refresh == True:
if not data.mercedesConfig.token.RefreshToken():
_LOGGER.error("Error refreshing token")
exit(1)
# Read Resources
if (args.resources == True) | (args.status == True):
if not data.mercedesResources.ReadResources():
_LOGGER.error("Error initializing resources")
exit(1)
# Print Available Resources
if args.resources == True:
data.mercedesResources.PrintAvailableResources()
# Print Resources State
if args.status == True:
data.mercedesResources.UpdateResourcesState()
data.mercedesResources.PrintResourcesState()