Skip to content

Commit

Permalink
Introduce tools folder and fix verify.py (#497)
Browse files Browse the repository at this point in the history
* Introduce tools and fix verify.py

* black

* update README
  • Loading branch information
chemelli74 authored Feb 16, 2024
1 parent dba1205 commit f108ecd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,17 @@ The repository includes example script to quickly try it out.
### Connect to a device and print its status whenever we receive a state change:

```
python3 example.py -ip <ip> [-u <username>] [-p <password] -i
python3 tools/example.py -ip <ip> [-u <username>] [-p <password] -i
```

### Connect to all the devices in `devices.json` at once and print their status:

```
python3 example.py -d -i
python3 tools/example.py -d -i
```
### Show usage help:
```
python3 example.py -h
python3 tools/example.py -h
```

## Contribution guidelines
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 12 additions & 8 deletions verify.py → tools/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import urllib3
from aiohttp.helpers import reify

import aioshelly
from aioshelly.block_device import BLOCK_VALUE_UNIT, BlockDevice
from aioshelly.block_device.coap import CoapType
from aioshelly.common import ConnectionOptions
from aioshelly.const import DEVICE_IO_TIMEOUT

urllib3.disable_warnings()

Expand Down Expand Up @@ -40,7 +43,7 @@ def url(self):
@reify
def content(self):
"""Get file content."""
return requests.get(self.url, verify=False).text
return requests.get(self.url, timeout=DEVICE_IO_TIMEOUT, verify=False).text

@reify
def content_parsed(self):
Expand Down Expand Up @@ -85,9 +88,9 @@ def cit_d(self):
@reify
def device(self):
"""Create mocked device."""
device = aioshelly.Device(Mock(), None, aioshelly.ConnectionOptions("mock-ip"))
device._update_d(self.cit_d)
device._update_s(self.cit_s)
device = BlockDevice(Mock(), None, ConnectionOptions("mock-ip"))
device._update_d(self.cit_d) # pylint: disable=protected-access
device._update_s(self.cit_s, CoapType.REPLY) # pylint: disable=protected-access
return device


Expand All @@ -96,6 +99,7 @@ def coiot_examples():
index = requests.get(
BASE_URL,
# Not sure, local machine barfs on their cert
timeout=DEVICE_IO_TIMEOUT,
verify=False,
).text
return [
Expand All @@ -118,8 +122,8 @@ def print_example(example):
if value is None:
value = "None"

if aioshelly.BLOCK_VALUE_UNIT in info:
unit = " " + info[aioshelly.BLOCK_VALUE_UNIT]
if BLOCK_VALUE_UNIT in info:
unit = " " + info[BLOCK_VALUE_UNIT]
else:
unit = ""

Expand All @@ -136,7 +140,7 @@ def run():
for example in coiot_examples():
try:
print_example(example)
except Exception as err:
except Exception as err: # pylint: disable=broad-except
errors.append((example, err))
break

Expand Down

0 comments on commit f108ecd

Please sign in to comment.