# mercedes_me_api
-[![License Status][license-img]][license-url]
[![Releases][releases-img]][releases-url]
[![Last Commit][last-commit-img]][last-commit-url]
[![hacs][hacs-img]][hacs-url]
+[![License Status][license-img]][license-url]
[![BuyMeCoffee][buymecoffee-img]][buymecoffee-url]
Script to use Mercedes Me APIs.
For more details about this component, please refer to the documentation at
https://github.com/xraver/mercedes_me_api/
"""
-from datetime import timedelta
+from datetime import datetime
import logging
import json
import os
self._state = state
self._timestamp = timestamp
self._valid = valid
+ if(timestamp != None):
+ self._lastupdate = datetime.fromtimestamp(self._timestamp/1000)
+ else:
+ self._lastupdate = 0
def __str__(self):
return json.dumps({
"valid" : self._valid,
})
+ def UpdateState(self, state, timestamp):
+ """Update status of the resource."""
+ self._state = state
+ self._timestamp = timestamp
+ self._lastupdate = datetime.fromtimestamp(self._timestamp/1000)
+ self._valid = True
+
@property
def name(self):
"""Return the name of the sensor."""
return ({
"valid": self._valid,
"timestamp": self._timestamp,
+ "last_update": self._lastupdate,
})
# @property
print ("\tvalid: " + str(res._valid))
print ("\tstate: " + res._state)
print ("\ttimestamp: " + str(res._timestamp))
+ print ("\tlast_update: " + str(res._lastupdate))
########################
# Update Resources State
for res in self.database:
result = GetResource(URL_RES_PREFIX + res._href, self.mercedesConfig)
if not "reason" in result:
- res._valid = True
- res._timestamp = result[res._name]["timestamp"]
- res._state = result[res._name]["value"]
+ res.UpdateState(result[res._name]["value"], result[res._name]["timestamp"])
# Write Resource File
self.WriteResourcesFile()
For more details about this component, please refer to the documentation at
https://github.com/xraver/mercedes_me_api/
"""
+from datetime import datetime
import logging
import json
import os
self._state = state
self._timestamp = timestamp
self._valid = valid
+ if(timestamp != None):
+ self._lastupdate = datetime.fromtimestamp(self._timestamp/1000)
+ else:
+ self._lastupdate = 0
def __str__(self):
return json.dumps({
"valid" : self._valid,
})
+ def UpdateState(self, state, timestamp):
+ """Update status of the resource."""
+ self._state = state
+ self._timestamp = timestamp
+ self._lastupdate = datetime.fromtimestamp(self._timestamp/1000)
+ self._valid = True
+
def name(self):
"""Return the name of the sensor."""
return self._vin + "_" + self._name
return ({
"valid": self._valid,
"timestamp": self._timestamp,
+ "last_update": self._lastupdate,
})
def update(self):
"""Fetch new state data for the sensor."""
result = GetResource(URL_RES_PREFIX + self._href, self._config)
if not "reason" in result:
- self._valid = True
- self._timestamp = result[self._name]["timestamp"]
self._state = result[self._name]["value"]
+ self._timestamp = result[self._name]["timestamp"]
+ self._lastupdate = datetime.fromtimestamp(self._timestamp/1000)
+ self._valid = True
class MercedesMeResources:
print ("\tvalid: " + str(res._valid))
print ("\tstate: " + res._state)
print ("\ttimestamp: " + str(res._timestamp))
+ print ("\tlast update: " + str(res._lastupdate))
########################
# Update Resources State
for res in self.database:
result = GetResource(URL_RES_PREFIX + res._href, self.mercedesConfig)
if not "reason" in result:
- res._valid = True
- res._timestamp = result[res._name]["timestamp"]
- res._state = result[res._name]["value"]
+ res.update(result[res._name]["value"], result[res._name]["timestamp"])
# Write Resource File
self.WriteResourcesFile()