-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method to create a QR code from the guest wifi settings
- Loading branch information
Showing
8 changed files
with
66 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Helper methods to allow advanced usage of information provided by the device.""" | ||
from io import BytesIO | ||
|
||
from segno.helpers import make_wifi | ||
|
||
from devolo_plc_api.device_api import WifiGuestAccessGet | ||
from devolo_plc_api.device_api.wifinetwork_pb2 import WPA_NONE | ||
|
||
|
||
def wifi_qr_code(guest_wifi: WifiGuestAccessGet) -> bytes: | ||
"""Generate a wifi QR code.""" | ||
buffer = BytesIO() | ||
qr_code = make_wifi(ssid=guest_wifi.ssid, password=guest_wifi.key, security=None if guest_wifi.wpa == WPA_NONE else "WPA") | ||
qr_code.save(out=buffer, kind="svg") | ||
return buffer.getvalue() |
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
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,29 @@ | ||
"""Test helper methods.""" | ||
from devolo_plc_api import wifi_qr_code | ||
from devolo_plc_api.device_api.wifinetwork_pb2 import WPA_2, WifiGuestAccessGet | ||
|
||
|
||
class TestHelpers: | ||
"""Test devolo_plc_api.helpers.""" | ||
|
||
def test_wifi_qr_code(self): | ||
"""Test getting wifi guest access status asynchronously.""" | ||
wifi_guest_access = WifiGuestAccessGet(enabled=True, ssid='"Test"', key='"Test"', wpa=WPA_2) | ||
assert ( | ||
wifi_qr_code(wifi_guest_access) | ||
== b'<?xml version="1.0" encoding="utf-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="37" height="37" ' | ||
b'class="segno"><path class="qrline" stroke="#000" d="M4 4.5h7m2 0h1m1 0h1m2 0h1m7 0h7m-29 1h1m5 0h1m2 0h1m6 ' | ||
b"0h2m2 0h1m1 0h1m5 0h1m-29 1h1m1 0h3m1 0h1m2 0h1m1 0h1m2 0h2m1 0h3m2 0h1m1 0h3m1 0h1m-29 1h1m1 0h3m1 0h1m3 " | ||
b"0h2m1 0h1m6 0h1m1 0h1m1 0h3m1 0h1m-29 1h1m1 0h3m1 0h1m3 0h1m1 0h1m4 0h1m2 0h1m1 0h1m1 0h3m1 0h1m-29 1h1m5 " | ||
b"0h1m1 0h2m5 0h1m1 0h1m1 0h2m1 0h1m5 0h1m-29 1h7m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h7m-17 1h2m1 " | ||
b"0h3m1 0h1m-20 1h1m2 0h1m1 0h2m1 0h2m4 0h1m1 0h2m3 0h1m1 0h1m-24 1h5m4 0h3m1 0h1m1 0h1m2 0h1m3 0h2m1 0h3m-28 " | ||
b"1h1m1 0h1m2 0h2m1 0h1m2 0h4m1 0h1m2 0h2m1 0h2m2 0h2m-28 1h1m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