dreautall / stromnetzgraz Goto Github PK
View Code? Open in Web Editor NEWPython client library for Stromnetz Graz API
License: MIT License
Python client library for Stromnetz Graz API
License: MIT License
The example is not working anymore with new python3...It took me a while to figure out new syntax.
If someone needs...or maybe @dreautall you update example:
#!/usr/bin/env python3
import asyncio, aiohttp
from src.sngraz import StromNetzGraz
async def get_sngrazdata():
print("Starting sngraz...")
sn = StromNetzGraz('email', 'password')
await sn.authenticate()
await sn.update_info()
for installation in sn.get_installations():
print("Installation ID", installation._installation_id)
print("Installation is installed at", installation._address)
for meter in installation.get_meters():
print("Meter ID", meter.id)
print(" Meter Name", meter._short_name)
await meter.fetch_consumption_data()
# meter._data now contains the meter readings of the last 30 days
print(meter._data)
await sn.close_connection()
print("End sngraz...")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(get_sngrazdata())
On my smart meter installation the first reading request seems to fail all the time, because of my readings available since.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/sngraz/sngraz.py", line 107, in _query
result = await resp.json()
File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1103, in json
raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://webportal.stromnetz-graz.at/api/getMeterReading')
My reading available since is:
readingsAvailableSince: 2022-04-12T12:49:00
If i correctly understand your code that the first reading makes following requests:
Opt-In
{
"meterPointId": xxx,
"fromDate": "2022-04-12T12:49:00.000+01:00",
"toDate": "2022-04-19T12:49:00.000+01:00",
"interval": "QuarterHourly",
"unitOfConsump": "KWH"
}
Which fails with error request rejected. If i change the time to 12:00 or 12:45 the request succeeds.
I opted in yesterday, but had the same problem before with "Opt-Middle". But i can't reproduce the error in this case, because the requests are working:
{
"meterPointId": xxx,
"fromDate": "2022-04-12T12:49:00.000+01:00",
"toDate": "2022-04-19T00:00:00.000+01:00",
"interval": "Daily",
"unitOfConsump": "KWH"
}
I just discovered your client library, and it works wonderful with my user data.
I would love to have that data available in Home-Assistant, the software for home automation.
Maybe you already have a WIP of some kind of Data-Logger already in use?
If nothing like that exists yet, I would be very interested to develop something.
It looks pretty easy to add Python Scripts to the Home-Assistant.
hi,
thx for your awesome library!
it seems i've a hard time getting it to work, i always get "login failed" even with the correct user/pw.
with the example code i get
File "/home/user/.cache/pypoetry/virtualenvs/stromnetz-graz-cli-oyNzUIS4-py3.11/lib/python3.11/site-packages/sngraz/sngraz.py", line 155, in authenticate
raise Exception("login failed")
Exception: login failed
But email/pw is correct, when i print out the token in function authenticate:152
i get
jwt.decode('e...Q', options={"verify_signature": False, "verify_exp": True})
{'email': MY_EMAIL, 'iat': 1681232478, 'exp': 1681318878}
if i simply remove the self.ok
check in authenticate:153
i get
Error connecting to API, response code 401
any idea what could be wrong?
sw version from pyprojects.toml
[tool.poetry.dependencies]
python = "^3.11"
aiohttp = "^3.8"
jwt = "^1.3"
stromnetzgraz = "^0.1.5"
resolved dependencies
aiohttp 3.8.4 Async http client/server framework (asyncio)
aiosignal 1.3.1 aiosignal: a list of registered asynchronous callbacks
async-timeout 4.0.2 Timeout context manager for asyncio programs
attrs 22.2.0 Classes Without Boilerplate
cffi 1.15.1 Foreign Function Interface for Python calling C code.
charset-normalizer 3.1.0 The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet.
cryptography 40.0.1 cryptography is a package which provides cryptographic recipes and primitives to Python developers.
frozenlist 1.3.3 A list-like structure which implements collections.abc.MutableSequence
idna 3.4 Internationalized Domain Names in Applications (IDNA)
jwt 1.3.1 JSON Web Token library for Python 3.
multidict 6.0.4 multidict implementation
pycparser 2.21 C parser in Python
stromnetzgraz 0.1.5 Python client library for Stromnetz Graz API
yarl 1.8.2 Yet another URL library
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.