Skip to content

Handle malformed Sonoff advertisements - #1589

Merged
Ernst79 merged 1 commit into
custom-components:masterfrom
IoannisArmamentos:fix/sonoff-malformed-advertisements
Sep 8, 2026
Merged

Handle malformed Sonoff advertisements#1589
Ernst79 merged 1 commit into
custom-components:masterfrom
IoannisArmamentos:fix/sonoff-malformed-advertisements

Conversation

@IoannisArmamentos

Copy link
Copy Markdown
Contributor

Summary

Prevent malformed or unsupported Sonoff BLE advertisements from causing parser exceptions.

Problem

The Sonoff parser had two failure cases:

  • Its initial length guard allowed payloads that were still too short for later encrypted-data processing, which could result in IndexError.
  • An unknown Sonoff device type could leave device_type undefined when report_unknown was disabled, resulting in UnboundLocalError.

Fix

Require the minimum payload length actually needed by the parser before processing the advertisement.

Also ensure unknown Sonoff device types always return cleanly after the optional diagnostic logging path.

Known Sonoff S-MATE and R5 parsing remains unchanged.

Regression tests cover truncated advertisements and unknown device types.

@Ernst79
Ernst79 merged commit 18c2845 into custom-components:master Sep 8, 2026
6 checks passed
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.

2 participants