pypetkitapi 1.2.4__tar.gz → 1.2.5__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: 1.2.4
3
+ Version: 1.2.5
4
4
  Summary: Python client for PetKit API
5
5
  Home-page: https://github.com/Jezza34000/pypetkit
6
6
  License: MIT
@@ -241,7 +241,7 @@ class PetKitClient:
241
241
 
242
242
  end_time = datetime.now()
243
243
  total_time = end_time - start_time
244
- _LOGGER.info("Petkit data fetched successfully in: %s", total_time)
244
+ _LOGGER.debug("Petkit data fetched successfully in: %s", total_time)
245
245
 
246
246
  async def _fetch_device_data(
247
247
  self,
@@ -277,7 +277,7 @@ class PetKitClient:
277
277
  _LOGGER.debug("Reading device type : %s (id=%s)", device_type, device_id)
278
278
 
279
279
  endpoint = data_class.get_endpoint(device_type)
280
- query_param = data_class.query_param(account, device.device_id)
280
+ query_param = data_class.query_param(account, device_type, device.device_id)
281
281
 
282
282
  response = await self.req.request(
283
283
  method=HTTPMethod.POST,
@@ -286,6 +286,10 @@ class PetKitClient:
286
286
  headers=await self.get_session_id(),
287
287
  )
288
288
 
289
+ # Workaround for the litter box T6
290
+ if isinstance(response, dict) and response.get("list", None):
291
+ response = response.get("list")
292
+
289
293
  # Check if the response is a list or a dict
290
294
  if isinstance(response, list):
291
295
  device_data = [data_class(**item) for item in response]
@@ -316,7 +320,7 @@ class PetKitClient:
316
320
  device_id: int,
317
321
  action: StrEnum,
318
322
  setting: dict | None = None,
319
- ) -> None:
323
+ ) -> bool:
320
324
  """Control the device using the PetKit API."""
321
325
  device = self.petkit_entities.get(device_id)
322
326
  if not device:
@@ -345,9 +349,11 @@ class PetKitClient:
345
349
  _LOGGER.debug(action)
346
350
  _LOGGER.debug(action_info)
347
351
  if device_type not in action_info.supported_device:
348
- raise PypetkitError(
349
- f"Device type {device.device_type} not supported for action {action}."
352
+ _LOGGER.error(
353
+ "Device type %s not supported for action %s.", device_type, action
350
354
  )
355
+ return False
356
+
351
357
  # Get the endpoint
352
358
  if callable(action_info.endpoint):
353
359
  endpoint = action_info.endpoint(device)
@@ -372,8 +378,9 @@ class PetKitClient:
372
378
  if res in (SUCCESS_KEY, RES_KEY):
373
379
  # TODO : Manage to get the response from manual feeding
374
380
  _LOGGER.debug("Command executed successfully")
375
- else:
376
- _LOGGER.error("Command execution failed")
381
+ return True
382
+ _LOGGER.error("Command execution failed")
383
+ return False
377
384
 
378
385
  async def close(self) -> None:
379
386
  """Close the aiohttp session if it was created by the client."""
@@ -259,7 +259,11 @@ class FeederRecord(BaseModel):
259
259
 
260
260
  @classmethod
261
261
  def query_param(
262
- cls, account: AccountData, device_id: int, request_date: str | None = None
262
+ cls,
263
+ account: AccountData,
264
+ device_type: str,
265
+ device_id: int,
266
+ request_date: str | None = None,
263
267
  ) -> dict:
264
268
  """Generate query parameters including request_date."""
265
269
  if request_date is None:
@@ -305,6 +309,8 @@ class Feeder(BaseModel):
305
309
  return PetkitEndpoint.DEVICE_DETAIL
306
310
 
307
311
  @classmethod
308
- def query_param(cls, account: AccountData, device_id: int) -> dict:
312
+ def query_param(
313
+ cls, account: AccountData, device_type: str, device_id: int
314
+ ) -> dict:
309
315
  """Generate query parameters including request_date."""
310
316
  return {"id": device_id}
@@ -5,7 +5,7 @@ from typing import Any, ClassVar
5
5
 
6
6
  from pydantic import BaseModel, Field
7
7
 
8
- from pypetkitapi.const import DEVICE_DATA, DEVICE_RECORDS, PetkitEndpoint
8
+ from pypetkitapi.const import DEVICE_DATA, DEVICE_RECORDS, T4, T6, PetkitEndpoint
9
9
  from pypetkitapi.containers import AccountData, CloudProduct, FirmwareDetail, Wifi
10
10
 
11
11
 
@@ -226,16 +226,32 @@ class LitterRecord(BaseModel):
226
226
  @classmethod
227
227
  def get_endpoint(cls, device_type: str) -> str:
228
228
  """Get the endpoint URL for the given device type."""
229
- return PetkitEndpoint.GET_DEVICE_RECORD
229
+ if device_type == T4:
230
+ return PetkitEndpoint.GET_DEVICE_RECORD
231
+ if device_type == T6:
232
+ return PetkitEndpoint.GET_DEVICE_RECORD_RELEASE
233
+ raise ValueError(f"Invalid device type: {device_type}")
230
234
 
231
235
  @classmethod
232
236
  def query_param(
233
- cls, account: AccountData, device_id: int, request_date: str | None = None
237
+ cls,
238
+ account: AccountData,
239
+ device_type: str,
240
+ device_id: int,
241
+ request_date: str | None = None,
234
242
  ) -> dict:
235
243
  """Generate query parameters including request_date."""
236
- if request_date is None:
237
- request_date = datetime.now().strftime("%Y%m%d")
238
- return {"date": int(request_date), "deviceId": device_id}
244
+ if device_type == T4:
245
+ if request_date is None:
246
+ request_date = datetime.now().strftime("%Y%m%d")
247
+ return {"date": int(request_date), "deviceId": device_id}
248
+ if device_type == T6:
249
+ return {
250
+ "timestamp": int(datetime.now().timestamp()),
251
+ "deviceId": device_id,
252
+ "type": 2,
253
+ }
254
+ raise ValueError(f"Invalid device type: {device_type}")
239
255
 
240
256
 
241
257
  class Litter(BaseModel):
@@ -286,6 +302,8 @@ class Litter(BaseModel):
286
302
  return PetkitEndpoint.DEVICE_DETAIL
287
303
 
288
304
  @classmethod
289
- def query_param(cls, account: AccountData, device_id: int) -> dict:
305
+ def query_param(
306
+ cls, account: AccountData, device_type: str, device_id: int
307
+ ) -> dict:
290
308
  """Generate query parameters including request_date."""
291
309
  return {"id": device_id}
@@ -102,7 +102,11 @@ class WaterFountainRecord(BaseModel):
102
102
 
103
103
  @classmethod
104
104
  def query_param(
105
- cls, account: AccountData, device_id: int, request_date: str | None = None
105
+ cls,
106
+ account: AccountData,
107
+ device_type: str,
108
+ device_id: int,
109
+ request_date: str | None = None,
106
110
  ) -> dict:
107
111
  """Generate query parameters including request_date."""
108
112
  if not account.user_list or not account.user_list[0]:
@@ -168,6 +172,8 @@ class WaterFountain(BaseModel):
168
172
  return PetkitEndpoint.DEVICE_DATA
169
173
 
170
174
  @classmethod
171
- def query_param(cls, account: AccountData, device_id: int) -> dict:
175
+ def query_param(
176
+ cls, account: AccountData, device_type: str, device_id: int
177
+ ) -> dict:
172
178
  """Generate query parameters including request_date."""
173
179
  return {"id": device_id}
@@ -187,7 +187,7 @@ build-backend = "poetry.core.masonry.api"
187
187
 
188
188
  [tool.poetry]
189
189
  name = "pypetkitapi"
190
- version = "1.2.4"
190
+ version = "1.2.5"
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 = "1.2.4"
207
+ current_version = "1.2.5"
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