File: __init__.py

package info (click to toggle)
devolo-plc-api 1.5.1%2Bgit20260208.5d3989e-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 504 kB
  • sloc: python: 1,616; makefile: 6
file content (23 lines) | stat: -rw-r--r-- 799 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Helper methods to allow advanced usage of information provided by the device."""

from io import BytesIO
from typing import Any

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, kind: str = "svg", **kwargs: Any) -> bytes:
    """
    Generate a wifi QR code.

    :param guest_wifi: Wifi credentials to represent in the QR code
    :param kind: Output format of the image
    :return: Bytes of image
    """
    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=kind, **kwargs)
    return buffer.getvalue()