Skip to content

Commit

Permalink
📦 NEW: added CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
unl0ck committed Jun 1, 2024
1 parent 56c6ec7 commit 5a126e9
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 55 deletions.
84 changes: 39 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
# Viessmann Gridbox Connector

### **<h3 style="text-align: center;">This is not an official Viessmann library</h3>**

a GridboxConnector Lib to fetch your Data from the Cloud.
It is using the same Rest-API like the Dashboard and the App.
Harness the power of your photovoltaic system with the GridboxConnector library. This versatile tool taps into the same REST API as the official dashboard and app, providing you with direct access to your data from the cloud.<br>

Whether you're a developer looking to integrate solar data into your own project, or a power user seeking command-line access, GridboxConnector has you covered. With its dual functionality, you can either embed it into your Python project as a library or use it as a standalone command-line interface (CLI) tool.<br>

**Take control of your solar data with GridboxConnector, and unlock the full potential of your photovoltaic system.**<br><br>
![Screenshot vom mygridbox](images/screenshot.png)

## Installation

```script shell
pip install viessmann-gridbox-connector
```
Set your email and password in the config.json.
Use your Login Data from the App or from https://mygridbox.viessmann.com/login

### Setup the python environment and install all dependencies
## Usage

You can use the CLI to retrieve live data from the Viessmann Gridbox API or use the GridboxConnector class in your own code. <br>
Use your Login data from the App or from https://mygridbox.viessmann.com/login

### CLI

```script shell
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
pip install viessmann-gridbox-connector
viessmann --username <username> --password <password>
```

### in your code

```python
from viessmann_gridbox_connector import GridboxConnector
from importlib.resources import path
import json

with path('viessmann_gridbox_connector', 'config.json') as config_file:
with open(config_file, 'r') as file:
data = json.load(file)
data["login"]["username"] = "username"
data["login"]["password"] = "password"
connector = GridboxConnector(data)
# Retrieve live data
live_data = connector.retrieve_live_data()
print(live_data)
```

### Example Output

```script json
{
"consumption": 496,
Expand All @@ -43,44 +70,12 @@ pip install -r requirements.txt
}
```

# Usage
```python
from gridbox_connector import GridboxConnector

# Initialize the connector with your configuration
config = {
"urls": {
"login":"https://gridx.eu.auth0.com/oauth/token",
"gateways":"https://api.gridx.de/gateways",
"live":"https://api.gridx.de/systems/{}/live"
},
"login":{
"grant_type":"http://auth0.com/oauth/grant-type/password-realm",
"username":"email",
"password":"password",
"audience":"my.gridx",
"client_id":"oZpr934Ikn8OZOHTJEcrgXkjio0I0Q7b",
"scope":"email openid",
"realm":"viessmann-authentication-db"
}
}

connector = GridboxConnector(config)
## Dependencies

# Retrieve live data
live_data = connector.retrieve_live_data()
print(live_data)
- requests

```
# Configuration
You need to provide a configuration dictionary with the following keys:
## Contributing

urls: Dictionary containing endpoint URLs.
login: Dictionary containing login credentials.

# Dependencies
requests
# Contributing
If you'd like to contribute to viessmann-gridbox-connector, please follow these steps:

Fork the repository.
Expand All @@ -89,7 +84,6 @@ Make your changes and write tests if possible.
Run tests and ensure they pass.
Submit a pull request.


# License
## License

This project is licensed under the MIT License - see the LICENSE file for details.
18 changes: 11 additions & 7 deletions read_live_data.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from gridbox_connector import GridboxConnector
from viessmann_gridbox_connector import GridboxConnector
from importlib.resources import path
import json

with open('config.json', 'r') as file:
data = json.load(file)
connector = GridboxConnector(data)
# Retrieve live data
live_data = connector.retrieve_live_data()
print(live_data)
with path('viessmann_gridbox_connector', 'config.json') as config_file:
with open(config_file, 'r') as file:
data = json.load(file)
data["login"]["username"] = "username"
data["login"]["password"] = "password"
connector = GridboxConnector(data)
# Retrieve live data
live_data = connector.retrieve_live_data()
print(live_data)
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@
install_requires=[
'requests'
],
package_data={
'viessmann_gridbox_connector': ['config.json'],
},
entry_points={
'console_scripts': [
'viessmann=viessmann_gridbox_connector.cli:main',
],
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, config):

def init_logging(self):
self.logger = logging.getLogger(__name__)
loglevel = os.getenv('LOGLEVEL', 'DEBUG') # Default to DEBUG if LOGLEVEL is not set
loglevel = os.getenv('LOG_LEVEL', 'DEBUG') # Default to DEBUG if LOGLEVEL is not set
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
File renamed without changes.
27 changes: 27 additions & 0 deletions viessmann_gridbox_connector/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import argparse
from viessmann_gridbox_connector import GridboxConnector
from importlib.resources import path
import json

def retrieve_live_data(username, password):
with path('viessmann_gridbox_connector', 'config.json') as config_file:
with open(config_file, 'r') as file:
data = json.load(file)
data["login"]["username"] = username
data["login"]["password"] = password
connector = GridboxConnector(data)
# Retrieve live data
live_data = connector.retrieve_live_data()
return live_data

def main():
parser = argparse.ArgumentParser(description='Retrieve live data from Viessmann Gridbox.')
parser.add_argument('-u', '--username', required=True, help='The username to use.')
parser.add_argument('-p', '--password', required=True, help='The password to use.')
args = parser.parse_args()

live_data = retrieve_live_data(args.username, args.password)
print(live_data)

if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions config.json → viessmann_gridbox_connector/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"login": {
"grant_type": "http://auth0.com/oauth/grant-type/password-realm",
"username": "[email protected]",
"password": "Simon1991!",
"username": "username",
"password": "password!",
"audience": "my.gridx",
"client_id": "oZpr934Ikn8OZOHTJEcrgXkjio0I0Q7b",
"scope": "email openid",
Expand Down

0 comments on commit 5a126e9

Please sign in to comment.