python-homewizard-energy 8.3.0__tar.gz → 8.3.2__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.
Files changed (16) hide show
  1. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/PKG-INFO +1 -1
  2. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/homewizard_energy.py +6 -2
  3. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/v2/__init__.py +15 -12
  4. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/pyproject.toml +2 -1
  5. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/LICENSE +0 -0
  6. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/README.md +0 -0
  7. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/__init__.py +0 -0
  8. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/const.py +0 -0
  9. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/errors.py +0 -0
  10. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/models.py +0 -0
  11. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/py.typed +0 -0
  12. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/utils.py +0 -0
  13. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/v1/__init__.py +0 -0
  14. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/v1/const.py +0 -0
  15. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/v2/cacert.py +0 -0
  16. {python_homewizard_energy-8.3.0 → python_homewizard_energy-8.3.2}/homewizard_energy/v2/const.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-homewizard-energy
3
- Version: 8.3.0
3
+ Version: 8.3.2
4
4
  Summary: Asynchronous Python client for the HomeWizard Energy
5
5
  Home-page: https://github.com/homewizard/python-homewizard-energy
6
6
  License: Apache-2.0
@@ -22,6 +22,8 @@ class HomeWizardEnergy:
22
22
 
23
23
  _device: Device | None = None
24
24
 
25
+ _lock: asyncio.Lock
26
+
25
27
  def __init__(
26
28
  self,
27
29
  host: str,
@@ -40,6 +42,8 @@ class HomeWizardEnergy:
40
42
  self._close_session = clientsession is None
41
43
  self._request_timeout = timeout
42
44
 
45
+ self._lock = asyncio.Lock()
46
+
43
47
  @property
44
48
  def host(self) -> str:
45
49
  """Return the hostname of the device.
@@ -117,6 +121,8 @@ class HomeWizardEnergy:
117
121
  async def _create_clientsession(self) -> None:
118
122
  """Create a client session."""
119
123
 
124
+ LOGGER.debug("Creating clientsession")
125
+
120
126
  if self._session is not None:
121
127
  raise RuntimeError("Session already exists")
122
128
 
@@ -131,8 +137,6 @@ class HomeWizardEnergy:
131
137
  connector=connector, timeout=ClientTimeout(total=self._request_timeout)
132
138
  )
133
139
 
134
- # self._session = self._create_clientsession(connector, timeout=ClientTimeout(total=self._request_timeout))
135
-
136
140
  async def __aenter__(self) -> HomeWizardEnergy:
137
141
  """Async enter.
138
142
 
@@ -221,11 +221,13 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
221
221
  ) -> tuple[HTTPStatus, dict[str, Any] | None]:
222
222
  """Make a request to the API."""
223
223
 
224
- if self._session is None:
225
- await self._create_clientsession()
224
+ async with self._lock:
225
+ if self._session is None:
226
+ await self._create_clientsession()
226
227
 
227
- if self._ssl is False:
228
- self._ssl = await self._get_ssl_context()
228
+ async with self._lock:
229
+ if self._ssl is False:
230
+ self._ssl = await self._get_ssl_context()
229
231
 
230
232
  # Construct request
231
233
  url = f"https://{self.host}{path}"
@@ -239,14 +241,15 @@ class HomeWizardEnergyV2(HomeWizardEnergy):
239
241
 
240
242
  try:
241
243
  async with async_timeout.timeout(self._request_timeout):
242
- resp = await self._session.request(
243
- method,
244
- url,
245
- json=data,
246
- headers=headers,
247
- ssl=self._ssl,
248
- server_hostname=self._identifier,
249
- )
244
+ async with self._lock:
245
+ resp = await self._session.request(
246
+ method,
247
+ url,
248
+ json=data,
249
+ headers=headers,
250
+ ssl=self._ssl,
251
+ server_hostname=self._identifier,
252
+ )
250
253
  LOGGER.debug("%s, %s", resp.status, await resp.text("utf-8"))
251
254
  except asyncio.TimeoutError as exception:
252
255
  raise RequestError(
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-homewizard-energy"
3
- version = "8.3.0"
3
+ version = "8.3.2"
4
4
  description = "Asynchronous Python client for the HomeWizard Energy"
5
5
  authors = ["DCSBL"]
6
6
  maintainers = ["DCSBL"]
@@ -107,6 +107,7 @@ max-attributes=20
107
107
 
108
108
  [tool.pytest.ini_options]
109
109
  addopts = "--cov"
110
+ asyncio_mode = "auto"
110
111
 
111
112
  [tool.vulture]
112
113
  min_confidence = 80