Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mqtt reason_code is not an int #252

Merged
merged 1 commit into from Mar 31, 2024

Conversation

Mips2648
Copy link
Contributor

@Mips2648 Mips2648 commented Mar 31, 2024

Description:

Hello,

reason_code received in mqtt callbacks is not an int anymore but an instance of ReasonCode, see https://eclipse.dev/paho/files/paho.mqtt.python/html/migrations.html#on-connect for reference

Comparaison with int is fine as magic method __eq__ & __lt__ exists but the representation is a string.

This cause logging error in case of unexpected disconnect:

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.9/logging/__init__.py", line 1079, in emit
    msg = self.format(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 923, in format
    return fmt.format(record)
  File "/usr/lib/python3.9/logging/__init__.py", line 659, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.9/logging/__init__.py", line 363, in getMessage
    msg = msg % self.args
TypeError: %d format: a number is required, not ReasonCode
Call stack:
  File "/root/.local/bin/TheengsGateway", line 4, in <module>
    main()
  File "/root/.local/share/pipx/venvs/theengsgateway/lib/python3.9/site-packages/TheengsGateway/__init__.py", line 55, in main
    run(configuration, config_path)
  File "/root/.local/share/pipx/venvs/theengsgateway/lib/python3.9/site-packages/TheengsGateway/ble_gateway.py", line 683, in run
    gw.client.loop_forever()
  File "/root/.local/share/pipx/venvs/theengsgateway/lib/python3.9/site-packages/paho/mqtt/client.py", line 2291, in loop_forever
    rc = self._loop(timeout)
  File "/root/.local/share/pipx/venvs/theengsgateway/lib/python3.9/site-packages/paho/mqtt/client.py", line 1701, in _loop
    return self.loop_misc()
  File "/root/.local/share/pipx/venvs/theengsgateway/lib/python3.9/site-packages/paho/mqtt/client.py", line 2143, in loop_misc
    self._check_keepalive()
  File "/root/.local/share/pipx/venvs/theengsgateway/lib/python3.9/site-packages/paho/mqtt/client.py", line 3289, in _check_keepalive
    self._do_on_disconnect(
  File "/root/.local/share/pipx/venvs/theengsgateway/lib/python3.9/site-packages/paho/mqtt/client.py", line 4378, in _do_on_disconnect
    on_disconnect(
  File "/root/.local/share/pipx/venvs/theengsgateway/lib/python3.9/site-packages/TheengsGateway/ble_gateway.py", line 163, in on_disconnect
    logger.error(
Message: 'Disconnected from MQTT broker with reason code = %d'
Arguments: (ReasonCode(Disconnect, 'Keep alive timeout'),)

Checklist:

  • I have created the pull request against the latest development branch
  • I have added only one feature/fix per PR and the code change compiles without warnings
  • I accept the Developer Certificate of Origin (DCO).

@koenvervloesem koenvervloesem merged commit fbb29ea into theengs:development Mar 31, 2024
7 checks passed
@koenvervloesem
Copy link
Member

Thanks for your contribution! I overlooked that indeed in the migration to Paho MQTT 2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants