python-xiaobiu 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-xiaobiu
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Suning biu smart home SMS login and session client
5
5
  Project-URL: Homepage, https://github.com/FaintGhost/python-xiaobiu
6
6
  Project-URL: Bug Tracker, https://github.com/FaintGhost/python-xiaobiu/issues
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-xiaobiu"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  description = "Suning biu smart home SMS login and session client"
5
5
  readme = "README.md"
6
6
  license = { text = "MIT" }
@@ -632,6 +632,7 @@ class SuningSmartHomeClient:
632
632
 
633
633
  response = send_request()
634
634
  if self._is_login_redirect(response):
635
+ self.bootstrap_service("shcss")
635
636
  self.bootstrap_service("itapig")
636
637
  response = send_request()
637
638
  if self._is_login_redirect(response):
@@ -885,10 +886,8 @@ class SuningSmartHomeClient:
885
886
 
886
887
  def keep_alive(self) -> dict[str, Any]:
887
888
  member_info = self.query_member_base_info()
888
- family_info = self.list_families()
889
889
  return {
890
890
  "member": member_info,
891
- "families": family_info,
892
891
  }
893
892
 
894
893
  def save_state(self) -> None:
@@ -3,8 +3,11 @@ from __future__ import annotations
3
3
  import json
4
4
  from urllib.parse import unquote_plus
5
5
 
6
+ import pytest
7
+
6
8
  from xiaobiu import SuningSmartHomeClient, parse_jsonp_or_json
7
9
  from xiaobiu.client import (
10
+ AuthenticationError,
8
11
  CaptchaRequiredError,
9
12
  CaptchaSolution,
10
13
  DEVICE_LIST_URL,
@@ -368,6 +371,52 @@ def test_list_devices_builds_dynamic_signed_request(monkeypatch) -> None:
368
371
  assert payload["responseCode"] == "0"
369
372
 
370
373
 
374
+ def test_request_app_api_rehydrates_shcss_before_itapig(monkeypatch) -> None:
375
+ client = SuningSmartHomeClient()
376
+ calls: list[tuple[str, str]] = []
377
+ bootstrap_calls: list[str] = []
378
+
379
+ class RedirectResponse:
380
+ status_code = 302
381
+ headers = {"Location": "https://passport.suning.com/ids/login?service=itapig"}
382
+
383
+ class SuccessResponse:
384
+ status_code = 200
385
+ headers: dict[str, str] = {}
386
+
387
+ def fake_request(method: str, url: str, **kwargs):
388
+ calls.append((method, url))
389
+ if len(calls) == 1:
390
+ return RedirectResponse()
391
+ return SuccessResponse()
392
+
393
+ monkeypatch.setattr(client.session, "request", fake_request)
394
+ monkeypatch.setattr(client, "bootstrap_service", lambda service_name: bootstrap_calls.append(service_name))
395
+
396
+ response = client._request_app_api(FAMILY_LIST_URL) # noqa: SLF001
397
+
398
+ assert response.status_code == 200
399
+ assert calls == [("POST", FAMILY_LIST_URL), ("POST", FAMILY_LIST_URL)]
400
+ assert bootstrap_calls == ["shcss", "itapig"]
401
+
402
+
403
+ def test_request_app_api_raises_after_failed_rebootstrap(monkeypatch) -> None:
404
+ client = SuningSmartHomeClient()
405
+ bootstrap_calls: list[str] = []
406
+
407
+ class RedirectResponse:
408
+ status_code = 302
409
+ headers = {"Location": "https://passport.suning.com/ids/login?service=itapig"}
410
+
411
+ monkeypatch.setattr(client.session, "request", lambda *_args, **_kwargs: RedirectResponse())
412
+ monkeypatch.setattr(client, "bootstrap_service", lambda service_name: bootstrap_calls.append(service_name))
413
+
414
+ with pytest.raises(AuthenticationError, match="itapig service bootstrap failed"):
415
+ client._request_app_api(FAMILY_LIST_URL) # noqa: SLF001
416
+
417
+ assert bootstrap_calls == ["shcss", "itapig"]
418
+
419
+
371
420
  def test_prepare_sms_login_uses_mobile_post_form(monkeypatch) -> None:
372
421
  client = SuningSmartHomeClient()
373
422
  cipher = SuAESCipher()
@@ -596,6 +645,22 @@ def test_list_family_infos_parses_expected_payload_shape(monkeypatch) -> None:
596
645
  assert families[0].name == "我的家"
597
646
 
598
647
 
648
+ def test_keep_alive_only_queries_member_info(monkeypatch) -> None:
649
+ client = SuningSmartHomeClient()
650
+ member_payload = {"code": "0", "desc": "SUCCESS"}
651
+
652
+ monkeypatch.setattr(client, "query_member_base_info", lambda: member_payload)
653
+ monkeypatch.setattr(
654
+ client,
655
+ "list_families",
656
+ lambda: (_ for _ in ()).throw(AssertionError("keep_alive should not call list_families")),
657
+ )
658
+
659
+ payload = client.keep_alive()
660
+
661
+ assert payload == {"member": member_payload}
662
+
663
+
599
664
  def test_list_family_infos_accepts_id_field_from_live_api(monkeypatch) -> None:
600
665
  client = SuningSmartHomeClient()
601
666
 
File without changes
File without changes