Skip to content

Commit 7c84be9

Browse files
psaffreyVilppu Vuorinen
authored andcommitted
amend README to include complete asyncio code
1 parent b1c5304 commit 7c84be9

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,27 @@ returned by `zones` property on `AtwDevice`.
163163
## Example usage
164164

165165
```python
166-
>>> import pymelcloud
167-
>>> token = await pymelcloud.login("[email protected]", "password")
168-
>>> devices = await pymelcloud.get_devices(token)
169-
>>> device = devices[pymelcloud.DEVICE_TYPE_ATA][0]
170-
>>> await device.update()
171-
>>> device.name
172-
'Heat Pump 1'
173-
>>> device.target_temperature
174-
21.0
175-
>>> device.set({"target_temperature": 21.5})
176-
>>> >>> device.target_temperature
177-
21.5
166+
import aiohttp
167+
import asyncio
168+
import pymelcloud
169+
170+
171+
async def main():
172+
173+
async with aiohttp.ClientSession() as session:
174+
# call the login method with the session
175+
token = await pymelcloud.login("[email protected]", "mysecretpassword", session=session)
176+
177+
# lookup the device
178+
devices = await pymelcloud.get_devices(token, session=session)
179+
device = devices[pymelcloud.DEVICE_TYPE_ATW][0]
180+
181+
# perform logic on the device
182+
await device.update()
183+
184+
print(device.name)
185+
await session.close()
186+
187+
loop = asyncio.get_event_loop()
188+
loop.run_until_complete(main())
178189
```

0 commit comments

Comments
 (0)