aioamazondevices 3.1.23__py3-none-any.whl → 3.2.0__py3-none-any.whl

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
  """aioamazondevices library."""
2
2
 
3
- __version__ = "3.1.23"
3
+ __version__ = "3.2.0"
4
4
 
5
5
 
6
6
  from .api import AmazonDevice, AmazonEchoApi
aioamazondevices/api.py CHANGED
@@ -56,6 +56,7 @@ from .exceptions import (
56
56
  CannotConnect,
57
57
  CannotRegisterDevice,
58
58
  CannotRetrieveData,
59
+ WrongCountry,
59
60
  WrongMethod,
60
61
  )
61
62
  from .utils import obfuscate_email, scrub_fields
@@ -525,6 +526,31 @@ class AmazonEchoApi:
525
526
  await self._save_to_file(login_data, "login_data", JSON_EXTENSION)
526
527
  return login_data
527
528
 
529
+ async def _check_country(self) -> None:
530
+ """Check if user selected country matches Amazon account country."""
531
+ url = f"https://alexa.amazon.{self._domain}/api/users/me"
532
+ _, resp_me = await self._session_request(HTTPMethod.GET, url)
533
+
534
+ if resp_me.status != HTTPStatus.OK:
535
+ raise CannotAuthenticate
536
+
537
+ resp_me_json = await resp_me.json()
538
+ market = resp_me_json["marketPlaceDomainName"]
539
+ language = resp_me_json["marketPlaceLocale"]
540
+
541
+ _domain = f"https://www.amazon.{self._domain}"
542
+
543
+ if market != _domain or language != self._language:
544
+ _LOGGER.debug(
545
+ "Selected country <%s> doesn't matches Amazon account:\n%s\n vs \n%s",
546
+ self._login_country_code.upper(),
547
+ {"site ": _domain, "locale": self._language},
548
+ {"market": market, "locale": language},
549
+ )
550
+ raise WrongCountry
551
+
552
+ _LOGGER.debug("User selected country matches Amazon account one")
553
+
528
554
  async def _get_devices_ids(self) -> list[dict[str, str]]:
529
555
  """Retrieve devices entityId and applianceId."""
530
556
  _, raw_resp = await self._session_request(
@@ -698,6 +724,9 @@ class AmazonEchoApi:
698
724
  self._login_stored_data = register_device
699
725
 
700
726
  _LOGGER.info("Register device: %s", scrub_fields(register_device))
727
+
728
+ await self._check_country()
729
+
701
730
  return register_device
702
731
 
703
732
  async def login_mode_stored_data(self) -> dict[str, Any]:
@@ -716,6 +745,8 @@ class AmazonEchoApi:
716
745
 
717
746
  self._client_session()
718
747
 
748
+ await self._check_country()
749
+
719
750
  return self._login_stored_data
720
751
 
721
752
  async def close(self) -> None:
@@ -25,3 +25,7 @@ class CannotRegisterDevice(AmazonError):
25
25
 
26
26
  class WrongMethod(AmazonError):
27
27
  """Exception raised when the wrong login metho is used."""
28
+
29
+
30
+ class WrongCountry(AmazonError):
31
+ """Exceptio nraised when Amazon country."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aioamazondevices
3
- Version: 3.1.23
3
+ Version: 3.2.0
4
4
  Summary: Python library to control Amazon devices
5
5
  License: Apache-2.0
6
6
  Author: Simone Chemelli
@@ -0,0 +1,11 @@
1
+ aioamazondevices/__init__.py,sha256=2bsaWXIfe39pE5Jjw25d1t7wCVNWK36dLG4zXoSQZpU,276
2
+ aioamazondevices/api.py,sha256=W4LyCmiWCSJlHzpTSAQkb8DMcZbBQxJufZ3lnSasiik,38648
3
+ aioamazondevices/const.py,sha256=J47aHAfoA6rRgHDvn-q_S4xp8MrC6O1rEk1ZeRnN-8E,8529
4
+ aioamazondevices/exceptions.py,sha256=CfOFKDvE_yl5BFoFcpTOuDfgRi_2oAtKk-nNJgfWBAs,726
5
+ aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ aioamazondevices/sounds.py,sha256=01pVCDFIuhrLypXInw4JNuHsC6zjMLsuKocet1R6we8,13409
7
+ aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
8
+ aioamazondevices-3.2.0.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
9
+ aioamazondevices-3.2.0.dist-info/METADATA,sha256=7d6AfzuC3n4IVSV1FWk37dR_Ruej_mCc1coKc5KE_yY,5234
10
+ aioamazondevices-3.2.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
+ aioamazondevices-3.2.0.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- aioamazondevices/__init__.py,sha256=mZIaRiUx4hb3bx5kIhZc9PX7hxD-qnhod-h81ENTXac,277
2
- aioamazondevices/api.py,sha256=J4e85fBrHIWPeTvP7TYsezvdHKQ0I_Pqz3HCcdmF6J8,37542
3
- aioamazondevices/const.py,sha256=J47aHAfoA6rRgHDvn-q_S4xp8MrC6O1rEk1ZeRnN-8E,8529
4
- aioamazondevices/exceptions.py,sha256=JDnSFi_7oEhqK31sHXf0S_cyMoMjiRJuLp4ow7mYgLY,643
5
- aioamazondevices/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- aioamazondevices/sounds.py,sha256=01pVCDFIuhrLypXInw4JNuHsC6zjMLsuKocet1R6we8,13409
7
- aioamazondevices/utils.py,sha256=RzuKRhnq_8ymCoJMoQJ2vBYyuew06RSWpqQWmqdNczE,2019
8
- aioamazondevices-3.1.23.dist-info/LICENSE,sha256=sS48k5sp9bFV-NSHDfAJuTZZ_-AP9ZDqUzQ9sffGlsg,11346
9
- aioamazondevices-3.1.23.dist-info/METADATA,sha256=xEheLDnUfjp1pQbgAMvDsWmOcG5xnDnU8eZfmYSWg4A,5235
10
- aioamazondevices-3.1.23.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
- aioamazondevices-3.1.23.dist-info/RECORD,,