mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-24 13:40:18 +00:00
Handle network key type
Aims to handle network key type by using a text match that assigns the integer, as reported in https://github.com/python-kasa/python-kasa/issues/1325 One solution of multiple potential solutions. Adds the default of 3, which should be WPA2, and is set as a default in multiple other locations within the code. May need more documentation on the levels (0-4) and their correspondence.
This commit is contained in:
@@ -679,7 +679,23 @@ class IotDevice(Device):
|
||||
async def _join(target: str, payload: dict) -> dict:
|
||||
return await self._query_helper(target, "set_stainfo", payload)
|
||||
|
||||
payload = {"ssid": ssid, "password": password, "key_type": int(keytype)}
|
||||
try:
|
||||
keytype = int(keytype)
|
||||
except ValueError:
|
||||
match keytype.lower():
|
||||
case "open":
|
||||
keytype = 0
|
||||
case "wep":
|
||||
keytype = 1
|
||||
case "wpa":
|
||||
keytype = 2
|
||||
case "wpa2":
|
||||
keytype = 3
|
||||
case "wpa3":
|
||||
keytype = 4
|
||||
case _:
|
||||
raise KasaException(f"Unknown network keytype: {keytype}")
|
||||
payload = {"ssid": ssid, "password": password, "key_type": keytype}
|
||||
try:
|
||||
return await _join("netif", payload)
|
||||
except KasaException as ex:
|
||||
|
||||
Reference in New Issue
Block a user