1
mirror of https://github.com/home-assistant/core synced 2024-10-07 10:13:38 +02:00
ha-core/script
Andrew Hayworth eb6b6ed87d Add Awair sensor platform (#18570)
* Awair Sensor Platform

This commit adds a sensor platform for Awair devices, by accessing
their beta API. Awair heavily rate-limits this API, so we throttle
updates based on the number of devices found. We also allow for the
user to bypass API device listing entirely, because the device list
endpoint is limited to only 6 calls per day. A crashing or restarting
server would quickly hit that limit.

This sensor platform uses the python_awair library (also written
as part of this PR), which is available for async usage.

* Disable pylint warning for broad try/catch

It's true that this is generally not a great idea, but we really don't
want to crash here. If we can't set up the platform, logging it and
continuing is the right answer.

* Add space to satisfy the linter

* Awair platform PR feedback

- Bump python_awair to 0.0.2, which has support for more granular exceptions
- Ensure we have python_awair available in test
- Raise PlatformNotReady if we can't set up Awair
- Make the 'Awair score' its own sensor, rather than exposing it other ways
- Set the platform up as polling, and set a sensible default
- Pass in throttling parameters to the underlying data class, rather
than use hacky global variable access to dynamically set the interval
- Switch to dict access for required variables
- Use pytest coroutines, set up components via async_setup_component,
  and test/modify/assert in generally better ways
- Commit test data as fixtures

* Awair PR feedback, volume 2

- Don't force updates in test, instead modify time itself and let
  homeassistant update things "normally".
- Remove unneeded polling attribute
- Rename timestamp attribute to 'last_api_update', to better reflect
  that it is the timestamp of the last time the Awair API servers
  received data from this device.
- Use that attribute to flag the component as unavailable when data
  is stale. My own Awair device periodically goes offline and it really
  hardly indicates that at all.
- Dynamically set fixture timestamps to the test run utcnow() value,
  so that we don't have to worry about ancient timestamps in tests
  blowing up down the line.
- Don't assert on entities directly, for the most part. Find desired
  attributes in ... the attributes dict.

* Patch an instance of utcnow I overlooked

* Switch to using a context manager for timestream modification

Honestly, it's just a lot easier to keep track of patches. Moreover,
the ones I seem to have missed are now caught, and tests seem to
consistently pass.

Also, switch test_throttle_async_update to manipulating time more
explicitly.

* Missing blank line, thank you hound

* Fix pydocstyle error

I very much need to set up a script to do this quickly w/o tox, because
running flake8 is not enough!

* PR feedback

* PR feedback
2018-11-25 09:01:19 +01:00
..
bootstrap Consolidate frontend (#9915) 2017-10-24 19:36:27 -07:00
check_dirty Fail if dirty (#16839) 2018-09-25 20:47:51 +02:00
dev_docker tradfri: Improve color temp support detection (#7211) 2017-04-21 23:32:51 -07:00
dev_openzwave_docker Improve development workflow in docker (#5079) 2017-01-02 22:04:09 +01:00
gen_requirements_all.py Add Awair sensor platform (#18570) 2018-11-25 09:01:19 +01:00
inspect_schemas.py Update pydocstyle to 2.1.1 and flake8-docstrings to 1.3.0 (#14557) 2018-08-24 10:28:43 +02:00
lazytox.py Update pydocstyle to 2.1.1 and flake8-docstrings to 1.3.0 (#14557) 2018-08-24 10:28:43 +02:00
lint script/lint: Ensure there are files to test with pylint (#14363) 2018-05-10 12:47:04 +02:00
lint_docker Speeds up lint and test in docker by keeping the cache between invocations. (#5177) 2017-01-05 09:45:14 +01:00
monkeytype Add script to run monkeytype typing on test suite (#14440) 2018-06-21 15:06:05 +02:00
release Update release script 2018-05-26 11:54:50 -04:00
server Improve development workflow in docker (#5079) 2017-01-02 22:04:09 +01:00
setup Reorganize lint travis builds (#10670) 2017-11-19 17:39:24 -08:00
test Removing asyncio.coroutine syntax from HASS core (#12509) 2018-02-25 03:38:46 -08:00
test_docker Fix a bunch of typos (#9545) 2017-09-23 17:15:46 +02:00
translations_develop Config flow translations (#13066) 2018-03-11 12:04:34 -07:00
translations_download Update translations 2018-10-17 14:12:41 +02:00
translations_download_split.py Update pydocstyle to 2.1.1 and flake8-docstrings to 1.3.0 (#14557) 2018-08-24 10:28:43 +02:00
translations_upload Fix for Lokalise backend misinterpretation of keys (#13986) 2018-04-18 15:58:47 -04:00
translations_upload_merge.py Update pydocstyle to 2.1.1 and flake8-docstrings to 1.3.0 (#14557) 2018-08-24 10:28:43 +02:00
travis_deploy Support serving of backend translations (#12453) 2018-02-28 19:31:38 -08:00
update Improve development workflow in docker (#5079) 2017-01-02 22:04:09 +01:00
version_bump.py Use older syntax for version bump 2018-06-22 11:07:26 -04:00