PySwitchbot 3.0.0__py3-none-any.whl → 3.2.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PySwitchbot
3
- Version: 3.0.0
3
+ Version: 3.2.0
4
4
  Summary: A library to communicate with Switchbot
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -42,6 +42,19 @@ source .venv/bin/activate
42
42
  pip install .
43
43
  ```
44
44
 
45
+ ## Air purifier filter reset
46
+
47
+ After replacing the filter, call `await purifier.reset_filter_usage()` on a
48
+ configured `SwitchbotAirPurifier` instance. The method uses the device's
49
+ encrypted BLE connection, sends the reset command without automatic retries,
50
+ and reads back the used-hours counter. It returns `True` and refreshes the
51
+ cached `filter element working time` only after the device reports zero.
52
+
53
+ Failed commands or an unconfirmed reset raise `SwitchbotOperationError`. If a
54
+ reply is lost, check the device before retrying: the reset may already have
55
+ been applied. This resets the device counter and does not restore its previous
56
+ value.
57
+
45
58
  ## OAuth account access
46
59
 
47
60
  pySwitchbot provides helpers for SwitchBot's authorization-code flow. The
@@ -1,5 +1,5 @@
1
1
  switchbot/__init__.py,sha256=pltMTceeYF7-Y9-3kGrnoTFXTIVHKoSWGgW-5JL3uwU,4673
2
- switchbot/__version__.py,sha256=EPmgXOdWKks5S__ZMH7Nu6xpAeVrZpfxaFy4pykuyeI,22
2
+ switchbot/__version__.py,sha256=OUX37Yd6ZO82d0GJL2dmK0gZTtc_xvlTvGQIl2I-D8k,22
3
3
  switchbot/adv_parser.py,sha256=M0Wy6rAlv0gipNFuV6FKW4IwQ0ea_wcPPhDN3Py5s9M,35473
4
4
  switchbot/adv_parsers/__init__.py,sha256=d39GEAICA1RrQiLy1ks49x0d9a-A_yKn9Awkj5za8Uk,46
5
5
  switchbot/adv_parsers/_sensor_th.py,sha256=FjVvxtkH6nZ-3u2W4q6zvDE1H4849JZ5LXRNd_nedhU,1182
@@ -44,12 +44,12 @@ switchbot/const/light.py,sha256=DsCua_IYYvGy23GmviSB9GkwATPGVYIe6VNF7rZt97U,817
44
44
  switchbot/const/lock.py,sha256=wKvq5uctsKpcM6gSzxPrcvmezzRhPZPd5n948I8R4n0,342
45
45
  switchbot/const/presence_sensor.py,sha256=X2oCfl0rbdd1-dSrqQFn3NDtEBXbti-87DbWq7NyN3A,135
46
46
  switchbot/devices/__init__.py,sha256=_fyzMy8qWC_2Y1BJ4hggrCP1udNqSoU6wFmfOiYpEl0,32
47
- switchbot/devices/air_purifier.py,sha256=JwT5HHQLvkDdFrDEKFT8sA41bM2G_DGfuOpf-74Smyw,10620
47
+ switchbot/devices/air_purifier.py,sha256=T-a61C2MNq4Cc4bOCy-JF60vuPf1P9qOxXO9BQl-AmI,11897
48
48
  switchbot/devices/art_frame.py,sha256=doMr_hGWWE9eqSXzxLGYJaBy_6AkBjGfhvB3vb5ZN30,5024
49
49
  switchbot/devices/base_cover.py,sha256=UWNA7eGbJdY80Mu-k41xO4tnyk7FhpYaWRWihGvDM2g,4385
50
50
  switchbot/devices/base_light.py,sha256=WWJJdRHfvoSYMRHDSv_RCmo5D6hYoZRxQVYfsOXZ7K0,6590
51
51
  switchbot/devices/blind_tilt.py,sha256=tY0JoZhyqU_6PlhjtnIaEeIG3Z-JdZKJ5Jwg_5b6xSQ,5761
52
- switchbot/devices/bot.py,sha256=Co2IiQa2si0WPs3HFize2CPpj5GVbMT570vMP5YWpaQ,4121
52
+ switchbot/devices/bot.py,sha256=yM2woM_HVxI9_Cf8qFSYztGRIKdHKjJzs6QDBQ9KHFE,4828
53
53
  switchbot/devices/bulb.py,sha256=ISxXck8JsBlFojLB8M5Wfip_z4o6_-VvyFbBvqK6_Bg,2313
54
54
  switchbot/devices/ceiling_light.py,sha256=7gxgsZz5ku6Bx8jfHSBkPcydjgagwGEuPvl5N-cMO6M,4600
55
55
  switchbot/devices/contact.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
@@ -77,7 +77,7 @@ switchbot/helpers.py,sha256=DJLvYZ4Dq0dkiGMOzfR--nSTM_8jE9QtB7t570PuGSU,2091
77
77
  switchbot/models.py,sha256=xibQOVGHC60FWWc54N6BW46vxFuJUjj6tK1Qw0_eTbI,372
78
78
  switchbot/oauth.py,sha256=j8tsfcy4d5qPqsnqrzaQ_Nro3ltyO0rCRgVTFXMFTKc,6487
79
79
  switchbot/utils.py,sha256=x1Qm0uIA1Jvxg4uxcQDBgWnopoU04-swKtjjCJ1Khak,1224
80
- pyswitchbot-3.0.0.dist-info/METADATA,sha256=nMSCKvgmubcHokReNBviTXqWlNs-5VFcyoFVqBBDunE,7728
81
- pyswitchbot-3.0.0.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
82
- pyswitchbot-3.0.0.dist-info/licenses/LICENSE,sha256=_hdUCmoRDzki4fYDJfn-5KpG7-7p6YJ6IsbMfrTXN6Y,1078
83
- pyswitchbot-3.0.0.dist-info/RECORD,,
80
+ pyswitchbot-3.2.0.dist-info/METADATA,sha256=bBquIslC7-75BXR8OSEiYq9Yig8eg_H4eMK_nv8I-8M,8374
81
+ pyswitchbot-3.2.0.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
82
+ pyswitchbot-3.2.0.dist-info/licenses/LICENSE,sha256=_hdUCmoRDzki4fYDJfn-5KpG7-7p6YJ6IsbMfrTXN6Y,1078
83
+ pyswitchbot-3.2.0.dist-info/RECORD,,
switchbot/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "3.0.0"
1
+ __version__ = "3.2.0"
@@ -33,6 +33,8 @@ DEVICE_GET_BASIC_SETTINGS_KEY = "570f4d81"
33
33
  COMMAND_SET_PERCENTAGE = f"{COMMAND_HEAD}02{{percentage:02x}}"
34
34
  READ_LED_SETTINGS_COMMAND = "570f4d05"
35
35
  READ_LED_STATUS_COMMAND = "570f4d07"
36
+ RESET_FILTER_USAGE_COMMAND = f"{COMMAND_HEAD}09"
37
+ READ_FILTER_USAGE_COMMAND = "570f4d09"
36
38
 
37
39
 
38
40
  class SwitchbotAirPurifier(SwitchbotSequenceBaseLight, SwitchbotEncryptedDevice):
@@ -147,6 +149,31 @@ class SwitchbotAirPurifier(SwitchbotSequenceBaseLight, SwitchbotEncryptedDevice)
147
149
  return data | {"pm25": pm25}
148
150
  return data
149
151
 
152
+ async def reset_filter_usage(self) -> bool:
153
+ """Reset filter usage, returning True only after a verified zero readback."""
154
+ result = await self._send_command(RESET_FILTER_USAGE_COMMAND, retry=0)
155
+ if not self._check_command_result(result, 0, {1}):
156
+ raise SwitchbotOperationError("Filter usage reset was rejected")
157
+
158
+ result = await self._send_command(READ_FILTER_USAGE_COMMAND)
159
+ if not result or len(result) < 3:
160
+ raise SwitchbotOperationError(
161
+ "Reset was sent, but filter usage could not be verified. "
162
+ "Check the device before retrying"
163
+ )
164
+ if not self._check_command_result(result, 0, {1}):
165
+ raise SwitchbotOperationError("Filter usage read was rejected")
166
+ used_hours = _UNPACK_UINT16_BE(result, 1)[0]
167
+ if used_hours != 0:
168
+ raise SwitchbotOperationError(
169
+ f"Reset was sent, but the device still reports {used_hours} used hours. "
170
+ "Check the device before retrying"
171
+ )
172
+
173
+ self._update_parsed_data({"filter element working time": used_hours})
174
+ self._fire_callbacks()
175
+ return True
176
+
150
177
  @update_after_operation
151
178
  async def set_preset_mode(self, preset_mode: str) -> bool:
152
179
  """Send command to set air purifier preset_mode."""
switchbot/devices/bot.py CHANGED
@@ -9,6 +9,7 @@ from .device import (
9
9
  DEVICE_SET_EXTENDED_KEY,
10
10
  DEVICE_SET_MODE_KEY,
11
11
  SwitchbotDeviceOverrideStateDuringConnection,
12
+ SwitchbotOperationError,
12
13
  update_after_operation,
13
14
  )
14
15
 
@@ -90,6 +91,18 @@ class Switchbot(SwitchbotDeviceOverrideStateDuringConnection):
90
91
  result = await self._send_command(DEVICE_SET_MODE_KEY + strength_key + mode_key)
91
92
  return self._check_command_result(result, 0, {1})
92
93
 
94
+ async def set_inverse_direction(self, inverse: bool) -> bool:
95
+ """Set the Bot's inverse direction while preserving its other mode settings."""
96
+ if not (settings := await self.get_basic_info()):
97
+ raise SwitchbotOperationError(
98
+ f"{self.name}: Unable to get current Bot mode settings"
99
+ )
100
+ return await self.set_switch_mode(
101
+ switch_mode=settings["switchMode"],
102
+ strength=settings["strength"],
103
+ inverse=inverse,
104
+ )
105
+
93
106
  @update_after_operation
94
107
  async def set_long_press(self, duration: int = 0) -> bool:
95
108
  """Set bot long press duration."""
@@ -121,3 +134,7 @@ class Switchbot(SwitchbotDeviceOverrideStateDuringConnection):
121
134
  if self._inverse:
122
135
  return not value
123
136
  return value
137
+
138
+ def inverse_direction(self) -> bool | None:
139
+ """Return the cached inverse direction setting."""
140
+ return self._get_adv_value("inverseDirection")