Skip to content

Commit

Permalink
📦 NEW: get historical data
Browse files Browse the repository at this point in the history
  • Loading branch information
unl0ck committed Nov 25, 2024
1 parent 264ed83 commit a499493
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions viessmann_gridbox_connector/GridboxConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ def __init__(self, config):
self.login_body = config["login"]
self.gateway_url = config["urls"]["gateways"]
self.live_url = config["urls"]["live"]
self.historical_url = config["urls"]["historical"]
self.username = os.getenv('USERNAME', self.login_body["username"])
self.password = os.getenv('PASSWORD', self.login_body["password"])
self.init_auth()

def init_logging(self):
self.logger = logging.getLogger(__name__)
loglevel = os.getenv('LOG_LEVEL', 'DEBUG') # Default to DEBUG if LOGLEVEL is not set
loglevel = os.getenv('LOG_LEVEL', 'INFO')
self.logger.setLevel(logging.getLevelName(loglevel))
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(funcName)s - %(message)s')
console_handler = logging.StreamHandler()
Expand Down Expand Up @@ -86,8 +87,26 @@ def retrieve_live_data(self):
responses.append(response_json)
# print(response_json)
else:
self.logger.warn("Status Code {}".format(response.status_code))
self.logger.warn("Response {}".format(response.json()))
self.logger.warning("Status Code {}".format(response.status_code))
self.logger.warning("Response {}".format(response.json()))
except Exception as e:
self.logger.error(e)
return responses

def retrieve_historical_data(self, start, end, resolution='15m'):
responses = []

for id in self.gateways:
self.historical_url_created = self.historical_url.format(id, start, end, resolution)
try:
response = requests.get(self.historical_url_created, headers=self.get_header())
if response.status_code == 200:
response_json = response.json()
responses.append(response_json)
# print(response_json)
else:
self.logger.warning("Status Code {}".format(response.status_code))
self.logger.warning("Response {}".format(response.json()))
except Exception as e:
self.logger.error(e)
return responses
2 changes: 1 addition & 1 deletion viessmann_gridbox_connector/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"login": "https://gridx.eu.auth0.com/oauth/token",
"gateways": "https://api.gridx.de/gateways",
"live": "https://api.gridx.de/systems/{}/live",
"historical": "https://api.gridx.de/systems/{}/historical?interval={}&resolution={}"
"historical": "https://api.gridx.de/systems/{}/historical?interval={}/{}&resolution={}"
},
"login": {
"grant_type": "http://auth0.com/oauth/grant-type/password-realm",
Expand Down

0 comments on commit a499493

Please sign in to comment.