Skip to content

Commit

Permalink
Fix examples (#457)
Browse files Browse the repository at this point in the history
Fix the readme example to be runnable + minor fixes to satisfy mypy
  • Loading branch information
baodrate authored Jun 7, 2024
1 parent f47b4b8 commit c59ecdd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ See the [github project](https://github.com/allenporter/pyrainbird).

This is an example usage to get the current irrigation state for all available
irrigation zones:
```
```python
import asyncio
import aiohttp
from pyrainbird import async_client

async with aiohttp.ClientSession() as client:
controller: AsyncRainbirdController = async_client.CreateController(
client,
"192.168.1.1",
"password"
)
zones = await controller.get_available_stations()
states = await controller.get_zone_states()
for zone in zones:
if zone in states.active_set:
print("Sprinkler zone {zone} is active")
async def main() -> None:
async with aiohttp.ClientSession() as client:
controller: async_client.AsyncRainbirdController = async_client.CreateController(
client,
"192.168.1.1",
"password"
)
zones = await controller.get_available_stations()
states = await controller.get_zone_states()
for zone in zones.active_set:
print(f"Sprinkler zone {zone}: {"active" if zone in states.active_set else "inactive"}")

asyncio.run(main())
```

See [examples](examples/) for additional details on how to use the APIs and an example command
Expand Down
2 changes: 2 additions & 0 deletions examples/mitm_rainbird.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from mitmproxy import contentviews, flow, http

import pyrainbird
import pyrainbird.encryption
from pyrainbird import rainbird


Expand Down Expand Up @@ -79,6 +80,7 @@ def render_priority(
return 0
if content_type != "application/octet-stream":
return 0
assert isinstance(flow, http.HTTPFlow)
if flow.request:
if "/stick" in flow.request.path:
return 1
Expand Down
4 changes: 2 additions & 2 deletions pyrainbird/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ class ModelAndVersion:
model: int
"""The device model number hex code."""

major: str
major: int
"""The major version string."""

minor: str
minor: int
"""The minor version string."""

@property
Expand Down

0 comments on commit c59ecdd

Please sign in to comment.