mesh-api icon indicating copy to clipboard operation
mesh-api copied to clipboard

HOME_ASSISTANT_CHANNEL_INDEX argument must be a string

Open lameritos opened this issue 5 months ago • 6 comments

in pull git and docker reconfigure config via web UI i have an error

MESH-API v0.7.4.1 Beta by: MR_TBOT (https://mr-tbot.com) https://mesh-api.dev - (https://github.com/mr-tbot/mesh-api/)

Messaging Dashboard Access: http://localhost:5000/dashboard

DISCLAIMER: This is beta software - NOT ASSOCIATED with the official Meshtastic (https://meshtastic.org/) project. It should not be relied upon for mission critical tasks or emergencies. Modification of this code for nefarious purposes is strictly frowned upon. Please use responsibly.

(Use at your own risk. For feedback or issues, visit https://mesh-api.dev or the links above.)

2026-06-17 21:33:13 UTC - Script started. 2026-06-17 21:33:13 UTC - Loading config files... 2026-06-17 21:33:13 UTC - File "/app/mesh-api.py", line 385, in HOME_ASSISTANT_CHANNEL_INDEX = int(config.get("home_assistant_channel_index", -1)) 2026-06-17 21:33:13 UTC - TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' 2026-06-17 21:33:20 UTC -

lameritos avatar Jun 17 '26 21:06 lameritos

in pull git and docker reconfigure config via web UI i have an error

MESH-API v0.7.4.1 Beta by: MR_TBOT (https://mr-tbot.com) https://mesh-api.dev - (https://github.com/mr-tbot/mesh-api/)

Messaging Dashboard Access: http://localhost:5000/dashboard

DISCLAIMER: This is beta software - NOT ASSOCIATED with the official Meshtastic (https://meshtastic.org/) project. It should not be relied upon for mission critical tasks or emergencies. Modification of this code for nefarious purposes is strictly frowned upon. Please use responsibly.

(Use at your own risk. For feedback or issues, visit https://mesh-api.dev or the links above.)

2026-06-17 21:33:13 UTC - Script started. 2026-06-17 21:33:13 UTC - Loading config files... 2026-06-17 21:33:13 UTC - File "/app/mesh-api.py", line 385, in HOME_ASSISTANT_CHANNEL_INDEX = int(config.get("home_assistant_channel_index", -1)) 2026-06-17 21:33:13 UTC - TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' 2026-06-17 21:33:20 UTC -

Will investigate! Thanks for the report!

mr-tbot avatar Jun 18 '26 14:06 mr-tbot

If you download the default config.json and start Mesh-API it seems the first config save in Mesh-API creates the config entries below "home_assistant_channel_index": null, "home_assistant_enable_pin": false, "home_assistant_secure_pin": "", "home_assistant_timeout": null, "home_assistant_token": "", "home_assistant_url": ""

If I change "home_assistant_channel_index": null, to "home_assistant_channel_index": 0 Mesh-API starts.

Th3H0ff avatar Jun 23 '26 08:06 Th3H0ff

Thanks for the detailed report — and @Th3H0ff, your investigation nailed it. 🙏

Root cause (confirmed): The WebUI config editor is the culprit, not just Home Assistant. When you open ⚙️ Config and hit Save, every empty numeric field (<input type="number">) is serialized as JSON null. Keys that were previously absent from config.json (so the code's built-in default applied) get written back as an explicit null. On the next start, coercions like:

HOME_ASSISTANT_CHANNEL_INDEX = int(config.get("home_assistant_channel_index", -1))

receive None instead of a missing key, and int(None) raises the TypeError you saw — at import time, before Flask even starts, so in Docker the container just restart-loops. home_assistant_channel_index is the first one to blow up, but meshtastic_connect_timeout_sec, serial_baud, wifi_port, max_ai_chunks, chunk_size and a few MeshCore keys are all in the same class. That's why editing null → 0 (as you found) fixes it: the value is now coercible.

Proposed fix (staged, pending the next release):

  1. Config is now sanitized on load — any null value is dropped so the coded default applies (_strip_null_config).
  2. The same sanitize runs on save (/config_editor/save), so the WebUI can no longer persist a null.
  3. Client-side, empty number inputs now serialize to undefined (key omitted) instead of null.

I reproduced the exact crash on a config poisoned with nulls for all of the above keys, applied the fix, and confirmed the dashboard now boots normally (previously it died at import). Your null → 0 workaround remains valid in the meantime.

Leaving this open — when the fix ships I'll ping you; would appreciate a confirmation from a fresh Docker pull + a WebUI save that it stays healthy across a restart. Does that match what you're seeing?

mr-tbot avatar Jul 08 '26 17:07 mr-tbot

Fixed in v0.7.5.0 Beta (just released: https://github.com/mr-tbot/mesh-api/releases/tag/v0.7.5.0-beta).

The WebUI Config editor was writing JSON null for any cleared numeric field, so on the next start int(config.get("home_assistant_channel_index", -1)) got None and raised the TypeError you saw — dying at import before Flask even started (hence the Docker restart-loop). Config is now null-sanitized both on load and on save, for the main config and every extension config, so a routine Save can't brick startup anymore. @Th3H0ff — thanks again, your note about the first save creating the null entries was the key.

Please pull the latest and confirm it stays healthy across a restart after a WebUI Save. Leaving this open for your confirmation.

mr-tbot avatar Jul 19 '26 00:07 mr-tbot

Update: the fix is now in v0.7.5.2 Beta — https://github.com/mr-tbot/mesh-api/releases/tag/v0.7.5.2-beta

Heads-up: v0.7.5.0 and v0.7.5.1 (which I referenced earlier) were pulled — they shipped a separate dashboard bug that broke the Node Map / Traffic Monitor. That's fixed in v0.7.5.2, which also contains this home_assistant_channel_index startup-crash fix (config is null-sanitized on load and save so a WebUI Save can't brick startup).

Please grab v0.7.5.2 (or docker pull mrtbot/mesh-api:latest), and confirm it starts cleanly across a restart after a WebUI Save. @Th3H0ff — thanks again. Leaving open for your confirmation.

mr-tbot avatar Jul 19 '26 04:07 mr-tbot

Hi thanks! the problem no longer responding closed

lameritos avatar Jul 26 '26 12:07 lameritos