Skip to content

Commit 3a6123b

Browse files
committed
Rework for 302 on v6 without breaking v8
1 parent fcbf1d0 commit 3a6123b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

airos/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ async def _request_json(
234234
authenticated: bool = False,
235235
ct_json: bool = False,
236236
ct_form: bool = False,
237+
allow_redirects: bool = True,
237238
) -> dict[str, Any] | Any:
238239
"""Make an authenticated API request and return JSON response."""
239240
# Pass the content type flags to the header builder
@@ -261,12 +262,13 @@ async def _request_json(
261262
json=json_data,
262263
data=form_data,
263264
headers=request_headers, # Pass the constructed headers
264-
allow_redirects=False, # Handle redirects manually if needed
265+
allow_redirects=allow_redirects,
265266
) as response:
266267
_LOGGER.error("TESTv6 - Response code: %s", response.status)
267268

268269
# v6 responds with a 302 redirect and empty body
269270
if url != self._login_urls["v6_login"]:
271+
_LOGGER.error("TESTv6 - we are in v8, raising for status")
270272
response.raise_for_status()
271273

272274
response_text = await response.text()
@@ -277,6 +279,10 @@ async def _request_json(
277279
self._store_auth_data(response)
278280
self.connected = True
279281

282+
# V6 responsds with empty body on login, not JSON
283+
if url != self._login_urls["v6_login"] and not response_text:
284+
return {}
285+
280286
return json.loads(response_text)
281287
except aiohttp.ClientResponseError as err:
282288
_LOGGER.error(
@@ -345,6 +351,7 @@ async def login(self) -> None:
345351
headers=login_headers,
346352
form_data=v6_simple_multipart_form_data,
347353
authenticated=True,
354+
allow_redirects=False,
348355
)
349356
except (AirOSUrlNotFoundError, AirOSConnectionSetupError) as err:
350357
_LOGGER.error(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "airos"
7-
version = "0.5.7a6"
7+
version = "0.5.7a7"
88
license = "MIT"
99
description = "Ubiquiti airOS module(s) for Python 3."
1010
readme = "README.md"

tests/test_airos_request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def test_request_json_success(
5858
json=None,
5959
data=None,
6060
headers={},
61-
allow_redirects=False,
61+
allow_redirects=True,
6262
)
6363

6464

@@ -155,5 +155,5 @@ async def test_request_json_with_params_and_data(
155155
json=params,
156156
data=data,
157157
headers={},
158-
allow_redirects=False,
158+
allow_redirects=True,
159159
)

0 commit comments

Comments
 (0)