-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Sonnen battery API as an additional data source
- Loading branch information
Showing
4 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import logging | ||
import requests | ||
import configparser | ||
import json | ||
|
||
class Sonnen: | ||
def __init__( | ||
self, | ||
configFileName: str | ||
) -> None: | ||
|
||
self.logger = logging.getLogger("Sonnen") | ||
|
||
configParser = configparser.ConfigParser() | ||
configParser.read(configFileName) | ||
|
||
apiUrl = configParser.get("Sonnen", "ApiUrl") | ||
ip = configParser.get("Sonnen", "IP") | ||
port = configParser.get("Sonnen", "Port") | ||
|
||
self.apiUrl = apiUrl.replace("{{IP}}", ip).replace("{{PORT}}", port) | ||
|
||
def __del__(self) -> None: | ||
self.logger.info("Del") | ||
|
||
def get_current_state(self) -> None: | ||
self.logger.info("Get current state") | ||
|
||
response = requests.get(self.apiUrl) | ||
jsonString = response.text | ||
|
||
self.logger.debug(f"JSON: {jsonString}") | ||
|
||
apiData = json.loads(jsonString) | ||
|
||
result = dict() | ||
result["loadToGridPower"] = apiData["GridFeedIn_W"] / 1000 | ||
result["batteryChargeLevel"] = apiData["USOC"] | ||
|
||
return result |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters