Skip to content

Add User-Agent#8

Merged
adrianmo merged 6 commits into
adrianmo:masterfrom
sheaur:patch-1
Feb 1, 2026
Merged

Add User-Agent#8
adrianmo merged 6 commits into
adrianmo:masterfrom
sheaur:patch-1

Conversation

@sheaur
Copy link
Copy Markdown
Contributor

@sheaur sheaur commented Jan 30, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit HTTP User-Agent header when fetching Meteoclimatic station RSS feeds.

Changes:

  • Switches urlopen(url) to urlopen(Request(...)) to include a User-Agent header.
  • Minor formatting adjustments around the raised MeteoclimaticError.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread meteoclimatic/client.py Outdated
Comment on lines +16 to +19
def weather_at_station(self, station_code):
url = self._base_url.format(station_code=station_code)

req = Request(url, headers={"User-Agent": "HomeAssistant Meteoclimatic"})
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hard-coded User-Agent value references "HomeAssistant", but this library is published as "pymeteoclimatic" and is not Home Assistant-specific (see README.md / setup.py). Consider using a library-identifying UA string (e.g., package name + version) and/or making the User-Agent configurable via the client constructor so downstream consumers can set their own UA.

Suggested change
def weather_at_station(self, station_code):
url = self._base_url.format(station_code=station_code)
req = Request(url, headers={"User-Agent": "HomeAssistant Meteoclimatic"})
def __init__(self, user_agent: str | None = None) -> None:
"""Initialize the Meteoclimatic client.
Args:
user_agent: Optional User-Agent string to use for HTTP requests.
If not provided, a default identifying this library is used.
"""
self._user_agent = user_agent or "pymeteoclimatic"
def weather_at_station(self, station_code):
url = self._base_url.format(station_code=station_code)
req = Request(url, headers={"User-Agent": self._user_agent})

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with this comment. Even though this library is used in Home Assistant's Meteoclimatic integration, it can also be used on its own or from any other platform.

It'd use pymeteoclimatic/<version>.

Comment thread meteoclimatic/client.py
Comment thread meteoclimatic/client.py
Copy link
Copy Markdown
Owner

@adrianmo adrianmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Can we also add/update test cases to make sure the changes are covered? Thanks

@sheaur
Copy link
Copy Markdown
Contributor Author

sheaur commented Jan 30, 2026

I've tried to test it, but being in the core I haven't had much time.

@sheaur
Copy link
Copy Markdown
Contributor Author

sheaur commented Jan 30, 2026

The problem, in principle, is that Meteoclimatic has blocked access.

@adrianmo adrianmo merged commit d3ba5ec into adrianmo:master Feb 1, 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.

3 participants