File tree Expand file tree Collapse file tree 3 files changed +49
-1
lines changed
Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change 1+ """PyMelcloud examples."""
Original file line number Diff line number Diff line change 1+ """Asynchronous Python client for MELCloud. This is an example file."""
2+
3+ import asyncio
4+ import logging
5+
6+ import aiohttp
7+ import pymelcloud
8+
9+ logging .basicConfig (level = logging .INFO )
10+ logger = logging .getLogger (__name__ )
11+
12+
13+ async def main () -> None :
14+ """Demonstrate the usage of pymelcloud.
15+
16+ This function logs in to the MELCloud service, retrieves a list of devices,
17+ and performs operations on a specific device. It uses an asynchronous
18+ HTTP session for communication.
19+
20+ Raises
21+ ------
22+ ValueError: If login fails due to invalid credentials or other issues.
23+ """
24+ async with aiohttp .ClientSession () as session :
25+ try :
26+ # Call the login method with the session
27+ token = await pymelcloud .login (
28+ "[email protected] " ,
"mysecretpassword" ,
session = session 29+ )
30+ logger .info ("Login successful, token: %s" , token )
31+ except ValueError :
32+ logger .exception ("Login failed" )
33+ return
34+
35+ # Lookup the device
36+ devices = await pymelcloud .get_devices (token , session = session )
37+ device = devices [pymelcloud .DEVICE_TYPE_ATW ][0 ]
38+
39+ # Perform logic on the device
40+ await device .update ()
41+
42+ logger .info ("Device name: %s" , device .name )
43+ await session .close ()
44+
45+
46+ if __name__ == "__main__" :
47+ asyncio .run (main ())
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ ignore-imports = true
107107max-line-length = 88
108108
109109[tool .pytest .ini_options ]
110- addopts = " --cov"
110+ addopts = " --cov --cov-fail-under=60 " # Fice for now, since this is how the project was inherited
111111asyncio_mode = " auto"
112112
113113[tool .ruff ]
You can’t perform that action at this time.
0 commit comments