-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
start_scan
settings and filters arguments #25
- Loading branch information
Showing
13 changed files
with
445 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
there.env | ||
*.asciidoc | ||
*.ipynb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
jupyter: | ||
jupytext: | ||
formats: ipynb,md | ||
text_representation: | ||
extension: .md | ||
format_name: markdown | ||
format_version: '1.3' | ||
jupytext_version: 1.11.2 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
```python | ||
from time import sleep | ||
|
||
from dataclasses import dataclass, field | ||
from typing import List | ||
|
||
%load_ext pythonhere | ||
%connect-there | ||
``` | ||
|
||
```python | ||
%%there | ||
from able.android.dispatcher import ( | ||
ArrayList, | ||
BluetoothDispatcher, | ||
ScanFilterBuilder, | ||
ScanSettingsBuilder | ||
) | ||
``` | ||
|
||
```python | ||
%%there | ||
@dataclass | ||
class Results: | ||
started: bool = None | ||
completed: bool = None | ||
devices: List = field(default_factory=lambda: []) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
name="$1" | ||
command="${2}" | ||
command="${command:=test}" | ||
|
||
|
||
cat "${name}.md" | | ||
jupytext --execute --to ipynb | | ||
jupyter nbconvert --stdin --no-input --to asciidoc --output "${name}" | ||
|
||
cat "${name}".asciidoc | ||
|
||
if [ "${command}" = "test" ]; then | ||
diff "${name}.asciidoc" "${name}.expected" | ||
elif [ "${command}" = "record" ]; then | ||
cp "${name}".asciidoc "${name}".expected | ||
else | ||
echo "Unknown command: ${command}" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
for name in test_*.md; do ./run "${name%%.*}"; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[[setup]] | ||
= Setup | ||
|
||
[[run-ble-devices-scan]] | ||
= Run BLE devices scan | ||
|
||
|
||
---- | ||
Started: None Completed: None | ||
---- | ||
|
||
[[check-that-scan-started-and-completed]] | ||
= Check that scan started and completed | ||
|
||
|
||
---- | ||
Started: 1 Completed: 1 | ||
---- | ||
|
||
[[check-that-testing-device-was-discovered]] | ||
= Check that testing device was discovered | ||
|
||
|
||
---- | ||
True | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
jupyter: | ||
jupytext: | ||
formats: ipynb,md | ||
text_representation: | ||
extension: .md | ||
format_name: markdown | ||
format_version: '1.3' | ||
jupytext_version: 1.11.2 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
# Setup | ||
|
||
```python | ||
%run init.ipynb | ||
``` | ||
|
||
```python | ||
%%there | ||
class BLE(BluetoothDispatcher): | ||
|
||
def on_scan_started(self, success): | ||
results.started = success | ||
|
||
def on_scan_completed(self): | ||
results.completed = 1 | ||
|
||
def on_device(self, device, rssi, advertisement): | ||
results.devices.append(device) | ||
|
||
ble = BLE() | ||
``` | ||
|
||
# Run BLE devices scan | ||
|
||
```python | ||
%%there | ||
results = Results() | ||
print(f"Started: {results.started} Completed: {results.completed}") | ||
ble.start_scan() | ||
``` | ||
|
||
```python | ||
sleep(10) | ||
``` | ||
|
||
```python | ||
%%there | ||
ble.stop_scan() | ||
``` | ||
|
||
```python | ||
sleep(2) | ||
``` | ||
|
||
# Check that scan started and completed | ||
|
||
```python | ||
%%there | ||
print(f"Started: {results.started} Completed: {results.completed}") | ||
``` | ||
|
||
# Check that testing device was discovered | ||
|
||
```python | ||
%%there | ||
print( | ||
"KivyBLETest" in [dev.getName() for dev in results.devices] | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[[setup]] | ||
= Setup | ||
|
||
[[test-device-is-found-with-filter-by-name]] | ||
= Test device is found with filter by name | ||
|
||
|
||
---- | ||
{'KivyBLETest'} | ||
---- | ||
|
||
[[test-device-is-not-found-filtered-out-by-name]] | ||
= Test device is not found: filtered out by name | ||
|
||
|
||
---- | ||
[] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
jupyter: | ||
jupytext: | ||
formats: ipynb,md | ||
text_representation: | ||
extension: .md | ||
format_name: markdown | ||
format_version: '1.3' | ||
jupytext_version: 1.11.2 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
# Setup | ||
|
||
```python | ||
%run init.ipynb | ||
``` | ||
|
||
```python | ||
%%there | ||
class BLE(BluetoothDispatcher): | ||
|
||
def on_scan_started(self, success): | ||
results.started = success | ||
|
||
def on_scan_completed(self): | ||
results.completed = 1 | ||
|
||
def on_device(self, device, rssi, advertisement): | ||
results.devices.append(device) | ||
|
||
ble = BLE() | ||
``` | ||
|
||
# Test device is found with filter by name | ||
|
||
```python | ||
%%there | ||
results = Results() | ||
|
||
filters = ArrayList() | ||
filters.add( | ||
ScanFilterBuilder().setDeviceName("KivyBLETest").build() | ||
) | ||
|
||
ble.start_scan(filters=filters) | ||
``` | ||
|
||
```python | ||
sleep(10) | ||
``` | ||
|
||
```python | ||
%%there | ||
ble.stop_scan() | ||
``` | ||
|
||
```python | ||
sleep(2) | ||
``` | ||
|
||
```python | ||
%%there | ||
print(set([dev.getName() for dev in results.devices])) | ||
``` | ||
|
||
# Test device is not found: filtered out by name | ||
|
||
```python | ||
%%there | ||
results = Results() | ||
|
||
filters = ArrayList() | ||
filters.add( | ||
ScanFilterBuilder().setDeviceName("No-such-device-8458e2e35158").build() | ||
) | ||
|
||
ble.start_scan(filters=filters) | ||
``` | ||
|
||
```python | ||
sleep(10) | ||
``` | ||
|
||
```python | ||
%%there | ||
ble.stop_scan() | ||
``` | ||
|
||
```python | ||
sleep(2) | ||
``` | ||
|
||
```python | ||
%%there | ||
ble.stop_scan() | ||
|
||
print(results.devices) | ||
``` |
Oops, something went wrong.