pypetkitapi 0.2.0__tar.gz → 0.2.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.1
2
2
  Name: pypetkitapi
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Python client for PetKit API
5
5
  Home-page: https://github.com/Jezza34000/pypetkit
6
6
  License: MIT
@@ -18,6 +18,7 @@ from pypetkitapi.const import (
18
18
  ERR_KEY,
19
19
  LOGIN_DATA,
20
20
  RES_KEY,
21
+ SUCCESS_KEY,
21
22
  Header,
22
23
  PetkitEndpoint,
23
24
  PetkitURL,
@@ -45,7 +46,7 @@ class PetKitClient:
45
46
  _session: SessionInfo | None = None
46
47
  _servers_list: list[RegionInfo] = []
47
48
  account_data: list[AccountData] = []
48
- device_list: list[Feeder | Litter | WaterFountain] = []
49
+ device_list: dict[int, Feeder | Litter | WaterFountain] = {}
49
50
 
50
51
  def __init__(
51
52
  self,
@@ -263,22 +264,28 @@ class PetKitClient:
263
264
  )
264
265
  device_data = data_class(**response)
265
266
  device_data.device_type = device.device_type # Add the device_type attribute
266
- _LOGGER.debug("Reading device type : %s", device.device_type)
267
- self.device_list.append(device_data)
267
+ _LOGGER.debug(
268
+ "Reading device type : %s (id=%s)", device.device_type, device.device_id
269
+ )
270
+ self.device_list[device.device_id] = device_data
268
271
 
269
272
  async def send_api_request(
270
273
  self,
271
- device: Feeder | Litter | WaterFountain,
274
+ device_id: int,
272
275
  action: StrEnum,
273
276
  setting: dict | None = None,
274
277
  ) -> None:
275
278
  """Control the device using the PetKit API."""
279
+ device = self.device_list.get(device_id)
280
+ if not device:
281
+ raise PypetkitError(f"Device with ID {device_id} not found.")
276
282
 
277
283
  _LOGGER.debug(
278
- "Control API: %s %s %s",
284
+ "Control API device=%s id=%s action=%s param=%s",
285
+ device.device_type,
286
+ device_id,
279
287
  action,
280
288
  setting,
281
- device,
282
289
  )
283
290
 
284
291
  if device.device_type:
@@ -312,12 +319,16 @@ class PetKitClient:
312
319
  params = action_info.params(device)
313
320
 
314
321
  prep_req = PrepReq(base_url=self._base_url)
315
- await prep_req.request(
322
+ res = await prep_req.request(
316
323
  method=HTTPMethod.POST,
317
324
  url=url,
318
325
  data=params,
319
326
  headers=headers,
320
327
  )
328
+ if res == SUCCESS_KEY:
329
+ _LOGGER.info("Command executed successfully")
330
+ else:
331
+ _LOGGER.error("Command execution failed")
321
332
 
322
333
 
323
334
  class PrepReq:
@@ -187,7 +187,7 @@ build-backend = "poetry.core.masonry.api"
187
187
 
188
188
  [tool.poetry]
189
189
  name = "pypetkitapi"
190
- version = "0.2.0"
190
+ version = "0.2.1"
191
191
  description = "Python client for PetKit API"
192
192
  authors = ["Jezza34000 <info@mail.com>"]
193
193
  readme = "README.md"
@@ -204,7 +204,7 @@ black = "^24.10.0"
204
204
  ruff = "^0.8.1"
205
205
 
206
206
  [tool.bumpver]
207
- current_version = "0.2.0"
207
+ current_version = "0.2.1"
208
208
  version_pattern = "MAJOR.MINOR.PATCH"
209
209
  commit_message = "bump version {old_version} -> {new_version}"
210
210
  tag_message = "{new_version}"
File without changes
File without changes