Comments (4)
Hi @azogue,
Thanks to your instructions, finally, I succeed making the test script 🎉 😄
I'm sure this is not any great success for an experimenter python developer but for me it's challenging 🤦♂️
This is the most simple python code to test the library integration with HA that I made:
from aiopvpc import PVPCData
from datetime import datetime
import asyncio
import aiohttp
async def main():
async with aiohttp.ClientSession() as session:
pvpc_handler = PVPCData(tariff="discrimination", websession=session )
await pvpc_handler.async_update_prices( datetime.now() )
pvpc_handler.process_state_and_attributes( datetime.now() )
print( pvpc_handler.state )
print( pvpc_handler.attributes )
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
The following is the result at the moment of executing it with the printing of the state and the attributes:
0.23482
{'attribution': 'Data retrieved from api.esios.ree.es by REE', 'tariff': '2.0TD', 'min_price': 0.09614, 'min_price_at': 4, 'next_best_at': [16, 17, 15, 14, 23, 22, 13, 18, 12, 19, 21, 20], 'price_00h': 0.10981, 'price_01h': 0.10678, 'price_02h': 0.10105, 'price_03h': 0.09804, 'price_04h': 0.09614, 'price_05h': 0.09934, 'price_06h': 0.10902, 'price_07h': 0.11468, 'price_08h': 0.15268, 'price_09h': 0.14259, 'price_10h': 0.23373, 'price_11h': 0.23414, 'price_12h': 0.23482, 'price_13h': 0.23409, 'price_14h': 0.14089, 'price_15h': 0.13898, 'price_16h': 0.13749, 'price_17h': 0.13762, 'price_18h': 0.23436, 'price_19h': 0.24117, 'price_20h': 0.24423, 'price_21h': 0.24247, 'price_22h': 0.15115, 'price_23h': 0.14768}
from aiopvpc.
I cloned the git repository and when I try the following test code using python version 3.8.10 (example in the README):
from aiopvpc import PVPCData
pvpc_handler = PVPCData(tariff="discrimination")
start = datetime(2020, 3, 20, 22)
end = datetime(2020, 4, 30, 16)
prices_range: dict = await pvpc_handler.async_download_prices_for_range(start, end)
I get the following error message:
File "test.py", line 7
prices_range: dict = await pvpc_handler.async_download_prices_for_range(start, end)
^
SyntaxError: 'await' outside function
from aiopvpc.
Hi @r-jordan, this is an async library (the "a" in aiopvpc
😜), so most methods are actually coroutines which need to be awaited...
(there is a lot of info out there about concurrency in Python, try this: https://realpython.com/async-io-python/)
The README example is intended for jupyter
users 😊, where there is an event loop running and you can await subroutines directly.
To call it from a script you would need to use asyncio.run(pvpc_handler.async_download_prices_for_range(start, end)
, or just use the blocking method of the PVPCData
class: pvpc_handler.download_prices_for_range(start, end)
😝
About the setup environment, everything you need to know is inside the pyproject.toml
, and you'll need poetry
to install it.
I would like to add some new calculated attributes
About new sensor attributes, please take a look into #21 and feel free to comment or suggest about other attributes :)
from aiopvpc.
Hi @azogue , it's public that my knowledge of the asyncio library nor python development with poetry is not very high, I'm sorry 🙏
I'll try to learn about all those things and I'll come back if I have more questions.
Anyway, I'm going to suggest one new attribute in #21 👍
Thank you!
from aiopvpc.
Related Issues (20)
- Atributo para obtener el precio actual HOT 8
- Node red integration HOT 2
- Attributes are referred to current and next_day prices HOT 2
- ¿No hay problema de no utilizar token? HOT 1
- No funciona la integración con HA desde el 2 de noviembre HOT 30
- Include self-consumption values HOT 1
- Sensor unavailable desde 02/11 (con actualización) HOT 4
- sensor.pvpc: repeated bad data update, mark component as unavailable source HOT 13
- Component errors in ha log HOT 4
- Sensor unit of measurement should use ISO 4217 monetary format HOT 1
- Recuperar datos que están a 0 por el fallo
- Detected code that uses str for device registry entry_type HOT 1
- Test failures with holidays-0.13 HOT 1
- Add gas compensation cost HOT 7
- Tag the source HOT 1
- aiopvpc - Repository structure for v4.1.0 is not compliant HOT 3
- openevse don't works in HA Hacs HOT 1
- Integrar precio excedentes de autoconsumo en el índice HOT 6
- Example provided results in error message HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiopvpc.