device.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. """
  2. API for Tuya Local devices.
  3. """
  4. import asyncio
  5. import logging
  6. from asyncio.exceptions import CancelledError
  7. from threading import Lock
  8. from time import time
  9. import tinytuya
  10. from homeassistant.const import (
  11. CONF_HOST,
  12. CONF_NAME,
  13. EVENT_HOMEASSISTANT_STARTED,
  14. EVENT_HOMEASSISTANT_STOP,
  15. )
  16. from homeassistant.core import HomeAssistant, callback
  17. from .const import (
  18. API_PROTOCOL_VERSIONS,
  19. CONF_DEVICE_CID,
  20. CONF_DEVICE_ID,
  21. CONF_LOCAL_KEY,
  22. CONF_POLL_ONLY,
  23. CONF_PROTOCOL_VERSION,
  24. DOMAIN,
  25. )
  26. from .helpers.config import get_device_id
  27. from .helpers.device_config import possible_matches
  28. from .helpers.log import log_json
  29. _LOGGER = logging.getLogger(__name__)
  30. def _collect_possible_matches(cached_state, product_ids):
  31. """Collect possible matches from generator into an array."""
  32. return list(possible_matches(cached_state, product_ids))
  33. class TuyaLocalDevice(object):
  34. def __init__(
  35. self,
  36. name,
  37. dev_id,
  38. address,
  39. local_key,
  40. protocol_version,
  41. dev_cid,
  42. hass: HomeAssistant,
  43. poll_only=False,
  44. ):
  45. """
  46. Represents a Tuya-based device.
  47. Args:
  48. name (str): The device name.
  49. dev_id (str): The device id.
  50. address (str): The network address.
  51. local_key (str): The encryption key.
  52. protocol_version (str | number): The protocol version.
  53. dev_cid (str): The sub device id.
  54. hass (HomeAssistant): The Home Assistant instance.
  55. poll_only (bool): True if the device should be polled only
  56. """
  57. self._name = name
  58. self._children = []
  59. self._force_dps = []
  60. self._product_ids = []
  61. self._running = False
  62. self._shutdown_listener = None
  63. self._startup_listener = None
  64. self._api_protocol_version_index = None
  65. self._api_protocol_working = False
  66. self._api_working_protocol_failures = 0
  67. self.dev_cid = dev_cid
  68. try:
  69. if dev_cid:
  70. if hass.data[DOMAIN].get(dev_id):
  71. parent = hass.data[DOMAIN][dev_id]["tuyadevice"]
  72. else:
  73. parent = tinytuya.Device(dev_id, address, local_key)
  74. hass.data[DOMAIN][dev_id] = {"tuyadevice": parent}
  75. self._api = tinytuya.Device(
  76. dev_cid,
  77. cid=dev_cid,
  78. parent=parent,
  79. )
  80. else:
  81. if hass.data[DOMAIN].get(dev_id):
  82. self._api = hass.data[DOMAIN][dev_id]["tuyadevice"]
  83. else:
  84. self._api = tinytuya.Device(dev_id, address, local_key)
  85. hass.data[DOMAIN][dev_id] = {"tuyadevice": self._api}
  86. except Exception as e:
  87. _LOGGER.error(
  88. "%s: %s while initialising device %s",
  89. type(e),
  90. e,
  91. dev_id,
  92. )
  93. raise e
  94. # we handle retries at a higher level so we can rotate protocol version
  95. self._api.set_socketRetryLimit(1)
  96. if self._api.parent:
  97. # Retries cause problems for other children of the parent device
  98. self._api.parent.set_socketRetryLimit(1)
  99. self._refresh_task = None
  100. self._protocol_configured = protocol_version
  101. self._poll_only = poll_only
  102. self._temporary_poll = False
  103. self._reset_cached_state()
  104. self._hass = hass
  105. # API calls to update Tuya devices are asynchronous and non-blocking.
  106. # This means you can send a change and immediately request an updated
  107. # state (like HA does), but because it has not yet finished processing
  108. # you will be returned the old state.
  109. # The solution is to keep a temporary list of changed properties that
  110. # we can overlay onto the state while we wait for the board to update
  111. # its switches.
  112. self._FAKE_IT_TIMEOUT = 5
  113. self._CACHE_TIMEOUT = 30
  114. # More attempts are needed in auto mode so we can cycle through all
  115. # the possibilities a couple of times
  116. self._AUTO_CONNECTION_ATTEMPTS = len(API_PROTOCOL_VERSIONS) * 2 + 1
  117. self._SINGLE_PROTO_CONNECTION_ATTEMPTS = 3
  118. # The number of failures from a working protocol before retrying other protocols.
  119. self._AUTO_FAILURE_RESET_COUNT = 10
  120. self._lock = Lock()
  121. @property
  122. def name(self):
  123. return self._name
  124. @property
  125. def unique_id(self):
  126. """Return the unique id for this device (the dev_id or dev_cid)."""
  127. return self.dev_cid or self._api.id
  128. @property
  129. def device_info(self):
  130. """Return the device information for this device."""
  131. return {
  132. "identifiers": {(DOMAIN, self.unique_id)},
  133. "name": self.name,
  134. "manufacturer": "Tuya",
  135. }
  136. @property
  137. def has_returned_state(self):
  138. """Return True if the device has returned some state."""
  139. return len(self._get_cached_state()) > 1
  140. @callback
  141. def actually_start(self, event=None):
  142. _LOGGER.debug("Starting monitor loop for %s", self.name)
  143. self._running = True
  144. self._shutdown_listener = self._hass.bus.async_listen_once(
  145. EVENT_HOMEASSISTANT_STOP, self.async_stop
  146. )
  147. if not self._refresh_task:
  148. self._refresh_task = self._hass.async_create_task(self.receive_loop())
  149. def start(self):
  150. if self._hass.is_stopping:
  151. return
  152. elif self._hass.is_running:
  153. if self._startup_listener:
  154. self._startup_listener()
  155. self._startup_listener = None
  156. self.actually_start()
  157. else:
  158. self._startup_listener = self._hass.bus.async_listen_once(
  159. EVENT_HOMEASSISTANT_STARTED, self.actually_start
  160. )
  161. async def async_stop(self, event=None):
  162. _LOGGER.debug("Stopping monitor loop for %s", self.name)
  163. self._running = False
  164. self._children.clear()
  165. self._force_dps.clear()
  166. if self._refresh_task:
  167. self._api.set_socketPersistent(False)
  168. if self._api.parent:
  169. self._api.parent.set_socketPersistent(False)
  170. await self._refresh_task
  171. _LOGGER.debug("Monitor loop for %s stopped", self.name)
  172. self._refresh_task = None
  173. def register_entity(self, entity):
  174. # If this is the first child entity to register, and HA is still
  175. # starting, refresh the device state so it shows as available without
  176. # waiting for startup to complete.
  177. should_poll = len(self._children) == 0 and not self._hass.is_running
  178. self._children.append(entity)
  179. for dp in entity._config.dps():
  180. if dp.force and dp.id not in self._force_dps:
  181. self._force_dps.append(int(dp.id))
  182. if not self._running and not self._startup_listener:
  183. self.start()
  184. if self.has_returned_state:
  185. entity.async_schedule_update_ha_state()
  186. elif should_poll:
  187. entity.async_schedule_update_ha_state(True)
  188. async def async_unregister_entity(self, entity):
  189. self._children.remove(entity)
  190. if not self._children:
  191. try:
  192. await self.async_stop()
  193. except CancelledError:
  194. pass
  195. async def receive_loop(self):
  196. """Coroutine wrapper for async_receive generator."""
  197. try:
  198. async for poll in self.async_receive():
  199. if isinstance(poll, dict):
  200. _LOGGER.debug(
  201. "%s received %s",
  202. self.name,
  203. log_json(poll),
  204. )
  205. full_poll = poll.pop("full_poll", False)
  206. self._cached_state = self._cached_state | poll
  207. self._cached_state["updated_at"] = time()
  208. self._remove_properties_from_pending_updates(poll)
  209. for entity in self._children:
  210. # let entities trigger off poll contents directly
  211. entity.on_receive(poll, full_poll)
  212. # clear non-persistant dps that were not in a full poll
  213. if full_poll:
  214. for dp in entity._config.dps():
  215. if not dp.persist and dp.id not in poll:
  216. self._cached_state.pop(dp.id, None)
  217. entity.schedule_update_ha_state()
  218. else:
  219. _LOGGER.debug(
  220. "%s received non data %s",
  221. self.name,
  222. log_json(poll),
  223. )
  224. _LOGGER.warning("%s receive loop has terminated", self.name)
  225. except Exception as t:
  226. _LOGGER.exception(
  227. "%s receive loop terminated by exception %s", self.name, t
  228. )
  229. self._api.set_socketPersistent(False)
  230. if self._api.parent:
  231. self._api.parent.set_socketPersistent(False)
  232. @property
  233. def should_poll(self):
  234. return self._poll_only or self._temporary_poll or not self.has_returned_state
  235. def pause(self):
  236. self._temporary_poll = True
  237. self._api.set_socketPersistent(False)
  238. if self._api.parent:
  239. self._api.parent.set_socketPersistent(False)
  240. def resume(self):
  241. self._temporary_poll = False
  242. async def async_receive(self):
  243. """Receive messages from a persistent connection asynchronously."""
  244. # If we didn't yet get any state from the device, we may need to
  245. # negotiate the protocol before making the connection persistent
  246. persist = not self.should_poll
  247. # flag to alternate updatedps and status calls to ensure we get
  248. # all dps updated
  249. dps_updated = False
  250. self._api.set_socketPersistent(persist)
  251. if self._api.parent:
  252. self._api.parent.set_socketPersistent(persist)
  253. while self._running:
  254. try:
  255. last_cache = self._cached_state.get("updated_at", 0)
  256. now = time()
  257. full_poll = False
  258. if persist == self.should_poll:
  259. # use persistent connections after initial communication
  260. # has been established. Until then, we need to rotate
  261. # the protocol version, which seems to require a fresh
  262. # connection.
  263. persist = not self.should_poll
  264. _LOGGER.debug(
  265. "%s persistant connection set to %s", self.name, persist
  266. )
  267. self._api.set_socketPersistent(persist)
  268. if self._api.parent:
  269. self._api.parent.set_socketPersistent(persist)
  270. if now - last_cache > self._CACHE_TIMEOUT:
  271. if (
  272. self._force_dps
  273. and not dps_updated
  274. and self._api_protocol_working
  275. ):
  276. poll = await self._retry_on_failed_connection(
  277. lambda: self._api.updatedps(self._force_dps),
  278. f"Failed to update device dps for {self.name}",
  279. )
  280. dps_updated = True
  281. else:
  282. poll = await self._retry_on_failed_connection(
  283. lambda: self._api.status(),
  284. f"Failed to fetch device status for {self.name}",
  285. )
  286. dps_updated = False
  287. full_poll = True
  288. elif persist:
  289. await self._hass.async_add_executor_job(
  290. self._api.heartbeat,
  291. True,
  292. )
  293. poll = await self._hass.async_add_executor_job(
  294. self._api.receive,
  295. )
  296. else:
  297. await asyncio.sleep(5)
  298. poll = None
  299. if poll:
  300. if "Error" in poll:
  301. _LOGGER.warning(
  302. "%s error reading: %s", self.name, poll["Error"]
  303. )
  304. if "Payload" in poll and poll["Payload"]:
  305. _LOGGER.info(
  306. "%s err payload: %s",
  307. self.name,
  308. poll["Payload"],
  309. )
  310. else:
  311. if "dps" in poll:
  312. poll = poll["dps"]
  313. poll["full_poll"] = full_poll
  314. yield poll
  315. await asyncio.sleep(0.1 if self.has_returned_state else 5)
  316. except CancelledError:
  317. self._running = False
  318. # Close the persistent connection when exiting the loop
  319. self._api.set_socketPersistent(False)
  320. if self._api.parent:
  321. self._api.parent.set_socketPersistent(False)
  322. raise
  323. except Exception as t:
  324. _LOGGER.exception(
  325. "%s receive loop error %s:%s",
  326. self.name,
  327. type(t),
  328. t,
  329. )
  330. self._api.set_socketPersistent(False)
  331. if self._api.parent:
  332. self._api.parent.set_socketPersistent(False)
  333. await asyncio.sleep(5)
  334. # Close the persistent connection when exiting the loop
  335. self._api.set_socketPersistent(False)
  336. if self._api.parent:
  337. self._api.parent.set_socketPersistent(False)
  338. def set_detected_product_id(self, product_id):
  339. self._product_ids.append(product_id)
  340. async def async_possible_types(self):
  341. cached_state = self._get_cached_state()
  342. if len(cached_state) <= 1:
  343. # in case of device22 devices, we need to poll them with a dp
  344. # that exists on the device to get anything back. Most switch-like
  345. # devices have dp 1. Lights generally start from 20. 101 is where
  346. # vendor specific dps start. Between them, these three should cover
  347. # most devices. 148 covers a doorbell device that didn't have these
  348. # 201 covers remote controllers and 2 and 9 cover others without 1
  349. self._api.set_dpsUsed(
  350. {
  351. "1": None,
  352. "2": None,
  353. "9": None,
  354. "20": None,
  355. "60": None,
  356. "101": None,
  357. "148": None,
  358. "201": None,
  359. }
  360. )
  361. await self.async_refresh()
  362. cached_state = self._get_cached_state()
  363. return await self._hass.async_add_executor_job(
  364. _collect_possible_matches,
  365. cached_state,
  366. self._product_ids,
  367. )
  368. async def async_inferred_type(self):
  369. best_match = None
  370. best_quality = 0
  371. cached_state = self._get_cached_state()
  372. possible = await self.async_possible_types()
  373. for config in possible:
  374. quality = config.match_quality(cached_state, self._product_ids)
  375. _LOGGER.info(
  376. "%s considering %s with quality %s",
  377. self.name,
  378. config.name,
  379. quality,
  380. )
  381. if quality > best_quality:
  382. best_quality = quality
  383. best_match = config
  384. if best_match:
  385. return best_match.config_type
  386. _LOGGER.warning(
  387. "Detection for %s with dps %s failed",
  388. self.name,
  389. log_json(cached_state),
  390. )
  391. async def async_refresh(self):
  392. _LOGGER.debug("Refreshing device state for %s", self.name)
  393. if self.should_poll:
  394. await self._retry_on_failed_connection(
  395. lambda: self._refresh_cached_state(),
  396. f"Failed to refresh device state for {self.name}.",
  397. )
  398. def get_property(self, dps_id):
  399. cached_state = self._get_cached_state()
  400. return cached_state.get(dps_id)
  401. async def async_set_property(self, dps_id, value):
  402. await self.async_set_properties({dps_id: value})
  403. def anticipate_property_value(self, dps_id, value):
  404. """
  405. Update a value in the cached state only. This is good for when you
  406. know the device will reflect a new state in the next update, but
  407. don't want to wait for that update for the device to represent
  408. this state.
  409. The anticipated value will be cleared with the next update.
  410. """
  411. self._cached_state[dps_id] = value
  412. def _reset_cached_state(self):
  413. self._cached_state = {"updated_at": 0}
  414. self._pending_updates = {}
  415. self._last_connection = 0
  416. def _refresh_cached_state(self):
  417. new_state = self._api.status()
  418. if new_state:
  419. self._cached_state = self._cached_state | new_state.get("dps", {})
  420. self._cached_state["updated_at"] = time()
  421. for entity in self._children:
  422. for dp in entity._config.dps():
  423. # Clear non-persistant dps that were not in the poll
  424. if not dp.persist and dp.id not in new_state.get("dps", {}):
  425. self._cached_state.pop(dp.id, None)
  426. entity.schedule_update_ha_state()
  427. _LOGGER.debug(
  428. "%s refreshed device state: %s",
  429. self.name,
  430. log_json(new_state),
  431. )
  432. if "Err" in new_state:
  433. _LOGGER.warning(
  434. "%s protocol error %s: %s",
  435. self.name,
  436. new_state.get("Err"),
  437. new_state.get("Error", "message not provided"),
  438. )
  439. _LOGGER.debug(
  440. "new state (incl pending): %s",
  441. log_json(self._get_cached_state()),
  442. )
  443. async def async_set_properties(self, properties):
  444. if len(properties) == 0:
  445. return
  446. self._add_properties_to_pending_updates(properties)
  447. await self._debounce_sending_updates()
  448. def _add_properties_to_pending_updates(self, properties):
  449. now = time()
  450. pending_updates = self._get_pending_updates()
  451. for key, value in properties.items():
  452. pending_updates[key] = {
  453. "value": value,
  454. "updated_at": now,
  455. "sent": False,
  456. }
  457. _LOGGER.debug(
  458. "%s new pending updates: %s",
  459. self.name,
  460. log_json(pending_updates),
  461. )
  462. def _remove_properties_from_pending_updates(self, data):
  463. self._pending_updates = {
  464. key: value
  465. for key, value in self._pending_updates.items()
  466. if key not in data or not value["sent"] or data[key] != value["value"]
  467. }
  468. async def _debounce_sending_updates(self):
  469. now = time()
  470. since = now - self._last_connection
  471. # set this now to avoid a race condition, it will be updated later
  472. # when the data is actally sent
  473. self._last_connection = now
  474. # Only delay a second if there was recently another command.
  475. # Otherwise delay 1ms, to keep things simple by reusing the
  476. # same send mechanism.
  477. waittime = 1 if since < 1.1 and self.should_poll else 0.001
  478. await asyncio.sleep(waittime)
  479. await self._send_pending_updates()
  480. async def _send_pending_updates(self):
  481. pending_properties = self._get_unsent_properties()
  482. _LOGGER.debug(
  483. "%s sending dps update: %s",
  484. self.name,
  485. log_json(pending_properties),
  486. )
  487. await self._retry_on_failed_connection(
  488. lambda: self._set_values(pending_properties),
  489. "Failed to update device state.",
  490. )
  491. def _set_values(self, properties):
  492. try:
  493. self._lock.acquire()
  494. self._api.set_multiple_values(properties, nowait=True)
  495. self._cached_state["updated_at"] = 0
  496. now = time()
  497. self._last_connection = now
  498. pending_updates = self._get_pending_updates()
  499. for key in properties.keys():
  500. pending_updates[key]["updated_at"] = now
  501. pending_updates[key]["sent"] = True
  502. finally:
  503. self._lock.release()
  504. async def _retry_on_failed_connection(self, func, error_message):
  505. if self._api_protocol_version_index is None:
  506. await self._rotate_api_protocol_version()
  507. auto = (self._protocol_configured == "auto") and (
  508. not self._api_protocol_working
  509. )
  510. connections = (
  511. self._AUTO_CONNECTION_ATTEMPTS
  512. if auto
  513. else self._SINGLE_PROTO_CONNECTION_ATTEMPTS
  514. )
  515. for i in range(connections):
  516. try:
  517. if not self._hass.is_stopping:
  518. retval = await self._hass.async_add_executor_job(func)
  519. if isinstance(retval, dict) and "Error" in retval:
  520. raise AttributeError(retval["Error"])
  521. self._api_protocol_working = True
  522. self._api_working_protocol_failures = 0
  523. return retval
  524. except Exception as e:
  525. _LOGGER.debug(
  526. "Retrying after exception %s %s (%d/%d)",
  527. type(e),
  528. e,
  529. i,
  530. connections,
  531. )
  532. if i + 1 == connections:
  533. self._reset_cached_state()
  534. self._api_working_protocol_failures += 1
  535. if (
  536. self._api_working_protocol_failures
  537. > self._AUTO_FAILURE_RESET_COUNT
  538. ):
  539. self._api_protocol_working = False
  540. for entity in self._children:
  541. entity.async_schedule_update_ha_state()
  542. if self._api_working_protocol_failures == 1:
  543. _LOGGER.error(error_message)
  544. else:
  545. _LOGGER.info(error_message)
  546. if not self._api_protocol_working:
  547. await self._rotate_api_protocol_version()
  548. def _get_cached_state(self):
  549. cached_state = self._cached_state.copy()
  550. return {**cached_state, **self._get_pending_properties()}
  551. def _get_pending_properties(self):
  552. return {
  553. key: property["value"]
  554. for key, property in self._get_pending_updates().items()
  555. }
  556. def _get_unsent_properties(self):
  557. return {
  558. key: info["value"]
  559. for key, info in self._get_pending_updates().items()
  560. if not info["sent"]
  561. }
  562. def _get_pending_updates(self):
  563. now = time()
  564. # sort pending updates according to their API identifier
  565. pending_updates_sorted = sorted(
  566. self._pending_updates.items(), key=lambda x: int(x[0])
  567. )
  568. self._pending_updates = {
  569. key: value
  570. for key, value in pending_updates_sorted
  571. if not value["sent"]
  572. or now - value.get("updated_at", 0) < self._FAKE_IT_TIMEOUT
  573. }
  574. return self._pending_updates
  575. async def _rotate_api_protocol_version(self):
  576. if self._api_protocol_version_index is None:
  577. try:
  578. self._api_protocol_version_index = API_PROTOCOL_VERSIONS.index(
  579. self._protocol_configured
  580. )
  581. except ValueError:
  582. self._api_protocol_version_index = 0
  583. # only rotate if configured as auto
  584. elif self._protocol_configured == "auto":
  585. self._api_protocol_version_index += 1
  586. if self._api_protocol_version_index >= len(API_PROTOCOL_VERSIONS):
  587. self._api_protocol_version_index = 0
  588. new_version = API_PROTOCOL_VERSIONS[self._api_protocol_version_index]
  589. _LOGGER.info(
  590. "Setting protocol version for %s to %0.1f",
  591. self.name,
  592. new_version,
  593. )
  594. await self._hass.async_add_executor_job(
  595. self._api.set_version,
  596. new_version,
  597. )
  598. if self._api.parent:
  599. await self._hass.async_add_executor_job(
  600. self._api.parent.set_version,
  601. new_version,
  602. )
  603. @staticmethod
  604. def get_key_for_value(obj, value, fallback=None):
  605. keys = list(obj.keys())
  606. values = list(obj.values())
  607. return keys[values.index(value)] if value in values else fallback
  608. def setup_device(hass: HomeAssistant, config: dict):
  609. """Setup a tuya device based on passed in config."""
  610. _LOGGER.info("Creating device: %s", get_device_id(config))
  611. hass.data[DOMAIN] = hass.data.get(DOMAIN, {})
  612. device = TuyaLocalDevice(
  613. config[CONF_NAME],
  614. config[CONF_DEVICE_ID],
  615. config[CONF_HOST],
  616. config[CONF_LOCAL_KEY],
  617. config[CONF_PROTOCOL_VERSION],
  618. config.get(CONF_DEVICE_CID),
  619. hass,
  620. config[CONF_POLL_ONLY],
  621. )
  622. hass.data[DOMAIN][get_device_id(config)] = {
  623. "device": device,
  624. "tuyadevice": device._api,
  625. }
  626. return device
  627. async def async_delete_device(hass: HomeAssistant, config: dict):
  628. device_id = get_device_id(config)
  629. _LOGGER.info("Deleting device: %s", device_id)
  630. await hass.data[DOMAIN][device_id]["device"].async_stop()
  631. del hass.data[DOMAIN][device_id]["device"]
  632. del hass.data[DOMAIN][device_id]["tuyadevice"]