Git Product home page Git Product logo

Comments (4)

r-jordan avatar r-jordan commented on July 18, 2024 1

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.

r-jordan avatar r-jordan commented on July 18, 2024

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.

azogue avatar azogue commented on July 18, 2024

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.

r-jordan avatar r-jordan commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.