core/tests/fixtures
Andrew Hayworth fed6625324
Refactor / update Awair integration (#34394)
* Refactor / update Awair integration

This commit does a few things, all in service of making the Awair
integration more modern and reliable. Specifically we do the following:

- Update to python_awair 0.1.1
- Begin using config entries / flow for setting up the integration.
  - YAML support is completely removed.
  - The integration now allows adding multiple Awair accounts, should a
    user wish to do so (I found it _very_ useful in development).
- Group various Awair sensors into devices, using the device registry.
- Renames various sensors and treats the "dust" sensor as a particulate sensor.
- Device update rate-limits are no longer dynamically calculated; the
  Awair API now separates rate-limits on a per-device basis.
- Supports sound pressure and illuminance sensors found on some Awair devices.
- We report the "awair index" for certain sensors as part of device_state_attributes.
  The "index" is a subjective measure of whether or not a sensor reading
  is "good" or "bad" (and to what extent). It's a component of the Awair
  score, and it is useful on its own as an input for those who wish to
  do things like "display this color if the value is 'bad'".

This is a breaking change, and requires updates to documentation and a
warning in the README. The breaking changes in detail, are:

- Support for all YAML configuration is removed, and users will need to
  re-add the integration via the UI.
- We no longer support overriding device discovery via manual
  configuration of device UUIDs. This was previously supported because
  the Awair API had severe limits on the device list endpoints; however
  those have since been removed.
- Gen 1 devices no longer show a "dust" sensor; rather we create a PM2.5
  sensor and a PM10 sensor and just keep the values in sync. This better
  reflects the sensor capabilities: it can detect particles in a range
  from 2.5 -> 10, but cannot differentiate between sizes.
- Sensors are renamed as follows:
  - "sensor.devicename_co2"   -> "sensor.devicename_carbon_dioxide"
  - "sensor.devicename_voc"   -> "sensor.devicename_volatile_organic_compounds"
  - "sensor.devicename_score" -> "sensor.devicename_air_quality_index"
  - I've chosen to call the "Awair Score" an "air quality index" sensor,
    because fundamentally the "Awair Score" and other air quality indices
    (such as CAQI) do the same thing: they calculate a value based on a
    variety of other inputs.

Under the hood, the integration has seen some improvements:

- We use the DataUpdateCoordinator class to handle updates, rather than
  rolling our own update class.
- The code no longer tracks availability based on a timestamp returned
  from the Awair service; we assert that if we have received a response
  and the response has data for our device, then we are available (and
  otherwise, not available). We don't need to test the actual Awair API
  so heavily.
- Test coverage has been expanded to handle a variety of products that
  Awair produces, not just the one I happen to own.
- Test coverage no longer concerns itself with testing behavior that is
  now handled by the DataUpdateCoordinator; nor is it concerned with
  ensuring that the overall component sets up and registers properly.
  These are assumed to be well-tested functionaity of the core and not
  things we need to re-test ourselves.

Finally - between library updates and integration updates, this
integration is well-positioned to support future updates. I have a
proof-of-concept patch for device automations, and the underlying
library now supports subclassing authentication (which clears the way
for us to use OAuth authentication for Awair).

* Wrap test fixture in mock_coro

Truthfully I'm not sure why this was passing on my local dev
environment, but I was developing with python 3.8 before. After
installing python 3.7, I was able to reproduce the CI failures and fix
them.

* Fix broken tests after #34901 and/or #34989

* Do not rename sensors so broadly

We're going to keep the sensors named as they were before, pending the
outcome of any decisions around the air_quality component and what names
should be standardized for air-quality-like devices.

If standardized names are selected (which does seem likely), then we
will update this integration to match them - at which point, it would be
a breaking change.

But for now, we'll keep names mostly identical to what users had before.

Notable in this commit is that we generate the entity_id ourselves,
rather than just allowing it to be auto-generated from the name
attribute. This allows us to provide more human friendly names, while
keeping the old format for entity ids. For example, given an Awair
device called "Living Room", we'll generate an entity id of
"sensor.living_room_voc" but show set the name of the device to "Living
Room Volatile organic compounds".

* Support import from config.yaml

We'll create a config entry from config.yaml the first time we're
loaded, and then defer to it from then on.

We ignore all keys other than the access_token, since we no longer need
to deal with per-account rate-limits (rather, everything is per-device
now).

* Add myself to CODEOWNERS

Since I wrote the initial integration, and now this re-write, it feels
appropriate for me to take care of the integration along with `danielsjf`.

* Remove name mangling

* Update homeassistant/components/awair/manifest.json

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/awair/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/awair/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/awair/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Address some review feedback

* Set up reauth flow in a job, rather than awaiting

* Remove unnecessary title string

* Remove unnecessary config schema checking

As pointed out in review, because this comes in via import from
`configuration.yaml`, we can rely on the `PLATFORM_SCHEMA` validation instead.

* Fix tests

* Set unique_id appropriately for legacy devices

For users who have had this integration already installed (and who have
updated their home assistant installation sometime in recent history),
we want to ensure that unique_id's are set to the same thing as before,
to facilitate the upgrade process.

To do that, we add an additional property to the `SENSOR_TYPES` dict
(`ATTR_UNIQUE_ID`) which allows us to map modern sensor names from
python_awair to what older versions called them - ie: `humidity` ->
`HUMID`. We then use that value when constructing the unique ID. This
should allow users to upgrade and not lose configuration even if entity
IDs would otherwise change (because we have changed the name format that
generates entity IDs).

One note is that for the gen1 `DUST` sensor, we have to treat it
differently. This integration used to call that a "PM2.5" sensor, but
the unique_id generated would be something like `awair_12345_DUST`. So
we special-case that sensor, and do the same thing. We do not need to
special-case the PM10 sensor for gen1 devices, because we didn't create
a PM10 sensor in the past (we do now, because the "DUST" sensor is
really a hybrid PM2.5/PM10 sensor).

* Patch async_setup_entry for two tests

* Update awair config_flow to require / use an email address for unique_id

Also, only start one re-auth flow.

* Add a few more tests, try to get coverage up.

* Add another test

* Move attribution to device_state_attributes

* Don't require email

* Switch from Union[dict, None] to Optional[dict]

* Use a mock where requested

* Fix missing constant rename

* Use async_create_task

* Bump test coverage a bit for config_flow

* s/CONF_UNIQUE_ID/UNIQUE_ID/g

* Add warning about deprecated platform config

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-06-21 21:46:07 +02:00
..
agent_dvr Add agent_dvr integration (#32711) 2020-05-08 09:49:47 -05:00
august Lock operation sensors for August (#32593) 2020-03-10 17:09:49 -07:00
awair Refactor / update Awair integration (#34394) 2020-06-21 21:46:07 +02:00
bsblan Add BSBLan Climate integration (#32375) 2020-05-09 22:16:21 -04:00
directv Support DirecTV music channels with extended meta (#34228) 2020-04-15 18:08:54 -07:00
elgato Add Elgato Key Light integration (#29592) 2019-12-08 09:26:31 +01:00
griddy Add griddy integration (#32591) 2020-03-10 23:00:30 +01:00
here_travel_time Add here_travel_time (#24603) 2019-09-23 11:50:18 +02:00
homekit_controller Add support for homekit valve accessories to homekit_controller (#32937) 2020-03-18 21:20:40 +00:00
hunterdouglas_powerview Fix legacy Hunter Douglas PowerView devices (#35895) 2020-05-21 09:18:45 +02:00
hvv_departures Add HVV integration (Hamburg public transportation) (#31564) 2020-06-15 00:15:20 +02:00
ipp Prevent discovery of IPP printers lacking identifier (#35630) 2020-05-16 10:48:36 +02:00
myq Add binary sensor for myq gateway connectivity (#33423) 2020-03-31 11:58:44 -07:00
nexia Add support for nexia automations (#33049) 2020-03-20 18:49:42 -05:00
nut Add tests for additional nut ups models (#34240) 2020-04-15 20:28:03 -05:00
ozw Add fan platform to ozw component (#35249) 2020-05-26 19:48:39 -04:00
powerwall Add version and device type to powerwall device_info (#33453) 2020-03-31 12:55:50 -07:00
pvpc_hourly_pricing Add pvpc electricity prices integration (#32092) 2020-03-22 14:25:31 -05:00
roku Update rokuecp to 0.5.0 (#36975) 2020-06-21 14:29:39 -05:00
sonarr Refactor Sonarr Integration (#33859) 2020-05-29 17:08:05 -07:00
tado Fix setting zone overlays for tados that support swing (#33439) 2020-03-31 17:29:45 -05:00
wled Fix dynamically add/remove WLED strip segments (#36407) 2020-06-03 17:18:50 +02:00
Ddwrt_Status_Lan.txt Unittests for ddwrt device tracker and bugfix (#3996) 2016-10-24 22:18:24 -07:00
Ddwrt_Status_Wireless.txt Unittests for ddwrt device tracker and bugfix (#3996) 2016-10-24 22:18:24 -07:00
abode_automation.json Add Abode tests (#32562) 2020-03-16 03:05:10 +01:00
abode_automation_changed.json Add Abode tests (#32562) 2020-03-16 03:05:10 +01:00
abode_devices.json Add Abode tests (#32562) 2020-03-16 03:05:10 +01:00
abode_login.json Add Abode tests (#32562) 2020-03-16 03:05:10 +01:00
abode_logout.json Fix Abode tests uncaught exceptions (#33365) 2020-03-28 18:54:07 +01:00
abode_oauth_claims.json Add Abode tests (#32562) 2020-03-16 03:05:10 +01:00
abode_panel.json Add Abode tests (#32562) 2020-03-16 03:05:10 +01:00
airly_no_station.json Add Airly integration (#26375) 2019-10-04 13:58:29 +02:00
airly_valid_station.json Add Airly integration (#26375) 2019-10-04 13:58:29 +02:00
alpr_cloud.json Component "Image processing" (#5166) 2017-01-14 08:18:03 +01:00
alpr_stdout.txt Component "Image processing" (#5166) 2017-01-14 08:18:03 +01:00
ambient_devices.json Make Ambient PWS async and cloud-push (#20332) 2019-01-28 15:35:39 -08:00
aurora.txt Fix aurora sensor not converting latitude and longitude correctly (#28643) 2020-01-09 08:40:10 +01:00
bom_weather.json Fix BOM weather '-' value (#14042) 2018-05-08 13:35:55 -04:00
brother_printer_data.json Bump brother to 0.1.11 (#33526) 2020-04-02 13:52:03 +02:00
coinmarketcap.json Add configurable decimal rounding of display value for CoinMarketCap sensor and upgrade to 5.0.3 (#14437) (#14604) 2018-05-25 15:39:04 +02:00
darksky.json Add severe weather sensor to Dark Sky (#22701) 2019-07-16 18:03:05 +02:00
efergy_budget.json Efergy (#15380) 2018-07-09 14:39:28 +02:00
efergy_cost.json Efergy (#15380) 2018-07-09 14:39:28 +02:00
efergy_current_values_multi.json Added support for multiple efergy sensors in the same household. (#6630) 2017-03-16 23:22:10 -07:00
efergy_current_values_single.json Added support for multiple efergy sensors in the same household. (#6630) 2017-03-16 23:22:10 -07:00
efergy_energy.json Efergy (#15380) 2018-07-09 14:39:28 +02:00
efergy_instant.json Added support for multiple efergy sensors in the same household. (#6630) 2017-03-16 23:22:10 -07:00
feedreader.xml Make Feedreader component more extendable (#14342) 2018-05-15 20:43:26 +02:00
feedreader1.xml Make Feedreader component more extendable (#14342) 2018-05-15 20:43:26 +02:00
feedreader2.xml Make Feedreader component more extendable (#14342) 2018-05-15 20:43:26 +02:00
feedreader3.xml avoid error in debug log mode and rss entry without title (#16316) 2018-08-31 12:54:25 +02:00
feedreader4.xml fix feedreader handling unrecognized published date (#28225) 2019-10-31 21:05:42 +01:00
foobot_data.json Adding Foobot device sensor (#12417) 2018-03-15 19:50:58 -07:00
foobot_devices.json Adding Foobot device sensor (#12417) 2018-03-15 19:50:58 -07:00
google_maps_elevation.json Move elevation to core config and clean up HTTP mocking in tests (#2378) 2016-06-27 09:02:45 -07:00
homematicip_cloud.json Bump dependency & add devices for HomematicIP Cloud (#36595) 2020-06-10 11:34:14 +02:00
ip-api.com.json Move elevation to core config and clean up HTTP mocking in tests (#2378) 2016-06-27 09:02:45 -07:00
ipapi.co.json Switch to ipapi.co (fixes #19846) (#19886) 2019-01-15 16:18:57 -08:00
london_air.json Adds London_air component (#9020) 2017-08-19 11:05:16 +02:00
melissa_cur_settings.json Add Melissa (HVAC/climate) component (#11503) 2018-02-03 03:17:01 +01:00
melissa_fetch_devices.json Add Melissa (HVAC/climate) component (#11503) 2018-02-03 03:17:01 +01:00
melissa_status.json Add Melissa (HVAC/climate) component (#11503) 2018-02-03 03:17:01 +01:00
metoffice.json Convert MetOffice to use UI for configuration (#34900) 2020-06-15 12:02:25 +02:00
microsoft_face_create_person.json [image_processing/microsoft_face_identify] face recognition for automation (#5472) 2017-01-24 21:50:10 -08:00
microsoft_face_detect.json [image_processing/microsoft_face_identify] face recognition for automation (#5472) 2017-01-24 21:50:10 -08:00
microsoft_face_identify.json [image_processing/microsoft_face_identify] face recognition for automation (#5472) 2017-01-24 21:50:10 -08:00
microsoft_face_persongroups.json [image_processing/microsoft_face_identify] face recognition for automation (#5472) 2017-01-24 21:50:10 -08:00
microsoft_face_persons.json [image_processing/microsoft_face_identify] face recognition for automation (#5472) 2017-01-24 21:50:10 -08:00
openhardwaremonitor.json Openhardwaremonitor (#8056) 2017-06-25 13:48:05 -07:00
pushbullet_devices.json Remove unnecessary executable permissions (#15469) 2018-07-14 23:03:36 +02:00
ring_chime_health_attrs.json Introducing Ring Door Bell Camera (including StickUp cameras) and WiFi sensors (#9962) 2017-10-21 16:08:40 +02:00
ring_devices.json Update Ring to 0.6.0 (#30748) 2020-01-14 12:54:45 -08:00
ring_devices_updated.json Update Ring to 0.6.0 (#30748) 2020-01-14 12:54:45 -08:00
ring_ding_active.json Make sure Ring binary_sensor state will update only if device_id matches (#9247) 2017-09-01 09:14:16 +02:00
ring_doorboot_health_attrs.json Introducing Ring Door Bell Camera (including StickUp cameras) and WiFi sensors (#9962) 2017-10-21 16:08:40 +02:00
ring_doorbot_siren_on_response.json Add ring switch platform (#25612) 2019-08-06 14:39:07 +02:00
ring_doorbots.json Introduced Ring binary sensors and refactored Ring component (#6520) 2017-03-31 08:53:56 -07:00
ring_oauth.json Fixes invalid JSON files and whitespace corrections in YAML files (#26396) 2019-09-03 16:02:42 -07:00
ring_session.json Introduced Ring binary sensors and refactored Ring component (#6520) 2017-03-31 08:53:56 -07:00
sleepiq-bed-single.json Sleepiq single sleeper crash (#24941) 2019-07-07 08:40:02 +02:00
sleepiq-bed.json SleepIQ component with sensor and binary sensor platforms (#3390) 2016-09-14 00:11:50 +02:00
sleepiq-familystatus-single.json Sleepiq single sleeper crash (#24941) 2019-07-07 08:40:02 +02:00
sleepiq-familystatus.json SleepIQ component with sensor and binary sensor platforms (#3390) 2016-09-14 00:11:50 +02:00
sleepiq-login-failed.json SleepIQ component with sensor and binary sensor platforms (#3390) 2016-09-14 00:11:50 +02:00
sleepiq-login.json SleepIQ component with sensor and binary sensor platforms (#3390) 2016-09-14 00:11:50 +02:00
sleepiq-sleeper.json SleepIQ component with sensor and binary sensor platforms (#3390) 2016-09-14 00:11:50 +02:00
smhi.json Swedish weather institute weather component (#16717) 2018-10-08 23:54:55 +02:00
uk_transport_bus.json Add uk_transport component. (#8600) 2017-07-26 20:49:52 +01:00
uk_transport_train.json Add uk_transport component. (#8600) 2017-07-26 20:49:52 +01:00
unifi_direct.txt Support for Unifi direct access device tracker (No unifi controller software) (#10097) 2017-11-17 14:47:40 -05:00
upc_connect.xml [device_traker/upc] New UPC connect box platform (#5100) 2017-01-09 18:08:37 +02:00
vultr_account_info.json Add platform and sensors for Vultr VPS (#9928) 2017-11-05 14:10:14 +01:00
vultr_server_list.json Add platform and sensors for Vultr VPS (#9928) 2017-11-05 14:10:14 +01:00
wsdot.json Added new Washington State DOT sensor. (#5496) 2017-01-24 22:08:19 -08:00
wunderground-error.json Make WUnderground async (#12385) 2018-02-16 14:54:11 -08:00
wunderground-invalid.json Make WUnderground async (#12385) 2018-02-16 14:54:11 -08:00
wunderground-valid.json Make WUnderground async (#12385) 2018-02-16 14:54:11 -08:00
yahoo_finance.json Added unit test to the Yahoo Finance sensor (#3943) 2016-10-20 20:14:50 +02:00
yahooweather.json Fix line endings [skipci] (#12333) 2018-02-11 23:07:28 -08:00
yandex_transport_reply.json Fix Yandex transport after API change (#32500) 2020-03-07 18:26:35 +01:00
yr.no.xml Fix incorrect file format yr test fixure (#29910) 2019-12-13 12:29:24 +01:00