-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path__init__.py
79 lines (63 loc) · 2.3 KB
/
__init__.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
"""
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/
"""
from datetime import timedelta
import logging
from .config import MercedesMeConfig
from .oauth import MercedesMeOauth
from .resources import MercedesMeResources
from .const import *
# Logger
_LOGGER = logging.getLogger(__name__)
class MercedesMeData:
########################
# Init
########################
def __init__(self, hass, config):
# Configuration Data
self.mercedesConfig = MercedesMeConfig(hass, config)
# Resource Data
self.mercedesResources = MercedesMeResources(self.mercedesConfig)
########################
# Update State
########################
def UpdateState(self, event_time):
_LOGGER.debug ("Start Update Resources")
self.mercedesResources.UpdateResourcesState()
#hass.helpers.dispatcher.dispatcher_send(UPDATE_SIGNAL)
_LOGGER.debug ("End Update")
########################
# Update Token
########################
def UpdateToken(self, event_time):
_LOGGER.debug ("Start Refresh Token")
self.mercedesConfig.token.RefreshToken()
#hass.helpers.dispatcher.dispatcher_send(UPDATE_SIGNAL)
_LOGGER.debug ("End Refresh Token")
########################
# Setup
########################
#async def async_setup(hass, config):
def setup(hass, config):
# Creating Data Structure
data = MercedesMeData(hass, config)
hass.data[DOMAIN] = data
# Reading Configuration
if not data.mercedesConfig.ReadConfig():
_LOGGER.error ("Error initializing configuration")
return False
if not data.mercedesResources.ReadResources():
_LOGGER.error ("Error initializing resources")
return False
# Create Task to initializate Platform Sensor
hass.async_create_task(
hass.helpers.discovery.async_load_platform("sensor", DOMAIN, {}, config)
)
# Create Task to Update Status
hass.helpers.event.track_time_interval(data.UpdateState, timedelta(seconds=data.mercedesConfig.scan_interval))
# Create Task to Update Token
hass.helpers.event.track_time_interval(data.UpdateToken, timedelta(seconds=data.mercedesConfig.token.token_expires_in))
return True