Skip to content

Fix/m1s telnet discovery v2 - #385

Open
teyou wants to merge 3 commits into
niceboygithub:masterfrom
teyou:fix/m1s-telnet-discovery-v2
Open

Fix/m1s telnet discovery v2#385
teyou wants to merge 3 commits into
niceboygithub:masterfrom
teyou:fix/m1s-telnet-discovery-v2

Conversation

@teyou

@teyou teyou commented Jul 27, 2026

Copy link
Copy Markdown

Summary

Fix device discovery on Aqara M1S gateways by improving Telnet file reading and M1S shell selection.

The integration could connect to MQTT, but failed to discover the gateway and paired Zigbee devices with errors such as:

Can't get devices: Expecting value: line 1 column 1 (char 0)

and:

Failed reading gateway file /data/zigbee/coordinator.info: telnet connection closed

Root cause

Duplicate Telnet reads

TelnetShell.read_file() performed two consecutive reads when with_newline=False.

The first read already consumed the file contents and shell prompt. The second read then waited for another prompt, which could return an empty response, timeout, or closed connection.

M1S shell prompt handling

The detected model name remains:

"M1S": "m1s gen2"

However, custom-flashed M1S firmware can still use the classic # shell prompt.

The old _get_shell() logic routed "m1s gen2" to TelnetShellM2POE, which expects the / # prompt. This caused Telnet reads to fail on this M1S firmware.

Changes

core/shell.py

  • Read file contents with one command and one prompt read.
  • Remove the duplicate Telnet read when with_newline=False.
  • Normalize Telnet line endings.
  • Remove possible echoed commands and trailing shell prompts.
  • Keep with_newline as output formatting only.
  • Preserve the existing "M1S": "m1s gen2" model mapping.

core/gateway.py

  • Route M1S model names through the standard TelnetShell.
  • Keep M2/M3/V1 models using TelnetShellM2POE.
  • Add safer JSON extraction for gateway Telnet output.
  • Parse coordinator.info and device.info using the safer JSON helper.

Tested with

  • Home Assistant Container 2026.7.4
  • Python 3.14.6
  • Aqara M1S
  • Custom firmware 4.0.6_0006.0646
  • Zigbee coordinator version 6.46

After applying the changes:

  • /data/zigbee/coordinator.info loads successfully
  • /data/zigbee/device.info loads successfully
  • paired Zigbee devices are discovered
  • MQTT heartbeat and state updates continue working
  • Telnet connection and JSON parsing errors no longer occur

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.

1 participant