Closed bernhardkaindl closed 2 years ago
There is one major thing I don't like, which I guess is not possible to solve while still using dataclass as base class:
Say I want to update a network connection and want to change e.g. the WiFi PSK like so:
profile.wifi_security.psk = args.password
This triggers this mypy error:
error: Item "None" of "Optional[WifiSecuritySettings]" has no attribute "psk"
The reason for this that the dataclass-based approach (has to use/uses) Optional[WifiSecuritySettings] to add "802-11-wifi-security" and all the other settings domains which are only present for specific connection types.
My idea for fixing this would be to create specific ConnectionProfile
top-level classes for each type of connection, and in .from_dbus()
of a master class (which would be used when converting from dbus internally as well) check what
connection_profile["connection"]["type"]
indicates and then create the needed class for the given connection_type. To you see other possible ways to fix this issue?
PS: My Prodict and MetaDict-based approaches does not have this issue.
But it seems, this would be solvable using different ConnectionProfile
classes like ConnectionProfileWireless
, ConnectionProfileEthernet
, etc.
Do you agree that this would be the way forward to fix that?
Say I want to update a network connection and want to change e.g. the WiFi PSK like so:
You can insert an assert so that mypy knows:
assert profile.wifi_security is not None
I will review this on weekend. A bit busy on workdays.
It got a lot of review feedback, thanks! The reviews in this PR are addressed or merged into #14, so this PR is not needed anymore.
Add testcase checking dbus_types and defaults using real connections from a running networkmanager (to be expanded to use json files too)
The testcase fails if the output from settings.from_dbus.().to_dbus() differs from settings and also fails the dataclass delivers more(or less properties, or even a change in a value of a property.
Change dbus_type of connection.timestamp from q to t (used by NetworkManager-1.30)
Add generated Ipv6Settings, ProxySettings, BridgeSettings, WireguardSettings, VpnSettings, EthernetSettings and kManagerProxySettings. (they are used by the network connection profiles on my box)
NetworkManngerSettings (typo and name clash) renamed to ConnectionProfile
Export classes of sdbus_async/networkmanager/settings.py in init.py
Convert example examples/async/list-connections-async.py
Convert example examples/async/add-wifi-psk-connection-async.py
Add generator tool generate-settings-dataclasses.py (based on NetWorkManager/generate-docs-nm-settings-docs-merge.py) - only for class generation, would be useful to generate dict classes too.
{ipv4,ipv6}.{addresses,routes} are deprecated, don't import them in from_dbus()
class NetworkManagerSettingsMixin.to_dbus(): Skip default values, not None (e.g. for bool, the real default can only be True or False)
ConnectionProfile.connection is not optional: uuid and type are always needed.
ConnectionProfileSettings: Use the generated default bool values