pypetkitapi 1.12.4__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.4
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.4"
54
+ __version__ = "1.12.5"
55
55
 
56
56
  __all__ = [
57
57
  "CTW3",
@@ -88,12 +88,13 @@ class BluetoothManager:
88
88
  """
89
89
  _LOGGER.debug("Opening BLE connection to fountain %s", fountain_id)
90
90
  water_fountain = await self._get_fountain_instance(fountain_id)
91
- if await self.check_relay_availability(fountain_id) is False:
92
- _LOGGER.debug("BLE relay not available (id: %s).", fountain_id)
93
- return False
94
91
  if water_fountain.is_connected is True:
95
92
  _LOGGER.debug("BLE connection already established (id %s)", fountain_id)
96
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
97
98
  response = await self.client.req.request(
98
99
  method=HTTPMethod.POST,
99
100
  url=PetkitEndpoint.BLE_CONNECT,
@@ -106,7 +107,6 @@ class BluetoothManager:
106
107
  )
107
108
  if response != {"state": 1}:
108
109
  _LOGGER.debug("Unable to open a BLE connection (id %s)", fountain_id)
109
- water_fountain.is_connected = False
110
110
  return False
111
111
  for attempt in range(BLE_CONNECT_ATTEMPT):
112
112
  _LOGGER.debug(
@@ -125,7 +125,16 @@ class BluetoothManager:
125
125
  },
126
126
  headers=await self.client.get_session_id(),
127
127
  )
128
- 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:
129
138
  _LOGGER.debug(
130
139
  "BLE connection established successfully (id %s)", fountain_id
131
140
  )
@@ -134,13 +143,11 @@ class BluetoothManager:
134
143
  "%Y-%m-%dT%H:%M:%S.%f"
135
144
  )
136
145
  return True
137
- await asyncio.sleep(4)
138
146
  _LOGGER.debug(
139
- "Failed to establish BLE connection after %s attempts (id %s)",
147
+ "Failed to establish BLE connection reached the max %s attempts allowed (id %s)",
140
148
  BLE_CONNECT_ATTEMPT,
141
149
  fountain_id,
142
150
  )
143
- water_fountain.is_connected = False
144
151
  return False
145
152
 
146
153
  async def close_ble_connection(self, fountain_id: int) -> None:
@@ -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
 
@@ -187,7 +187,7 @@ build-backend = "poetry.core.masonry.api"
187
187
 
188
188
  [tool.poetry]
189
189
  name = "pypetkitapi"
190
- version = "1.12.4"
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.4"
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