__init__.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. """Library to handle connection with Switchbot."""
  2. from __future__ import annotations
  3. import asyncio
  4. import binascii
  5. import logging
  6. from typing import Any
  7. from uuid import UUID
  8. import bleak
  9. DEFAULT_RETRY_COUNT = 3
  10. DEFAULT_RETRY_TIMEOUT = 1
  11. DEFAULT_SCAN_TIMEOUT = 5
  12. # Keys common to all device types
  13. DEVICE_GET_BASIC_SETTINGS_KEY = "5702"
  14. DEVICE_SET_MODE_KEY = "5703"
  15. DEVICE_SET_EXTENDED_KEY = "570f"
  16. # Bot keys
  17. PRESS_KEY = "570100"
  18. ON_KEY = "570101"
  19. OFF_KEY = "570102"
  20. DOWN_KEY = "570103"
  21. UP_KEY = "570104"
  22. # Curtain keys
  23. OPEN_KEY = "570f450105ff00" # 570F4501010100
  24. CLOSE_KEY = "570f450105ff64" # 570F4501010164
  25. POSITION_KEY = "570F450105ff" # +actual_position ex: 570F450105ff32 for 50%
  26. STOP_KEY = "570F450100ff"
  27. CURTAIN_EXT_SUM_KEY = "570f460401"
  28. CURTAIN_EXT_ADV_KEY = "570f460402"
  29. CURTAIN_EXT_CHAIN_INFO_KEY = "570f468101"
  30. # Base key when encryption is set
  31. KEY_PASSWORD_PREFIX = "571"
  32. _LOGGER = logging.getLogger(__name__)
  33. CONNECT_LOCK = asyncio.Lock()
  34. def _sb_uuid(comms_type: str = "service") -> UUID | str:
  35. """Return Switchbot UUID."""
  36. _uuid = {"tx": "002", "rx": "003", "service": "d00"}
  37. if comms_type in _uuid:
  38. return UUID(f"cba20{_uuid[comms_type]}-224d-11e6-9fb8-0002a5d5c51b")
  39. return "Incorrect type, choose between: tx, rx or service"
  40. def _process_wohand(data: bytes) -> dict[str, bool | int]:
  41. """Process woHand/Bot services data."""
  42. _switch_mode = bool(data[1] & 0b10000000)
  43. _bot_data = {
  44. "switchMode": _switch_mode,
  45. "isOn": not bool(data[1] & 0b01000000) if _switch_mode else False,
  46. "battery": data[2] & 0b01111111,
  47. }
  48. return _bot_data
  49. def _process_wocurtain(data: bytes, reverse: bool = True) -> dict[str, bool | int]:
  50. """Process woCurtain/Curtain services data."""
  51. _position = max(min(data[3] & 0b01111111, 100), 0)
  52. _curtain_data = {
  53. "calibration": bool(data[1] & 0b01000000),
  54. "battery": data[2] & 0b01111111,
  55. "inMotion": bool(data[3] & 0b10000000),
  56. "position": (100 - _position) if reverse else _position,
  57. "lightLevel": (data[4] >> 4) & 0b00001111,
  58. "deviceChain": data[4] & 0b00000111,
  59. }
  60. return _curtain_data
  61. def _process_wosensorth(data: bytes) -> dict[str, object]:
  62. """Process woSensorTH/Temp sensor services data."""
  63. _temp_sign = 1 if data[4] & 0b10000000 else -1
  64. _temp_c = _temp_sign * ((data[4] & 0b01111111) + (data[3] / 10))
  65. _temp_f = (_temp_c * 9 / 5) + 32
  66. _temp_f = (_temp_f * 10) / 10
  67. _wosensorth_data = {
  68. "temp": {"c": _temp_c, "f": _temp_f},
  69. "fahrenheit": bool(data[5] & 0b10000000),
  70. "humidity": data[5] & 0b01111111,
  71. "battery": data[2] & 0b01111111,
  72. }
  73. return _wosensorth_data
  74. class GetSwitchbotDevices:
  75. """Scan for all Switchbot devices and return by type."""
  76. def __init__(self, interface: int = 0) -> None:
  77. """Get switchbot devices class constructor."""
  78. self._interface = f"hci{interface}"
  79. self._adv_data: dict[str, Any] = {}
  80. def detection_callback(
  81. self,
  82. device: bleak.backends.device.BLEDevice,
  83. advertisement_data: bleak.backends.scanner.AdvertisementData,
  84. ) -> None:
  85. """BTLE adv scan callback."""
  86. _device = device.address.replace(":", "").lower()
  87. _service_data = list(advertisement_data.service_data.values())[0]
  88. _model = chr(_service_data[0] & 0b01111111)
  89. supported_types: dict[str, dict[str, Any]] = {
  90. "H": {"modelName": "WoHand", "func": _process_wohand},
  91. "c": {"modelName": "WoCurtain", "func": _process_wocurtain},
  92. "T": {"modelName": "WoSensorTH", "func": _process_wosensorth},
  93. }
  94. self._adv_data[_device] = {
  95. "mac_address": device.address.lower(),
  96. "rawAdvData": list(advertisement_data.service_data.values())[0],
  97. "data": {
  98. "rssi": device.rssi,
  99. },
  100. }
  101. if _model in supported_types:
  102. self._adv_data[_device].update(
  103. {
  104. "isEncrypted": bool(_service_data[0] & 0b10000000),
  105. "model": _model,
  106. "modelName": supported_types[_model]["modelName"],
  107. "data": supported_types[_model]["func"](_service_data),
  108. }
  109. )
  110. self._adv_data[_device]["data"]["rssi"] = device.rssi
  111. async def discover(
  112. self, retry: int = DEFAULT_RETRY_COUNT, scan_timeout: int = DEFAULT_SCAN_TIMEOUT
  113. ) -> dict:
  114. """Find switchbot devices and their advertisement data."""
  115. devices = None
  116. devices = bleak.BleakScanner(
  117. filters={"UUIDs": [str(_sb_uuid())]},
  118. adapter=self._interface,
  119. )
  120. devices.register_detection_callback(self.detection_callback)
  121. async with CONNECT_LOCK:
  122. await devices.start()
  123. await asyncio.sleep(scan_timeout)
  124. await devices.stop()
  125. if devices is None:
  126. if retry < 1:
  127. _LOGGER.error(
  128. "Scanning for Switchbot devices failed. Stop trying", exc_info=True
  129. )
  130. return self._adv_data
  131. _LOGGER.warning(
  132. "Error scanning for Switchbot devices. Retrying (remaining: %d)",
  133. retry,
  134. )
  135. await asyncio.sleep(DEFAULT_RETRY_TIMEOUT)
  136. return await self.discover(retry - 1, scan_timeout)
  137. return self._adv_data
  138. async def get_curtains(self) -> dict:
  139. """Return all WoCurtain/Curtains devices with services data."""
  140. if not self._adv_data:
  141. await self.discover()
  142. _curtain_devices = {
  143. device: data
  144. for device, data in self._adv_data.items()
  145. if data.get("model") == "c"
  146. }
  147. return _curtain_devices
  148. async def get_bots(self) -> dict[str, Any] | None:
  149. """Return all WoHand/Bot devices with services data."""
  150. if not self._adv_data:
  151. await self.discover()
  152. _bot_devices = {
  153. device: data
  154. for device, data in self._adv_data.items()
  155. if data.get("model") == "H"
  156. }
  157. return _bot_devices
  158. async def get_tempsensors(self) -> dict[str, Any] | None:
  159. """Return all WoSensorTH/Temp sensor devices with services data."""
  160. if not self._adv_data:
  161. await self.discover()
  162. _bot_temp = {
  163. device: data
  164. for device, data in self._adv_data.items()
  165. if data.get("model") == "T"
  166. }
  167. return _bot_temp
  168. async def get_device_data(self, mac: str) -> dict[str, Any] | None:
  169. """Return data for specific device."""
  170. if not self._adv_data:
  171. await self.discover()
  172. _switchbot_data = {
  173. device: data
  174. for device, data in self._adv_data.items()
  175. if data.get("mac_address") == mac
  176. }
  177. return _switchbot_data
  178. class SwitchbotDevice:
  179. """Base Representation of a Switchbot Device."""
  180. def __init__(
  181. self,
  182. mac: str,
  183. password: str | None = None,
  184. interface: int = 0,
  185. **kwargs: Any,
  186. ) -> None:
  187. """Switchbot base class constructor."""
  188. self._interface = f"hci{interface}"
  189. self._mac = mac.replace("-", ":").lower()
  190. self._sb_adv_data: dict[str, Any] = {}
  191. self._scan_timeout: int = kwargs.pop("scan_timeout", DEFAULT_SCAN_TIMEOUT)
  192. self._retry_count: int = kwargs.pop("retry_count", DEFAULT_RETRY_COUNT)
  193. if password is None or password == "":
  194. self._password_encoded = None
  195. else:
  196. self._password_encoded = "%x" % (
  197. binascii.crc32(password.encode("ascii")) & 0xFFFFFFFF
  198. )
  199. self._last_notification = bytearray()
  200. async def _notification_handler(self, sender: int, data: bytearray) -> None:
  201. """Handle notification responses."""
  202. self._last_notification = data
  203. def _commandkey(self, key: str) -> str:
  204. """Add password to key if set."""
  205. if self._password_encoded is None:
  206. return key
  207. key_action = key[3]
  208. key_suffix = key[4:]
  209. return KEY_PASSWORD_PREFIX + key_action + self._password_encoded + key_suffix
  210. async def _sendcommand(self, key: str, retry: int) -> bytes:
  211. """Send command to device and read response."""
  212. command = bytearray.fromhex(self._commandkey(key))
  213. notify_msg = b""
  214. _LOGGER.debug("Sending command to switchbot %s", command)
  215. if len(self._mac.split(":")) != 6:
  216. raise ValueError("Expected MAC address, got %s" % repr(self._mac))
  217. async with CONNECT_LOCK:
  218. try:
  219. async with bleak.BleakClient(
  220. address_or_ble_device=self._mac, timeout=float(self._scan_timeout)
  221. ) as client:
  222. _LOGGER.debug("Connnected to switchbot: %s", client.is_connected)
  223. _LOGGER.debug("Subscribe to notifications")
  224. await client.start_notify(
  225. _sb_uuid(comms_type="rx"), self._notification_handler
  226. )
  227. _LOGGER.debug("Sending command, %s", key)
  228. await client.write_gatt_char(
  229. _sb_uuid(comms_type="tx"), command, False
  230. )
  231. await asyncio.sleep(
  232. 1.0
  233. ) # Bot needs pause. Otherwise notification could be missed.
  234. notify_msg = self._last_notification
  235. _LOGGER.info("Notification received: %s", notify_msg)
  236. _LOGGER.debug("UnSubscribe to notifications")
  237. await client.stop_notify(_sb_uuid(comms_type="rx"))
  238. except (bleak.BleakError, asyncio.exceptions.TimeoutError):
  239. if retry < 1:
  240. _LOGGER.error(
  241. "Switchbot communication failed. Stopping trying", exc_info=True
  242. )
  243. return b"\x00"
  244. _LOGGER.debug("Switchbot communication failed with:", exc_info=True)
  245. if notify_msg:
  246. if notify_msg == b"\x07":
  247. _LOGGER.error("Password required")
  248. elif notify_msg == b"\t":
  249. _LOGGER.error("Password incorrect")
  250. return notify_msg
  251. _LOGGER.warning("Cannot connect to Switchbot. Retrying (remaining: %d)", retry)
  252. if retry < 1: # failsafe
  253. return b"\x00"
  254. await asyncio.sleep(DEFAULT_RETRY_TIMEOUT)
  255. return await self._sendcommand(key, retry - 1)
  256. def get_mac(self) -> str:
  257. """Return mac address of device."""
  258. return self._mac
  259. def get_battery_percent(self) -> Any:
  260. """Return device battery level in percent."""
  261. if not self._sb_adv_data:
  262. return None
  263. return self._sb_adv_data["data"]["battery"]
  264. async def get_device_data(
  265. self, retry: int = DEFAULT_RETRY_COUNT, interface: int | None = None
  266. ) -> dict | None:
  267. """Find switchbot devices and their advertisement data."""
  268. if interface:
  269. _interface: int = interface
  270. else:
  271. _interface = int(self._interface.replace("hci", ""))
  272. dev_id = self._mac.replace(":", "")
  273. _data = await GetSwitchbotDevices(interface=_interface).discover(
  274. retry=retry, scan_timeout=self._scan_timeout
  275. )
  276. if _data.get(dev_id):
  277. self._sb_adv_data = _data[dev_id]
  278. return self._sb_adv_data
  279. class Switchbot(SwitchbotDevice):
  280. """Representation of a Switchbot."""
  281. def __init__(self, *args: Any, **kwargs: Any) -> None:
  282. """Switchbot Bot/WoHand constructor."""
  283. super().__init__(*args, **kwargs)
  284. self._inverse: bool = kwargs.pop("inverse_mode", False)
  285. self._settings: dict[str, Any] = {}
  286. async def update(self, interface: int | None = None) -> None:
  287. """Update mode, battery percent and state of device."""
  288. await self.get_device_data(retry=self._retry_count, interface=interface)
  289. async def turn_on(self) -> bool:
  290. """Turn device on."""
  291. result = await self._sendcommand(ON_KEY, self._retry_count)
  292. if result[0] == 1:
  293. return True
  294. if result[0] == 5:
  295. _LOGGER.debug("Bot is in press mode and doesn't have on state")
  296. return True
  297. return False
  298. async def turn_off(self) -> bool:
  299. """Turn device off."""
  300. result = await self._sendcommand(OFF_KEY, self._retry_count)
  301. if result[0] == 1:
  302. return True
  303. if result[0] == 5:
  304. _LOGGER.debug("Bot is in press mode and doesn't have off state")
  305. return True
  306. return False
  307. async def hand_up(self) -> bool:
  308. """Raise device arm."""
  309. result = await self._sendcommand(UP_KEY, self._retry_count)
  310. if result[0] == 1:
  311. return True
  312. if result[0] == 5:
  313. _LOGGER.debug("Bot is in press mode")
  314. return True
  315. return False
  316. async def hand_down(self) -> bool:
  317. """Lower device arm."""
  318. result = await self._sendcommand(DOWN_KEY, self._retry_count)
  319. if result[0] == 1:
  320. return True
  321. if result[0] == 5:
  322. _LOGGER.debug("Bot is in press mode")
  323. return True
  324. return False
  325. async def press(self) -> bool:
  326. """Press command to device."""
  327. result = await self._sendcommand(PRESS_KEY, self._retry_count)
  328. if result[0] == 1:
  329. return True
  330. if result[0] == 5:
  331. _LOGGER.debug("Bot is in switch mode")
  332. return True
  333. return False
  334. async def set_switch_mode(
  335. self, switch_mode: bool = False, strength: int = 100, inverse: bool = False
  336. ) -> bool:
  337. """Change bot mode."""
  338. mode_key = format(switch_mode, "b") + format(inverse, "b")
  339. strength_key = f"{strength:0{2}x}" # to hex with padding to double digit
  340. result = await self._sendcommand(
  341. DEVICE_SET_MODE_KEY + strength_key + mode_key, self._retry_count
  342. )
  343. if result[0] == 1:
  344. return True
  345. return False
  346. async def set_long_press(self, duration: int = 0) -> bool:
  347. """Set bot long press duration."""
  348. duration_key = f"{duration:0{2}x}" # to hex with padding to double digit
  349. result = await self._sendcommand(
  350. DEVICE_SET_EXTENDED_KEY + "08" + duration_key, self._retry_count
  351. )
  352. if result[0] == 1:
  353. return True
  354. return False
  355. async def get_basic_info(self) -> dict[str, Any] | None:
  356. """Get device basic settings."""
  357. _data = await self._sendcommand(
  358. key=DEVICE_GET_BASIC_SETTINGS_KEY, retry=self._retry_count
  359. )
  360. if _data in (b"\x07", b"\x00"):
  361. _LOGGER.error("Unsuccessfull, please try again")
  362. return None
  363. self._settings = {
  364. "battery": _data[1],
  365. "firmware": _data[2] / 10.0,
  366. "strength": _data[3],
  367. "timers": _data[8],
  368. "switchMode": bool(_data[9] & 16),
  369. "inverseDirection": bool(_data[9] & 1),
  370. "holdSeconds": _data[10],
  371. }
  372. return self._settings
  373. def switch_mode(self) -> Any:
  374. """Return true or false from cache."""
  375. # To get actual position call update() first.
  376. if not self._sb_adv_data.get("data"):
  377. return None
  378. return self._sb_adv_data["data"].get("switchMode")
  379. def is_on(self) -> Any:
  380. """Return switch state from cache."""
  381. # To get actual position call update() first.
  382. if not self._sb_adv_data.get("data"):
  383. return None
  384. if self._inverse:
  385. return not self._sb_adv_data["data"].get("isOn")
  386. return self._sb_adv_data["data"].get("isOn")
  387. class SwitchbotCurtain(SwitchbotDevice):
  388. """Representation of a Switchbot Curtain."""
  389. def __init__(self, *args: Any, **kwargs: Any) -> None:
  390. """Switchbot Curtain/WoCurtain constructor."""
  391. # The position of the curtain is saved returned with 0 = open and 100 = closed.
  392. # This is independent of the calibration of the curtain bot (Open left to right/
  393. # Open right to left/Open from the middle).
  394. # The parameter 'reverse_mode' reverse these values,
  395. # if 'reverse_mode' = True, position = 0 equals close
  396. # and position = 100 equals open. The parameter is default set to True so that
  397. # the definition of position is the same as in Home Assistant.
  398. super().__init__(*args, **kwargs)
  399. self._reverse: bool = kwargs.pop("reverse_mode", True)
  400. self._settings: dict[str, Any] = {}
  401. self.ext_info_sum: dict[str, Any] = {}
  402. self.ext_info_adv: dict[str, Any] = {}
  403. async def open(self) -> bool:
  404. """Send open command."""
  405. result = await self._sendcommand(OPEN_KEY, self._retry_count)
  406. if result[0] == 1:
  407. return True
  408. return False
  409. async def close(self) -> bool:
  410. """Send close command."""
  411. result = await self._sendcommand(CLOSE_KEY, self._retry_count)
  412. if result[0] == 1:
  413. return True
  414. return False
  415. async def stop(self) -> bool:
  416. """Send stop command to device."""
  417. result = await self._sendcommand(STOP_KEY, self._retry_count)
  418. if result[0] == 1:
  419. return True
  420. return False
  421. async def set_position(self, position: int) -> bool:
  422. """Send position command (0-100) to device."""
  423. position = (100 - position) if self._reverse else position
  424. hex_position = "%0.2X" % position
  425. result = await self._sendcommand(POSITION_KEY + hex_position, self._retry_count)
  426. if result[0] == 1:
  427. return True
  428. return False
  429. async def update(self, interface: int | None = None) -> None:
  430. """Update position, battery percent and light level of device."""
  431. await self.get_device_data(retry=self._retry_count, interface=interface)
  432. def get_position(self) -> Any:
  433. """Return cached position (0-100) of Curtain."""
  434. # To get actual position call update() first.
  435. if not self._sb_adv_data.get("data"):
  436. return None
  437. return self._sb_adv_data["data"].get("position")
  438. async def get_basic_info(self) -> dict[str, Any] | None:
  439. """Get device basic settings."""
  440. _data = await self._sendcommand(
  441. key=DEVICE_GET_BASIC_SETTINGS_KEY, retry=self._retry_count
  442. )
  443. if _data in (b"\x07", b"\x00"):
  444. _LOGGER.error("Unsuccessfull, please try again")
  445. return None
  446. _position = max(min(_data[6], 100), 0)
  447. self._settings = {
  448. "battery": _data[1],
  449. "firmware": _data[2] / 10.0,
  450. "chainLength": _data[3],
  451. "openDirection": (
  452. "right_to_left" if _data[4] & 0b10000000 == 128 else "left_to_right"
  453. ),
  454. "touchToOpen": bool(_data[4] & 0b01000000),
  455. "light": bool(_data[4] & 0b00100000),
  456. "fault": bool(_data[4] & 0b00001000),
  457. "solarPanel": bool(_data[5] & 0b00001000),
  458. "calibrated": bool(_data[5] & 0b00000100),
  459. "inMotion": bool(_data[5] & 0b01000011),
  460. "position": (100 - _position) if self._reverse else _position,
  461. "timers": _data[7],
  462. }
  463. return self._settings
  464. async def get_extended_info_summary(self) -> dict[str, Any] | None:
  465. """Get basic info for all devices in chain."""
  466. _data = await self._sendcommand(
  467. key=CURTAIN_EXT_SUM_KEY, retry=self._retry_count
  468. )
  469. if _data in (b"\x07", b"\x00"):
  470. _LOGGER.error("Unsuccessfull, please try again")
  471. return None
  472. self.ext_info_sum["device0"] = {
  473. "openDirectionDefault": not bool(_data[1] & 0b10000000),
  474. "touchToOpen": bool(_data[1] & 0b01000000),
  475. "light": bool(_data[1] & 0b00100000),
  476. "openDirection": (
  477. "left_to_right" if _data[1] & 0b00010000 == 1 else "right_to_left"
  478. ),
  479. }
  480. # if grouped curtain device present.
  481. if _data[2] != 0:
  482. self.ext_info_sum["device1"] = {
  483. "openDirectionDefault": not bool(_data[1] & 0b10000000),
  484. "touchToOpen": bool(_data[1] & 0b01000000),
  485. "light": bool(_data[1] & 0b00100000),
  486. "openDirection": (
  487. "left_to_right" if _data[1] & 0b00010000 else "right_to_left"
  488. ),
  489. }
  490. return self.ext_info_sum
  491. async def get_extended_info_adv(self) -> dict[str, Any] | None:
  492. """Get advance page info for device chain."""
  493. _data = await self._sendcommand(
  494. key=CURTAIN_EXT_ADV_KEY, retry=self._retry_count
  495. )
  496. if _data in (b"\x07", b"\x00"):
  497. _LOGGER.error("Unsuccessfull, please try again")
  498. return None
  499. _state_of_charge = [
  500. "not_charging",
  501. "charging_by_adapter",
  502. "charging_by_solar",
  503. "fully_charged",
  504. "solar_not_charging",
  505. "charging_error",
  506. ]
  507. self.ext_info_adv["device0"] = {
  508. "battery": _data[1],
  509. "firmware": _data[2] / 10.0,
  510. "stateOfCharge": _state_of_charge[_data[3]],
  511. }
  512. # If grouped curtain device present.
  513. if _data[4]:
  514. self.ext_info_adv["device1"] = {
  515. "battery": _data[4],
  516. "firmware": _data[5] / 10.0,
  517. "stateOfCharge": _state_of_charge[_data[6]],
  518. }
  519. return self.ext_info_adv
  520. def get_light_level(self) -> Any:
  521. """Return cached light level."""
  522. # To get actual light level call update() first.
  523. if not self._sb_adv_data.get("data"):
  524. return None
  525. return self._sb_adv_data["data"].get("lightLevel")
  526. def is_reversed(self) -> bool:
  527. """Return True if curtain position is opposite from SB data."""
  528. return self._reverse
  529. def is_calibrated(self) -> Any:
  530. """Return True curtain is calibrated."""
  531. # To get actual light level call update() first.
  532. if not self._sb_adv_data.get("data"):
  533. return None
  534. return self._sb_adv_data["data"].get("calibration")