Skip to content

feat(sensor): make User-Agent configurable per feed - #164

Open
davenicoll wants to merge 1 commit into
custom-components:masterfrom
davenicoll:feat/configurable-user-agent
Open

davenicoll wants to merge 1 commit into
custom-components:masterfrom
davenicoll:feat/configurable-user-agent

Conversation

@davenicoll

Copy link
Copy Markdown

Summary

Adds an optional per-sensor user_agent setting. The default is unchanged (Home Assistant Feed-parser Integration <version>), so existing configurations behave identically.

Some servers stall or reject clients they don't recognise. CBC's RSS feeds, for example, hang indefinitely for generic agents. Today the only workaround is patching the integration.

sensor:
  - platform: feedparser
    name: Picky Server Feed
    feed_url: https://example.com/rss
    user_agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...'

Changes

  • sensor.py: new CONF_USER_AGENT option in PLATFORM_SCHEMA (default USER_AGENT), passed to FeedParserSensor and sent on every request. The constructor argument is last and defaulted, so direct callers are unaffected.
  • README.md: document the option, with an example.
  • tests/test_sensors.py: tests for the default agent, a custom agent (checked on the request actually sent), and the schema default/override.
  • pyproject.toml: ruff max-args 10 → 11 for the new constructor argument, in line with how the limit was sized previously.

Testing

  • pytest tests/: 113 passed (88 before; 25 new cases across the test feeds) on Home Assistant 2026.9 / Python 3.14.
  • black 22.10.0 and ruff 0.0.278 (versions pinned in .pre-commit-config.yaml) are clean.
  • mypy 1.4.1 is clean with --ignore-missing-imports, the same as master. I couldn't run the full pre-commit mypy hook locally because homeassistant-stubs needs Home Assistant installed; CI will cover it.

🤖 Generated with Claude Code

- Add optional `user_agent` setting; default stays the integration's agent
- Send the configured agent on every feed request
- Document the option in the README
- Add tests for the default agent, a custom agent and the config schema
- Raise ruff max-args to 11 for the new constructor argument

Some servers stall or reject clients they don't recognise. CBC's RSS
feeds, for example, hang indefinitely for generic agents. A per-feed
setting lets users work around this without patching the integration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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