homewizard / python-homewizard-energy

HomeWizard Energy API implementation in Python. Designed for Home Assistant but can be used for any Async application.
https://api-documentation.homewizard.com
Apache License 2.0
14 stars 4 forks source link

Example code #321

Closed cambronf closed 9 months ago

cambronf commented 9 months ago

I have issues to run the example under Python 3.9 (and 3.11). Code was updated to:

import asyncio
from homewizard_energy import HomeWizardEnergy

IP_ADDRESS = "192.168.1.60"

async def main():

    async with HomeWizardEnergy(host=IP_ADDRESS) as api:

        print(await api.identify())
        print(await api.device())
        print(await api.data())

        await api.state_set(power_on=True)

asyncio.run(main())

Output of .identify, .device and .data is OK, but await api.state_set(power_on=True) is causing following error:

Traceback (most recent call last):
  File "/home/openhabian/digMeterHW.py", line 17, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/openhabian/digMeterHW.py", line 15, in main
    await api.state_set(power_on=True)
  File "/home/openhabian/.local/lib/python3.9/site-packages/homewizard_energy/homewizard_energy.py", line 33, in wrapper
    raise UnsupportedError(f"{func.__name__} is not supported") from ex
homewizard_energy.errors.UnsupportedError: state_set is not supported

Calling state_set without any argument give no errors, but the expected output is: "At least one state update is required"

Is the state_power call necessary? What is the purpose of this call, as everything works fine with out this call.

DCSBL commented 9 months ago

Hi! Do you try to turn on a P1 Meter?

The state_set call is only supported for the HWE-SKT (Energy Socket), to turn on and off the relay. See https://api-documentation.homewizard.com/docs/endpoints/api-v1-state

DCSBL commented 9 months ago

Maybe this can help preventing confusion like that; https://github.com/homewizard/python-homewizard-energy/pull/326 ?