OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides a variety of device interactions with power. | 5 """Provides a variety of device interactions with power. |
6 """ | 6 """ |
7 # pylint: disable=unused-argument | 7 # pylint: disable=unused-argument |
8 | 8 |
9 import collections | 9 import collections |
10 import contextlib | 10 import contextlib |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 battery_level = self.GetBatteryInfo().get('level') | 377 battery_level = self.GetBatteryInfo().get('level') |
378 if battery_level is None: | 378 if battery_level is None: |
379 logging.warning('Unable to find current battery level.') | 379 logging.warning('Unable to find current battery level.') |
380 battery_level = 100 | 380 battery_level = 100 |
381 else: | 381 else: |
382 logging.info('current battery level: %s', battery_level) | 382 logging.info('current battery level: %s', battery_level) |
383 battery_level = int(battery_level) | 383 battery_level = int(battery_level) |
384 return battery_level >= level | 384 return battery_level >= level |
385 | 385 |
386 timeout_retry.WaitFor(device_charged, wait_period=wait_period) | 386 timeout_retry.WaitFor(device_charged, wait_period=wait_period) |
| 387 |
| 388 def LetBatteryCoolToTemperature(self, target_temp, wait_period=60): |
| 389 """Lets device sit to give battery time to cool down |
| 390 Args: |
| 391 temp: maximum temperature to allow in tenths of degrees c. |
| 392 wait_period: time in seconds to wait between checking. |
| 393 """ |
| 394 def cool_device(): |
| 395 temp = self.GetBatteryInfo().get('temperature') |
| 396 if temp is None: |
| 397 logging.warning('Unable to find current battery temperature.') |
| 398 temp = 0 |
| 399 else: |
| 400 logging.info('Current battery temperature: %s', temp) |
| 401 return int(temp) <= target_temp |
| 402 |
| 403 logging.info('Waiting for the device to cool down to %s degrees.', |
| 404 target_temp) |
| 405 timeout_retry.WaitFor(cool_device, wait_period=wait_period) |
OLD | NEW |