pypetkitapi 1.2.3__py3-none-any.whl → 1.2.5__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
@@ -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
 
@@ -142,7 +142,7 @@ class StateLitter(BaseModel):
142
142
  work_state: WorkState | None = Field(None, alias="workState")
143
143
 
144
144
 
145
- class Content(BaseModel):
145
+ class ContentSC(BaseModel):
146
146
  """Dataclass for content data."""
147
147
 
148
148
  box: int | None = None
@@ -157,11 +157,22 @@ class Content(BaseModel):
157
157
  upload: int | None = None
158
158
 
159
159
 
160
- class SubContent(BaseModel):
160
+ class LRContent(BaseModel):
161
+ """Dataclass for pet data."""
162
+
163
+ auto_clear: int | None = Field(None, alias="autoClear")
164
+ interval: int | None = None
165
+ pet_weight: int | None = Field(None, alias="petWeight")
166
+ time_in: int | None = Field(None, alias="timeIn")
167
+ time_out: int | None = Field(None, alias="timeOut")
168
+ error: int | None = None
169
+
170
+
171
+ class LRSubContent(BaseModel):
161
172
  """Dataclass for sub-content data."""
162
173
 
163
174
  aes_key: str | None = Field(None, alias="aesKey")
164
- content: Content | None = None
175
+ content: ContentSC | None = None
165
176
  device_id: int | None = Field(None, alias="deviceId")
166
177
  duration: int | None = None
167
178
  enum_event_type: str | None = Field(None, alias="enumEventType")
@@ -189,7 +200,7 @@ class LitterRecord(BaseModel):
189
200
 
190
201
  aes_key: str | None = Field(None, alias="aesKey")
191
202
  avatar: str | None = None
192
- content: dict[str, Any] | None = None
203
+ content: LRContent | None = None
193
204
  device_id: int | None = Field(None, alias="deviceId")
194
205
  duration: int | None = None
195
206
  enum_event_type: str | None = Field(None, alias="enumEventType")
@@ -205,7 +216,7 @@ class LitterRecord(BaseModel):
205
216
  preview: str | None = None
206
217
  related_event: str | None = Field(None, alias="relatedEvent")
207
218
  storage_space: int | None = Field(None, alias="storageSpace")
208
- sub_content: list[SubContent] | None = Field(None, alias="subContent")
219
+ sub_content: list[LRSubContent] | None = Field(None, alias="subContent")
209
220
  timestamp: int | None = None
210
221
  toilet_detection: int | None = Field(None, alias="toiletDetection")
211
222
  upload: int | None = None
@@ -215,16 +226,32 @@ class LitterRecord(BaseModel):
215
226
  @classmethod
216
227
  def get_endpoint(cls, device_type: str) -> str:
217
228
  """Get the endpoint URL for the given device type."""
218
- 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}")
219
234
 
220
235
  @classmethod
221
236
  def query_param(
222
- 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,
223
242
  ) -> dict:
224
243
  """Generate query parameters including request_date."""
225
- if request_date is None:
226
- request_date = datetime.now().strftime("%Y%m%d")
227
- 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}")
228
255
 
229
256
 
230
257
  class Litter(BaseModel):
@@ -267,7 +294,7 @@ class Litter(BaseModel):
267
294
  service_status: int | None = Field(None, alias="serviceStatus")
268
295
  total_time: int | None = Field(None, alias="totalTime")
269
296
  device_type: str | None = Field(None, alias="deviceType")
270
- device_records: LitterRecord | None = None
297
+ device_records: list[LitterRecord] | None = None
271
298
 
272
299
  @classmethod
273
300
  def get_endpoint(cls, device_type: str) -> str:
@@ -275,6 +302,8 @@ class Litter(BaseModel):
275
302
  return PetkitEndpoint.DEVICE_DETAIL
276
303
 
277
304
  @classmethod
278
- 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:
279
308
  """Generate query parameters including request_date."""
280
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}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pypetkitapi
3
- Version: 1.2.3
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
@@ -0,0 +1,14 @@
1
+ pypetkitapi/__init__.py,sha256=eVpyGMD3tkYtiHUkdKEeNSZhQlZ4woI2Y5oVoV7CwXM,61
2
+ pypetkitapi/client.py,sha256=1jWE1BhdOycRstg_qm1mIu9ZHjlJ4rOJNRZ3Zd5K-KA,16753
3
+ pypetkitapi/command.py,sha256=gw3_J_oZHuuGLk66P8uRSqSrySjYa8ArpKaPHi2ybCw,7155
4
+ pypetkitapi/const.py,sha256=Mxgezd9sy-LtpgjYuVKb9ii9HSUnz8FVyKx1GXbXBAU,3291
5
+ pypetkitapi/containers.py,sha256=m7vzWcJG0U1EPftuBF6OB8eTVRhCoA2DFqekxI6LozI,3428
6
+ pypetkitapi/exceptions.py,sha256=NWmpsI2ewC4HaIeu_uFwCeuPIHIJxZBzjoCP7aNwvhs,1139
7
+ pypetkitapi/feeder_container.py,sha256=ASsIUxzrQTJ1K0ArVQwJAPpmX9S9nvPevtCu6b1UdQA,13273
8
+ pypetkitapi/litter_container.py,sha256=wYxeq7hDF1UxQN1NFE-nELbxnciwYTFzXHklGY1mQnI,13992
9
+ pypetkitapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ pypetkitapi/water_fountain_container.py,sha256=uN7MJodxQ-Ow8BGRQkXP_Zyrww2wJksyyJ8LIqEC3SQ,6709
11
+ pypetkitapi-1.2.5.dist-info/LICENSE,sha256=4FWnKolNLc1e3w6cVlT61YxfPh0DQNeQLN1CepKKSBg,1067
12
+ pypetkitapi-1.2.5.dist-info/METADATA,sha256=80J-aVK676hQHc9S2_8ZQHapyhmC-UQO8k4BAgHq9tQ,4590
13
+ pypetkitapi-1.2.5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
14
+ pypetkitapi-1.2.5.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- pypetkitapi/__init__.py,sha256=eVpyGMD3tkYtiHUkdKEeNSZhQlZ4woI2Y5oVoV7CwXM,61
2
- pypetkitapi/client.py,sha256=7-eWcDXxo2OtK_YN-MMmWo7g_O3FisjGJBTxR-FtVEU,16538
3
- pypetkitapi/command.py,sha256=gw3_J_oZHuuGLk66P8uRSqSrySjYa8ArpKaPHi2ybCw,7155
4
- pypetkitapi/const.py,sha256=Mxgezd9sy-LtpgjYuVKb9ii9HSUnz8FVyKx1GXbXBAU,3291
5
- pypetkitapi/containers.py,sha256=m7vzWcJG0U1EPftuBF6OB8eTVRhCoA2DFqekxI6LozI,3428
6
- pypetkitapi/exceptions.py,sha256=NWmpsI2ewC4HaIeu_uFwCeuPIHIJxZBzjoCP7aNwvhs,1139
7
- pypetkitapi/feeder_container.py,sha256=8toLt9YSvEvjNSy9b6jwHSNZxuXP6D1ZnrnUdL78K6s,13190
8
- pypetkitapi/litter_container.py,sha256=-2pwUdpg48gcBQb-68zX3J6RHoslhVjucF6RvfuqQ2g,13049
9
- pypetkitapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- pypetkitapi/water_fountain_container.py,sha256=Lr1qc_hh2DKtIQEFMsLGJhRcguGhWn6-bm7UfBMT15A,6626
11
- pypetkitapi-1.2.3.dist-info/LICENSE,sha256=4FWnKolNLc1e3w6cVlT61YxfPh0DQNeQLN1CepKKSBg,1067
12
- pypetkitapi-1.2.3.dist-info/METADATA,sha256=2PCwdvnC6vGtJCMF0hYXgKVihF0UyLKBWm_-x6Xnn4E,4590
13
- pypetkitapi-1.2.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
14
- pypetkitapi-1.2.3.dist-info/RECORD,,