Repository navigation
Conversation
by-ae
left a comment
There was a problem hiding this comment.
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 errorUp to you whether that belongs in this PR or a follow-up. It's the same "setup should fail cleanly" case.
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.querylogs it and returns None.validate_homescreenthen callsNone.json()and raisesAttributeError, whichstart()doesn't catch.This PR raises
BlinkSetupErrorinstead, sostart()returns False and leavesavailableset 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 callsget_homescreen()and doesn't catchBlinkSetupError, so a failed homescreen request during a refresh now raisesBlinkSetupErrorinstead ofAttributeError. It still raises either way, just with a clearer error.I've added two tests: one for
get_homescreen()with no response, and one forstart()returning False. Both fail without the fix.Related issue (if applicable): none
Checklist:
toxrun successfully PR cannot be meged unless tests pass