Skip to content

Raise a setup error when the homescreen request fails - #1332

Open
scardus wants to merge 1 commit into
fronzbot:devfrom
scardus:fix-homescreen-no-response
Open

scardus wants to merge 1 commit into
fronzbot:devfrom
scardus:fix-homescreen-no-response

Conversation

@scardus

@scardus scardus commented Oct 23, 2026

Copy link
Copy Markdown

Description:

I found this while looking into how Home Assistant's Blink integration copes when setup goes wrong.

When the homescreen request hits a connection error or a timeout, Auth.query logs it and returns None. validate_homescreen then calls None.json() and raises AttributeError, which start() doesn't catch.

This PR raises BlinkSetupError instead, so start() returns False and leaves available set to False, the same as other setup failures. Home Assistant then retries setup, instead of failing the config entry until a manual reload.

One thing to note... refresh() also calls get_homescreen() and doesn't catch BlinkSetupError, so a failed homescreen request during a refresh now raises BlinkSetupError instead of AttributeError. It still raises either way, just with a clearer error.

I've added two tests: one for get_homescreen() with no response, and one for start() returning False. Both fail without the fix.

Related issue (if applicable): none

Checklist:

  • Local tests with tox run successfully PR cannot be meged unless tests pass
  • Changes tested locally to ensure platform still works as intended
  • Tests added to verify new code works

@by-ae by-ae left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested b368a2a locally (Python 3.13, aiohttp from requirements.txt): full suite 252 passed. Both new tests fail on dev and pass here.

I also ran Blink.start() against a real aiohttp session with auth.startup / setup_urls mocked so the homescreen URL points at a local port:

                                  dev                                PR
connection refused                AttributeError: 'NoneType'...json  start() -> False, available False
local server, 503 text/html       ContentTypeError                   ContentTypeError
local server, 200 text/html       ContentTypeError                   ContentTypeError

So the connection error / timeout path is fixed as described. The other half of the same failure mode is still open, though: request_homescreen uses json=False, so Auth.validate_response hands back the raw response without checking status or content type (auth.py#L213-L215), and validate_homescreen then calls response.json() on whatever came back. An HTML error page (Blink returning a 5xx during an outage, or a captive portal) raises aiohttp's ContentTypeError, which start() doesn't catch either, so Home Assistant would still fail the entry the same way.

Wrapping the json call fixed all three rows in the same harness (start() -> False, available False), and the suite still passes (252):

from aiohttp import ContentTypeError
...
        try:
            self.homescreen = await response.json()
        except (ContentTypeError, ValueError) as error:
            _LOGGER.error("Unexpected homescreen response: %s", response.status)
            raise BlinkSetupError from error

Up to you whether that belongs in this PR or a follow-up. It's the same "setup should fail cleanly" case.

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