Skip to content

Commit

Permalink
Merge pull request #13 from bj00rn/vnext
Browse files Browse the repository at this point in the history
Vnext
  • Loading branch information
bj00rn authored Dec 23, 2024
2 parents d1ab847 + a15f68a commit c533580
Show file tree
Hide file tree
Showing 19 changed files with 586 additions and 726 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
"--port",
"3001"
]
},
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"--no-cov",
"-o",
"log_cli=1",
"--timeout=30",
"--timeout=300",
"--verbose",
"--import-mode=prepend",
],
"autoDocstring.docstringFormat": "sphinx"
}
63 changes: 11 additions & 52 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,70 +29,29 @@ Supported devices

LOKE1/Loke Basic/LS-01 using control system 4.1.5

Usage with asyncio as library
Example usage
=============================


Read data
---------

.. code-block:: python3
import asyncio
import aiohttp
from pysaleryd.client import Client
async def work():
async with aiohttp.ClientSession() as session:
async with Client(WEBSOCKET_URL, WEBSOCKET_PORT, session) as hrv_client:
await asyncio.sleep(2) # wait a bit for some data
print(client.data)
loop = asyncio.new_event_loop()
loop.run_until_complete(work())
Read data using callback
------------------------

.. code-block:: python3
import asyncio
import aiohttp
from pysaleryd.client import Client
from pysaleryd.const import DataKey
def handle_message(data: dict):
# must be safe to call from event loop
print("message handler")
print(data)
async def work():
update_interval = 10 # call handle_message every 30 seconds
async with aiohttp.ClientSession() as session:
async with Client(WEBSOCKET_URL, WEBSOCKET_PORT, session, update_interval) as hrv_client:
hrv_client.add_handler(handle_message)
await asyncio.sleep(update_interval +1 ) # wait around a bit for data
loop = asyncio.new_event_loop()
loop.run_until_complete(work())
Send control command
--------------------
Command syntax can be found by dissecting websocket messages in the built in web ui

.. code-block:: python3
import asyncio
import aiohttp
from pysaleryd.client import Client
async def work():
async with aiohttp.ClientSession() as session:
async with Client(WEBSOCKET_URL, WEBSOCKET_PORT, session) as hrv_client:
await hrv_client.send_command("MF", 1)
async def main():
update_interval = 10
with Client("192.168.1.151", update_interval=update_interval) as hrv_client:
hrv_client.add_message_handler(handle_message)
await asyncio.sleep(update_interval +1 ) # wait around a bit for data
await hrv_client.send_command(DataKey.FIREPLACE_MODE, 1) # turn on fireplace mode
loop = asyncio.new_event_loop()
loop.run_until_complete(work())
loop.run_until_complete(main())
Troubleshooting
===============
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ known_first_party = ["pysaleryd"]
profile = "black"

[tool.pysaleryd]
version = "6.0.2"
version = "7.0.0-rc.0"
8 changes: 5 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ python_requires = >=3.11
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.11"
aiohttp
websockets>=14.1,<15


[options.packages.find]
Expand Down Expand Up @@ -77,8 +77,8 @@ testing =
# console_scripts =
# script_name = pysaleryd.module:function
# For example:
console_scripts =
pysaleryd = pysaleryd.skeleton:run
# console_scripts =
# pysaleryd = pysaleryd.skeleton:run
# And any other entry points, for example:
# pyscaffold.cli =
# awesome = pyscaffoldext.awesome.extension:AwesomeExtension
Expand All @@ -91,6 +91,8 @@ console_scripts =
# in order to write a coverage file that can be read by Jenkins.
# CAUTION: --cov flags may prohibit setting breakpoints while debugging.
# Comment those flags to avoid this pytest issue.
# asyncio_mode = auto
# asyncio_default_fixture_loop_scope = session
addopts =
--cov pysaleryd --cov-report term-missing
--verbose --timeout 30
Expand Down
Loading

0 comments on commit c533580

Please sign in to comment.