Closed bernhardkaindl closed 2 years ago
Hmm on a second thought..........
Is mypy going to complain about this? Will python-sdbus be able to encode it?
profile.connection.connection_type = ConnectionType.WIRELESS
Also stackoverflow gives me another example of StrEnum: https://stackoverflow.com/questions/58608361/string-based-enum-in-python/58608362#58608362
@igo95862 Good catch!
Is mypy going to complain about this? Will python-sdbus be able to encode it?
profile.connection.connection_type = ConnectionType.WIRELESS
Yes it complains correcty. But it won't work this way with an Enum! (see below)
Also stackoverflow gives me another example of StrEnum: https://stackoverflow.com/questions/58608361/string-based-enum-in-python/58608362#58608362
Yes, I saw these as well and tried them:
Finally, I understood that Enum
means that one has to use .value
: :-1:
profile.connection.connection_type = ConnectionType.WIRELESS.value
Instead, I really want the simple use:
profile.connection.connection_type = ConnectionType.WIFI
class ConnectionType:
...
WIFI = "802-11-wireless"
WPAN = "wpan"
I renamed WIRELESS
to WIFI
now to be consistent with enum DeviceType
:
class DeviceType(IntEnum):
"""Device Type..."""
https://github.com/python-sdbus/python-sdbus-networkmanager/blob/6815ceaaae9ae4e578497a9c6e87d681244e49a9/sdbus_async/networkmanager/enums.py#L514 and I need to derive the ConnectionType
from the DeviceType
string at runtime (see #26), so be in line with DeviceType
.
The new commit makes use of ConnectionType.WIFI
in examples/async/add-wifi-psk-connection-async.py:
profile = ConnectionProfile(
connection=ConnectionSettings(
uuid=str(uuid.uuid4()),
- connection_type='802-11-wireless',
+ connection_type=ConnectionType.WIFI,
connection_id=args.conn_id,
autoconnect=args.auto,
),
*This is working correctly and is checked with mypy --strict
, and should be good to go.
Ok. I cherry picked cae9fbd3946bad3ad91d68b994f06746faa38a5b .
Add enums.ConnectionType (on top of #24)