pypetkitapi 1.12.3__tar.gz → 1.12.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.3
2
2
  Name: pypetkitapi
3
- Version: 1.12.3
3
+ Version: 1.12.5
4
4
  Summary: Python client for PetKit API
5
5
  License: MIT
6
6
  Author: Jezza34000
@@ -51,7 +51,7 @@ from .media import DownloadDecryptMedia, MediaCloud, MediaFile, MediaManager
51
51
  from .purifier_container import Purifier
52
52
  from .water_fountain_container import WaterFountain
53
53
 
54
- __version__ = "1.12.3"
54
+ __version__ = "1.12.5"
55
55
 
56
56
  __all__ = [
57
57
  "CTW3",
@@ -41,6 +41,9 @@ class BluetoothManager:
41
41
  if not isinstance(water_fountain, WaterFountain):
42
42
  _LOGGER.error("Water fountain with ID %s not found.", fountain_id)
43
43
  raise TypeError(f"Water fountain with ID {fountain_id} not found.")
44
+ if water_fountain.device_nfo is None:
45
+ raise ValueError(f"Device info not found for fountain {fountain_id}")
46
+
44
47
  return water_fountain
45
48
 
46
49
  async def check_relay_availability(self, fountain_id: int) -> bool:
@@ -85,21 +88,25 @@ class BluetoothManager:
85
88
  """
86
89
  _LOGGER.debug("Opening BLE connection to fountain %s", fountain_id)
87
90
  water_fountain = await self._get_fountain_instance(fountain_id)
88
- if await self.check_relay_availability(fountain_id) is False:
89
- _LOGGER.debug("BLE relay not available (id: %s).", fountain_id)
90
- return False
91
91
  if water_fountain.is_connected is True:
92
92
  _LOGGER.debug("BLE connection already established (id %s)", fountain_id)
93
93
  return True
94
+ water_fountain.is_connected = False
95
+ if await self.check_relay_availability(fountain_id) is False:
96
+ _LOGGER.debug("BLE relay not available (id: %s).", fountain_id)
97
+ return False
94
98
  response = await self.client.req.request(
95
99
  method=HTTPMethod.POST,
96
100
  url=PetkitEndpoint.BLE_CONNECT,
97
- data={"bleId": fountain_id, "type": 24, "mac": water_fountain.mac},
101
+ data={
102
+ "bleId": fountain_id,
103
+ "type": water_fountain.device_nfo.type, # type: ignore[union-attr]
104
+ "mac": water_fountain.mac,
105
+ },
98
106
  headers=await self.client.get_session_id(),
99
107
  )
100
108
  if response != {"state": 1}:
101
109
  _LOGGER.debug("Unable to open a BLE connection (id %s)", fountain_id)
102
- water_fountain.is_connected = False
103
110
  return False
104
111
  for attempt in range(BLE_CONNECT_ATTEMPT):
105
112
  _LOGGER.debug(
@@ -111,10 +118,23 @@ class BluetoothManager:
111
118
  response = await self.client.req.request(
112
119
  method=HTTPMethod.POST,
113
120
  url=PetkitEndpoint.BLE_POLL,
114
- data={"bleId": fountain_id, "type": 24, "mac": water_fountain.mac},
121
+ data={
122
+ "bleId": fountain_id,
123
+ "type": water_fountain.device_nfo.type, # type: ignore[union-attr]
124
+ "mac": water_fountain.mac,
125
+ },
115
126
  headers=await self.client.get_session_id(),
116
127
  )
117
- if response == 1:
128
+ if response == 0:
129
+ # Wait for 4 seconds before polling again, connection is still in progress
130
+ await asyncio.sleep(4)
131
+ elif response == -1:
132
+ _LOGGER.debug("Failed to establish BLE connection (id %s)", fountain_id)
133
+ water_fountain.last_ble_poll = datetime.now().strftime(
134
+ "%Y-%m-%dT%H:%M:%S.%f"
135
+ )
136
+ return False
137
+ elif response == 1:
118
138
  _LOGGER.debug(
119
139
  "BLE connection established successfully (id %s)", fountain_id
120
140
  )
@@ -123,13 +143,11 @@ class BluetoothManager:
123
143
  "%Y-%m-%dT%H:%M:%S.%f"
124
144
  )
125
145
  return True
126
- await asyncio.sleep(4)
127
146
  _LOGGER.debug(
128
- "Failed to establish BLE connection after %s attempts (id %s)",
147
+ "Failed to establish BLE connection reached the max %s attempts allowed (id %s)",
129
148
  BLE_CONNECT_ATTEMPT,
130
149
  fountain_id,
131
150
  )
132
- water_fountain.is_connected = False
133
151
  return False
134
152
 
135
153
  async def close_ble_connection(self, fountain_id: int) -> None:
@@ -149,7 +167,11 @@ class BluetoothManager:
149
167
  await self.client.req.request(
150
168
  method=HTTPMethod.POST,
151
169
  url=PetkitEndpoint.BLE_CANCEL,
152
- data={"bleId": fountain_id, "type": 24, "mac": water_fountain.mac},
170
+ data={
171
+ "bleId": fountain_id,
172
+ "type": water_fountain.device_nfo.type, # type: ignore[union-attr]
173
+ "mac": water_fountain.mac,
174
+ },
153
175
  headers=await self.client.get_session_id(),
154
176
  )
155
177
  _LOGGER.debug("BLE connection closed successfully (id %s)", fountain_id)
@@ -206,7 +228,7 @@ class BluetoothManager:
206
228
  "cmd": cmd_code,
207
229
  "data": cmd_data,
208
230
  "mac": water_fountain.mac,
209
- "type": 24,
231
+ "type": water_fountain.device_nfo.type, # type: ignore[union-attr]
210
232
  },
211
233
  headers=await self.client.get_session_id(),
212
234
  )
@@ -12,7 +12,7 @@ DEVICE_STATS = "deviceStats"
12
12
  PET_DATA = "petData"
13
13
 
14
14
  # Bluetooth
15
- BLE_CONNECT_ATTEMPT = 4
15
+ BLE_CONNECT_ATTEMPT = 32
16
16
  BLE_START_TRAME = [250, 252, 253]
17
17
  BLE_END_TRAME = [251]
18
18
 
@@ -322,7 +322,7 @@ class MediaManager:
322
322
  cp_sub = self.is_subscription_active(device_obj)
323
323
 
324
324
  if not feeder_id or not record.items:
325
- _LOGGER.warning("Missing feeder_id or items for record")
325
+ _LOGGER.debug("Missing feeder_id or items for record")
326
326
  return media_files
327
327
 
328
328
  for item in record.items:
@@ -187,7 +187,7 @@ build-backend = "poetry.core.masonry.api"
187
187
 
188
188
  [tool.poetry]
189
189
  name = "pypetkitapi"
190
- version = "1.12.3"
190
+ version = "1.12.5"
191
191
  description = "Python client for PetKit API"
192
192
  authors = ["Jezza34000 <info@mail.com>"]
193
193
  readme = "README.md"
@@ -209,7 +209,7 @@ ruff = "^0.8.1"
209
209
  types-aiofiles = "^24.1.0.20240626"
210
210
 
211
211
  [tool.bumpver]
212
- current_version = "1.12.3"
212
+ current_version = "1.12.5"
213
213
  version_pattern = "MAJOR.MINOR.PATCH"
214
214
  commit_message = "bump version {old_version} -> {new_version}"
215
215
  tag_message = "{new_version}"
File without changes
File without changes