pypetkitapi 0.2.0__py3-none-any.whl → 0.2.1__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.
pypetkitapi/client.py CHANGED
@@ -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:
@@ -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
@@ -1,5 +1,5 @@
1
1
  pypetkitapi/__init__.py,sha256=eVpyGMD3tkYtiHUkdKEeNSZhQlZ4woI2Y5oVoV7CwXM,61
2
- pypetkitapi/client.py,sha256=tbYTezkPZMDtKCM3M9QjlWK9WzUEDYt5o9w7WjQpsJM,14209
2
+ pypetkitapi/client.py,sha256=xfdhNAW3jsq9xQWgnEZTc2fAH7z4GHA3jtZlwDlmgCc,14635
3
3
  pypetkitapi/command.py,sha256=ibJ0zenONy-FBvUvyIA_IvUnYEUezLpPxhC_9XZ6SwM,9282
4
4
  pypetkitapi/const.py,sha256=49NMRaCGok20P-qfzlL6PH7QN9-QDuAsPh2Fejqf2iE,2945
5
5
  pypetkitapi/containers.py,sha256=GQqZKaDgemQM4UDnugWYDP7N01anpJwO4VjQy2Gla3E,3109
@@ -7,7 +7,7 @@ pypetkitapi/exceptions.py,sha256=f9QY1EME9ha_vJJx4DuL_OBNpoynYVdtMFtVZbdfook,112
7
7
  pypetkitapi/feeder_container.py,sha256=IGXeAEbLkZhOTCzF2MhwqadIAKXg6jHbfU037dt6byY,10985
8
8
  pypetkitapi/litter_container.py,sha256=aLAvcB8K_nx7iBRkAarZs-48HAj2NkG7XjJFonWMuME,8948
9
9
  pypetkitapi/water_fountain_container.py,sha256=LcCTDjk7eSbnF7e38xev3D5mCv5wwJ6go8WGGBv-CaU,5278
10
- pypetkitapi-0.2.0.dist-info/LICENSE,sha256=4FWnKolNLc1e3w6cVlT61YxfPh0DQNeQLN1CepKKSBg,1067
11
- pypetkitapi-0.2.0.dist-info/METADATA,sha256=bQFC9AJGJmBF2TmX2BeytugFr63V4rtlxpzrjQSIhME,3700
12
- pypetkitapi-0.2.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
13
- pypetkitapi-0.2.0.dist-info/RECORD,,
10
+ pypetkitapi-0.2.1.dist-info/LICENSE,sha256=4FWnKolNLc1e3w6cVlT61YxfPh0DQNeQLN1CepKKSBg,1067
11
+ pypetkitapi-0.2.1.dist-info/METADATA,sha256=mb2SmQx9J0Vx-N5ukYHAlUodTLrU0M1TYc0psdIb57E,3700
12
+ pypetkitapi-0.2.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
13
+ pypetkitapi-0.2.1.dist-info/RECORD,,