@@ -85,16 +85,22 @@ def is_pi3():
85
85
86
86
# New values taken from settings_file.
87
87
with open (settings_file , 'r' ) as f :
88
- config_string = '[dummy_section]\n ' + f .read ()
88
+ # Inject section manually and read all file.
89
+ # Needed as configparser 3.11 cannot read INI files without sections.
90
+ config_string = '[wifi]\n ' + f .read ()
89
91
settings = configparser .ConfigParser ()
90
- settings .read_string (config_string )
91
- new_channel = settings ['dummy_section' ]['channel' ]
92
- new_country = settings ['dummy_section' ]['country' ]
93
- new_password = settings ['dummy_section' ]['password' ]
94
- new_ssid = settings ['dummy_section' ]['ssid' ]
95
- password_protected = settings ['dummy_section' ]['passwordprotected' ]
96
- ssid_hidden_state = settings ['dummy_section' ]['ssidhiddenstate' ]
97
- new_static_ip = settings ['dummy_section' ]['ipaddress' ]
92
+ try :
93
+ settings .read_string (config_string )
94
+ section = settings ['wifi' ]
95
+ new_channel = section .get ('channel' , default_channel )
96
+ new_country = section .get ('country' , default_country )
97
+ new_password = section .get ('password' , default_password )
98
+ new_ssid = section .get ('ssid' , default_ssid )
99
+ password_protected = section .get ('passwordprotected' , '1' )
100
+ ssid_hidden_state = section .get ('ssidhiddenstate' , '0' )
101
+ new_static_ip = section .get ('ipaddress' , default_ip_address )
102
+ except (KeyError , configparser .Error ) as e :
103
+ sys .exit (f"Invalid settings file: { e } " )
98
104
99
105
# Action functions.
100
106
0 commit comments