GTFS Custom Sensor - missing attributes

I have a custom sensor based on GTFS which is failing after upgrading from a 2011 version to 2022.8.7. with Python 3.10.6. The sensor loads and the state of the sensor is available but the attributes defined in the sensor code are not loading and not available. I am running core in a venv on a RPi4. I am not sure but this error may be related to the issue.

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/loader.py", line 657, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/loader.py", line 674, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/components/cast/__init__.py", line 7, in <module>
    from pychromecast import Chromecast
  File "/srv/homeassistant/lib/python3.10/site-packages/pychromecast/__init__.py", line 14, in <module>
    from . import socket_client
  File "/srv/homeassistant/lib/python3.10/site-packages/pychromecast/socket_client.py", line 23, in <module>
    from . import cast_channel_pb2
  File "/srv/homeassistant/lib/python3.10/site-packages/pychromecast/cast_channel_pb2.py", line 20, in <module>
    _SIGNATUREALGORITHM = DESCRIPTOR.enum_types_by_name['SignatureAlgorithm']

Some posts suggest upgrading the version of protobuf which I have done (f3.6.1 to 3.20.1). I have also upgraded the version of gtfs-realtime-bindings (0.0.5 to 0.0.7) and the result is the same with the same error. The sensor worked perfectly in the 2011 version (2011.11 I think). Any ideas on how to solve it greatly appreciated.

Upgrading to 2022.9.4 did not solve it either. It’s possible that it’s a Python 3.10 issue.

It seems that a function name was changed for 2021.12.

“device_state_attributes has been deprecated and replaced with extra_state_attributes in 2021.12.0b1”

Changing the word ‘device’ to ‘extra’ seems to work. I also had a mismatch betwwen the REQUIREMENTS statement in the custom code

REQUIREMENTS = [
    'gtfs-realtime-bindings==0.0.7',
    'protobuf==3.20.1'
]

and the equivalent in the ‘manifest.json’ file

 "requirements": [
        "gtfs-realtime-bindings==0.0.5",
        "protobuf==3.6.1"
    ]

I don’t know if that has any impact.