NickWaterton / Roomba980-Python

Python program and library to control iRobot Roomba 980 Vacuum Cleaner
MIT License
377 stars 106 forks source link

Automatically generated config.ini appears to be unusable by read_config_file() in roomba.py. #54

Open JonStratton opened 5 years ago

JonStratton commented 5 years ago

It appears there are at lease two read_config_file()s; one in roomba.py and one in main.py. And the version in roomba.py looks like it will only use the first address if there are more than one, based on the indention.

Example Application code:

myroomba = Roomba()
myroomba.connect()

Error from Application code:

Traceback (most recent call last):
  File "/usr/lib/python3.5/configparser.py", line 1135, in _unify_values
    sectiondict = self._sections[section]
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "complicated.py", line 64, in <module>
    myroomba = Roomba()
  File "/home/jgstratton/Work/venvs/Roomba980-Python/lib/python3.5/site-packages/roomba/roomba.py", line 210, in __init__
    self.read_config_file(file)
  File "/home/jgstratton/Work/venvs/Roomba980-Python/lib/python3.5/site-packages/roomba/roomba.py", line 232, in read_config_file
    self.blid = Config.get(self.address, "blid"),
  File "/usr/lib/python3.5/configparser.py", line 778, in get
    d = self._unify_values(section, vars)
  File "/usr/lib/python3.5/configparser.py", line 1138, in _unify_values
    raise NoSectionError(section)
configparser.NoSectionError: No section: None

Suspect Code in read_config_file() in roomba.py (Note the indention of "self.address = addresses[0]"):

        if self.address is None:
            if len(addresses) > 1:
                self.log.warn("config file has entries for %d Roombas, "
                              "only configuring the first!")
                self.address = addresses[0]
        self.blid = Config.get(self.address, "blid"),
        self.password = Config.get(self.address, "password")

There might be other issues around the getting of the address. I'm kind of playing around with a fix and may open a PR unless a fix gets banged out sooner (or I missed something obvious and by Issue request is invalid...)