pypetkitapi 1.7.5__py3-none-any.whl → 1.7.7__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 +20 -10
- pypetkitapi/const.py +2 -1
- pypetkitapi/exceptions.py +5 -1
- pypetkitapi/feeder_container.py +8 -3
- pypetkitapi/medias.py +2 -1
- {pypetkitapi-1.7.5.dist-info → pypetkitapi-1.7.7.dist-info}/METADATA +1 -1
- pypetkitapi-1.7.7.dist-info/RECORD +15 -0
- pypetkitapi-1.7.5.dist-info/RECORD +0 -15
- {pypetkitapi-1.7.5.dist-info → pypetkitapi-1.7.7.dist-info}/LICENSE +0 -0
- {pypetkitapi-1.7.5.dist-info → pypetkitapi-1.7.7.dist-info}/WHEEL +0 -0
pypetkitapi/client.py
CHANGED
@@ -30,9 +30,11 @@ from pypetkitapi.const import (
|
|
30
30
|
from pypetkitapi.containers import AccountData, Device, Pet, RegionInfo, SessionInfo
|
31
31
|
from pypetkitapi.exceptions import (
|
32
32
|
PetkitAuthenticationError,
|
33
|
+
PetkitAuthenticationUnregisteredEmailError,
|
33
34
|
PetkitInvalidHTTPResponseCodeError,
|
34
35
|
PetkitInvalidResponseFormat,
|
35
36
|
PetkitRegionalServerNotFoundError,
|
37
|
+
PetkitSessionExpiredError,
|
36
38
|
PetkitTimeoutError,
|
37
39
|
PypetkitError,
|
38
40
|
)
|
@@ -87,6 +89,7 @@ class PetKitClient:
|
|
87
89
|
for region in response.get("list", []):
|
88
90
|
server = RegionInfo(**region)
|
89
91
|
if server.name.lower() == self.region or server.id.lower() == self.region:
|
92
|
+
self.region = server.id.lower()
|
90
93
|
self.req.base_url = server.gateway
|
91
94
|
_LOGGER.debug("Found matching server: %s", server)
|
92
95
|
return
|
@@ -529,17 +532,24 @@ class PrepReq:
|
|
529
532
|
|
530
533
|
# Check for errors in the response
|
531
534
|
if ERR_KEY in response_json:
|
535
|
+
error_code = int(response_json[ERR_KEY].get("code", 0))
|
532
536
|
error_msg = response_json[ERR_KEY].get("msg", "Unknown error")
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
537
|
+
|
538
|
+
match error_code:
|
539
|
+
case 5:
|
540
|
+
raise PetkitSessionExpiredError(f"Session expired: {error_msg}")
|
541
|
+
case 122:
|
542
|
+
raise PetkitAuthenticationError(
|
543
|
+
f"Authentication failed: {error_msg}"
|
544
|
+
)
|
545
|
+
case 125:
|
546
|
+
raise PetkitAuthenticationUnregisteredEmailError(
|
547
|
+
f"Authentication failed: {error_msg}"
|
548
|
+
)
|
549
|
+
case _:
|
550
|
+
raise PypetkitError(
|
551
|
+
f"Request failed code : {error_code} details : {error_msg}"
|
552
|
+
)
|
543
553
|
|
544
554
|
# Check for success in the response
|
545
555
|
if RES_KEY in response_json:
|
pypetkitapi/const.py
CHANGED
@@ -131,4 +131,5 @@ class PetkitEndpoint(StrEnum):
|
|
131
131
|
MANUAL_FEED_MINI = "feedermini/save_dailyfeed"
|
132
132
|
MANUAL_FEED_FRESH_ELEMENT = "feeder/save_dailyfeed"
|
133
133
|
MANUAL_FEED_DUAL = "saveDailyFeed"
|
134
|
-
DAILY_FEED_AND_EAT = "dailyFeedAndEat"
|
134
|
+
DAILY_FEED_AND_EAT = "dailyFeedAndEat" # D3
|
135
|
+
FEED_STATISTIC = "feedStatistic" # D4
|
pypetkitapi/exceptions.py
CHANGED
@@ -11,10 +11,14 @@ class PetkitTimeoutError(PypetkitError):
|
|
11
11
|
"""Class for PyPetkit timeout exceptions."""
|
12
12
|
|
13
13
|
|
14
|
-
class
|
14
|
+
class PetkitSessionExpiredError(PypetkitError):
|
15
15
|
"""Class for PyPetkit connection exceptions."""
|
16
16
|
|
17
17
|
|
18
|
+
class PetkitAuthenticationUnregisteredEmailError(PypetkitError):
|
19
|
+
"""Exception raised when the email is not registered with Petkit."""
|
20
|
+
|
21
|
+
|
18
22
|
class PetkitRegionalServerNotFoundError(PypetkitError):
|
19
23
|
"""Exception raised when the specified region server is not found."""
|
20
24
|
|
pypetkitapi/feeder_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 D3, DEVICE_DATA, DEVICE_RECORDS, PetkitEndpoint
|
8
|
+
from pypetkitapi.const import D3, D4, DEVICE_DATA, DEVICE_RECORDS, PetkitEndpoint
|
9
9
|
from pypetkitapi.containers import CloudProduct, Device, FirmwareDetail, Wifi
|
10
10
|
|
11
11
|
|
@@ -271,6 +271,8 @@ class FeederRecord(BaseModel):
|
|
271
271
|
"""Get the endpoint URL for the given device type."""
|
272
272
|
if device_type == D3:
|
273
273
|
return PetkitEndpoint.DAILY_FEED_AND_EAT
|
274
|
+
if device_type == D4:
|
275
|
+
return PetkitEndpoint.FEED_STATISTIC
|
274
276
|
return PetkitEndpoint.GET_DEVICE_RECORD
|
275
277
|
|
276
278
|
@classmethod
|
@@ -283,7 +285,10 @@ class FeederRecord(BaseModel):
|
|
283
285
|
"""Generate query parameters including request_date."""
|
284
286
|
if request_date is None:
|
285
287
|
request_date = datetime.now().strftime("%Y%m%d")
|
286
|
-
|
288
|
+
|
289
|
+
if device.device_type.lower() == D4:
|
290
|
+
return {"date": request_date, "type": 0, "deviceId": device.device_id}
|
291
|
+
return {"days": request_date, "deviceId": device.device_id}
|
287
292
|
|
288
293
|
|
289
294
|
class Feeder(BaseModel):
|
@@ -296,7 +301,7 @@ class Feeder(BaseModel):
|
|
296
301
|
cloud_product: CloudProduct | None = Field(None, alias="cloudProduct")
|
297
302
|
created_at: str | None = Field(None, alias="createdAt")
|
298
303
|
firmware: float
|
299
|
-
firmware_details: list[FirmwareDetail] = Field(alias="firmwareDetails")
|
304
|
+
firmware_details: list[FirmwareDetail] | None = Field(None, alias="firmwareDetails")
|
300
305
|
hardware: int
|
301
306
|
id: int
|
302
307
|
locale: str | None = None
|
pypetkitapi/medias.py
CHANGED
@@ -194,5 +194,6 @@ class MediaDownloadDecode:
|
|
194
194
|
except Exception as e: # noqa: BLE001
|
195
195
|
logging.error("Error decrypting image from file %s: %s", file_path, e)
|
196
196
|
return None
|
197
|
-
Path(file_path).
|
197
|
+
if Path(file_path).exists():
|
198
|
+
Path(file_path).unlink()
|
198
199
|
return decrypted_data
|
@@ -0,0 +1,15 @@
|
|
1
|
+
pypetkitapi/__init__.py,sha256=eVpyGMD3tkYtiHUkdKEeNSZhQlZ4woI2Y5oVoV7CwXM,61
|
2
|
+
pypetkitapi/client.py,sha256=nsQX5vULtmecj-m5p46GMws25-yQn_Ot9c5wHKh25NQ,20331
|
3
|
+
pypetkitapi/command.py,sha256=gw3_J_oZHuuGLk66P8uRSqSrySjYa8ArpKaPHi2ybCw,7155
|
4
|
+
pypetkitapi/const.py,sha256=yXRk3734QjuSH0HPosEIIbi3kjv-Oke6Q5z2MDNrfDo,3528
|
5
|
+
pypetkitapi/containers.py,sha256=nhp50QwyoQRveTnEgWL7JFEY3Tl5m5wp9EqZvklW87Y,4338
|
6
|
+
pypetkitapi/exceptions.py,sha256=fuTLT6Iw2_kA7eOyNJPf59vQkgfByhAnTThY4lC0Rt0,1283
|
7
|
+
pypetkitapi/feeder_container.py,sha256=YFVUAb-q7FfakCrehBHunCtIUlcfo4Ebo_dujq208Fo,14289
|
8
|
+
pypetkitapi/litter_container.py,sha256=wsM-v7ibx17lsD-o17RGz2wvcHCUu1iZ2RqAh3CN1Qc,18254
|
9
|
+
pypetkitapi/medias.py,sha256=IuWkC7usw0Hbx173X8TGv24jOp4nqv6bIUosZBpXMGg,6945
|
10
|
+
pypetkitapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
+
pypetkitapi/water_fountain_container.py,sha256=3F4GP5pXJqq6kxLMSK__GgFMuZ-rz1VDIIhaVd19Kl8,6781
|
12
|
+
pypetkitapi-1.7.7.dist-info/LICENSE,sha256=4FWnKolNLc1e3w6cVlT61YxfPh0DQNeQLN1CepKKSBg,1067
|
13
|
+
pypetkitapi-1.7.7.dist-info/METADATA,sha256=gUzTQqnxVR5201HG0GiWv-Yb3rGf6vjRi3uTwWKvE94,4852
|
14
|
+
pypetkitapi-1.7.7.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
15
|
+
pypetkitapi-1.7.7.dist-info/RECORD,,
|
@@ -1,15 +0,0 @@
|
|
1
|
-
pypetkitapi/__init__.py,sha256=eVpyGMD3tkYtiHUkdKEeNSZhQlZ4woI2Y5oVoV7CwXM,61
|
2
|
-
pypetkitapi/client.py,sha256=aBfwh6O-egpaX7vhW1I2l3flnXL_XrwGraH1uOzmH-w,19888
|
3
|
-
pypetkitapi/command.py,sha256=gw3_J_oZHuuGLk66P8uRSqSrySjYa8ArpKaPHi2ybCw,7155
|
4
|
-
pypetkitapi/const.py,sha256=ZpFWBgzb3nvy0Z4oyM550cCunlIceWgXqqtwtJc3mFo,3479
|
5
|
-
pypetkitapi/containers.py,sha256=nhp50QwyoQRveTnEgWL7JFEY3Tl5m5wp9EqZvklW87Y,4338
|
6
|
-
pypetkitapi/exceptions.py,sha256=NWmpsI2ewC4HaIeu_uFwCeuPIHIJxZBzjoCP7aNwvhs,1139
|
7
|
-
pypetkitapi/feeder_container.py,sha256=y1A5WhObXCdbcWwtKgSPzTWokYchoUDlholAD-AMgGQ,14069
|
8
|
-
pypetkitapi/litter_container.py,sha256=wsM-v7ibx17lsD-o17RGz2wvcHCUu1iZ2RqAh3CN1Qc,18254
|
9
|
-
pypetkitapi/medias.py,sha256=8hrMdzFR9d0L0PQOVYdy-MReSF9GMp8Ft0IGGHtL1Ag,6904
|
10
|
-
pypetkitapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
pypetkitapi/water_fountain_container.py,sha256=3F4GP5pXJqq6kxLMSK__GgFMuZ-rz1VDIIhaVd19Kl8,6781
|
12
|
-
pypetkitapi-1.7.5.dist-info/LICENSE,sha256=4FWnKolNLc1e3w6cVlT61YxfPh0DQNeQLN1CepKKSBg,1067
|
13
|
-
pypetkitapi-1.7.5.dist-info/METADATA,sha256=bvYlZOdBLw9_nu53rnNrPSXvgYdSvQMjqAVeSFMm7VE,4852
|
14
|
-
pypetkitapi-1.7.5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
15
|
-
pypetkitapi-1.7.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|