Smbus2 no longer working after upgrading to Core 2021.2.3

All,

I have a Home Assistant implementation which heavily depends on I2C control of an MCP23017. I directly control the I2C parameters with smbus2.

After upgrading to Core 2021.2.3 today, the automation stopped working, seriously impacting the whole implementation.

I could nail down the issue to smbus2. Just adding the line

from smbus2 import SMBusWrapper

will fail the implementation already. I need to add that I also have the following requirements in my code.

REQUIREMENTS = ['smbus2==0.2.1']

Has something changed in the smbus2 implementation or the version with the new Core OS?

Thanks all.
Kind regards.

OK, found it.

If there are other people running into the same issue: the new version is 0.3.1.

REQUIREMENTS = ['smbus2==0.3.1']

… and then smbus2 can be called with e.g.

from smbus2 import SMBus
with SMBus(1) as smbus:
   ...

Available in case you need more information or help.

Kind regards.

Hello, I have similar problem with SMBUS doesn’t work after HA upgrade to newer version. Could You explain more about solution, where i should change this place REQUIREMENTS = [‘smbus2==0.3.1’]?
I use this expand board and solution for HA abelectronics-home-assistant-custom-components/abelectronicsiopi at master · abelectronicsuk/abelectronics-home-assistant-custom-components · GitHub

Thanks

Hi Andrius,

Looking back at my post, I must admit that I was pretty sparse in the information I gave. In the meantime I also solved the problem in a totally different way, so I am no longer dependent on the smbus2 version, but here goes …

Back then I had programmed my own switch. The folder with the switch then has the following minimal components.

image

The REQUIREMENTS = [‘smbus2==0.3.1’] line is located in the switch.py file.

I didn’t find back the requirements in the abelectronicsuk library you mentioned. If you want to add it nevertheless, I would try adding the line in the IOPi.py file.

image

… and I would change the

try:
    from smbus2 import SMBus
except ImportError:

    try:
        from smbus import SMBus
    except ImportError:
        raise ImportError("python-smbus or smbus2 not found")

lines into:

REQUIREMENTS = ['smbus2==0.3.1']

try:
    from smbus2 import SMBus
except ImportError:
    raise ImportError("python-smbus2 not found")