pypetkitapi 1.2.4__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 +14 -7
- pypetkitapi/feeder_container.py +8 -2
- pypetkitapi/litter_container.py +25 -7
- pypetkitapi/water_fountain_container.py +8 -2
- {pypetkitapi-1.2.4.dist-info → pypetkitapi-1.2.5.dist-info}/METADATA +1 -1
- pypetkitapi-1.2.5.dist-info/RECORD +14 -0
- pypetkitapi-1.2.4.dist-info/RECORD +0 -14
- {pypetkitapi-1.2.4.dist-info → pypetkitapi-1.2.5.dist-info}/LICENSE +0 -0
- {pypetkitapi-1.2.4.dist-info → pypetkitapi-1.2.5.dist-info}/WHEEL +0 -0
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.
|
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
|
-
) ->
|
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
|
-
|
349
|
-
|
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
|
-
|
376
|
-
|
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."""
|
pypetkitapi/feeder_container.py
CHANGED
@@ -259,7 +259,11 @@ class FeederRecord(BaseModel):
|
|
259
259
|
|
260
260
|
@classmethod
|
261
261
|
def query_param(
|
262
|
-
cls,
|
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(
|
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}
|
pypetkitapi/litter_container.py
CHANGED
@@ -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
|
-
|
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,
|
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
|
237
|
-
request_date
|
238
|
-
|
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(
|
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,
|
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(
|
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}
|
@@ -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=F16kIMlgqk97ewQrqsIPY6NX7qWvfQ2qM4If68Tq5Yg,13414
|
9
|
-
pypetkitapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
-
pypetkitapi/water_fountain_container.py,sha256=Lr1qc_hh2DKtIQEFMsLGJhRcguGhWn6-bm7UfBMT15A,6626
|
11
|
-
pypetkitapi-1.2.4.dist-info/LICENSE,sha256=4FWnKolNLc1e3w6cVlT61YxfPh0DQNeQLN1CepKKSBg,1067
|
12
|
-
pypetkitapi-1.2.4.dist-info/METADATA,sha256=NRf9Cu42Kl8Zngxerji1AIppGxN3Pojeq97bTDJGsYc,4590
|
13
|
-
pypetkitapi-1.2.4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
14
|
-
pypetkitapi-1.2.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|