Commit Graph

84 Commits (48057e1dfb49774ce11dff2a323ecb033988b69b)

Author SHA1 Message Date
Allen Porter 9e3f7d2961
Simplify nest reauth config flow (#63058) 2022-01-02 21:43:50 +01:00
Allen Porter 15baea4ba3
Use more narrow exception catching in `nest` (#63225) 2022-01-02 18:54:56 +01:00
Allen Porter ebc8e19788
Revert nest reloading due to lock up (#63206) 2022-01-02 17:08:38 +01:00
Allen Porter 788373a7ca
Update legacy nest config flow tests to use modern best practices (#63019)
* Update legacy nest tests to use modern best practices

Update legacy nest integration config flow tests to test the config flow actually through the integration APIs rather
than interacting with the config flow object directly. This is a pre-factoring pulled out of a larger config flow revamp
where we want to exercise the actual production code for initializing configuration, config flows, and authentication
implementations.

* Revert some test name/comment changes

* Update setup calls to verify async_setup_legacy is called
2021-12-29 10:38:50 -08:00
Allen Porter 2df0adfbc7
Reload nest integration when new devices are added (#62976) 2021-12-29 12:20:55 +01:00
Allen Porter 17fbfe2eed
Set a suggested_area on nest devices based on the Google Home room name (#62871) 2021-12-27 11:39:57 -08:00
Ville Skyttä f913961d63
Use DeviceAutomationType in tests/components/[m-r]* (#62443) 2021-12-20 22:29:22 +01:00
Allen Porter 368e16f189
Simplify nest test patch using new keyword (#62336) 2021-12-19 11:45:04 -08:00
Allen Porter a63fa53275
Persist nest media events to disk backed storage (#61641)
* Persist nest media events to disk backed storage

Persist nest events in the media player to disk, targeting about ~500mb
per camera device as a cap. Events are stored in config/nest/event_media/.

Add a NestEventMediaStore is used for persistence. It has three main jobs:
- Read/write the key/value data that holds event data (event type, time, device, etc)
- Read/write media contents to disk
- Pick the filename for the media event based on device and event deatils

The nest event media manager library handles cache management and eviction, and by
default uses an in memory cache. Home Assistant nest integration now provides the
disk backed implementation, which is invoked by the nest library.

The store reads the event metadata key/value dict on startup, and then writes it
back with a short delay of 5 seconds to avoid unnecessary writes.

Future work planned includes:
- Possibly a small memory buffer for media objects themselves. This could make sense
  when adding thumbnails to the media player grid to avoid unnecessary fetches
- Transcoding mp4 clips to animated image previews

* Address style errors

* Cleanup from CI test/pylint/etc.

* Put media for each device into its own directory

* Update comments for media store

* Decrease # of events to lower disk requirements

Target more like 1k events, to reduce disk needs.

* Address PR feedback

* Update homeassistant/components/nest/media_source.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Ignore incorrect mypy in nest library

* Fix pylint errors

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2021-12-18 23:53:40 -08:00
Allen Porter bff677e34e
Bump google-nest-sdm to 0.4.8 (#61851) 2021-12-15 13:12:38 +01:00
Allen Porter efbec55818
Suppress errors for legacy nest api when using media source (#61629) 2021-12-13 17:41:45 +01:00
Allen Porter cd001d0243
Only publish nest camera event messages once per thread and bump nest version (#61587) 2021-12-12 14:12:05 -08:00
Allen Porter c3e72bec0a
Update logic for nest media source `can_play` for events (#61537) 2021-12-12 14:10:20 -08:00
Allen Porter bbe4a67a98
Coalesce nest media source preview clips by session and bump google-nest-sdm (#61081) 2021-12-05 23:59:24 -08:00
Allen Porter 5bd1139867
Fix regression in nest event media player with multiple devices (#61064) 2021-12-05 13:02:37 -08:00
Allen Porter 5fdcbbe0e1
Fetch media for events for rendering in the nest media player (#61056) 2021-12-05 09:45:40 -08:00
Allen Porter 08003c5287
Improve nest media source event timestamp display (#61027)
Drop subsecond text from the nest media source event timestamp display, using a common date/time
template string.
2021-12-05 00:39:18 -08:00
Allen Porter ba99dc3af9
Add Nest Battery Cam event clip support with a Nest MediaSource (#60073) 2021-12-03 10:53:05 -08:00
Allen Porter a84b12abe7
Revert "Add an entity service for saving nest event related snapshots" (#60632) 2021-11-30 16:16:00 +01:00
Allen Porter c4e5242b0c
Add an entity service for saving nest event related snapshots (#58369)
* Add an entity service for saving nest event related snapshots

Add an entity service `nest.snapshot_event` for recording camera event
related media to disk. This is based on `camera.snapshot` but takes in
a parameter for a Nest API event_id.

PR #58299 adds `nest_event_id` to events published by nest so that they can
be hooked up to this service for capturing events.

Future related work includes:
- Height & Width parameters for the rendered image
- Support video clips for new battery cameras
- An API for proxying media related to events, separate from the camera image thumbnail
- A Nest MediaSource for browsing media related to events

* Revert debugging information

* Add test coverage for OSError failure case

* Add service description for nest snapshot service

* Reduce unnecessary diffs.

* Sort nest camera imports

* Remove unnecessary if block in snapshot
2021-11-29 23:04:29 -08:00
Allen Porter cc543b200d
Update `nest` config flow to dramatically simplify end user setup with automated pub/sub subscription creation (#59260)
* Configure nest pubsub subscriber automatically

Update the config flow to configure the nest pubsub subscriber automatically.
After completing the authentication step, the user is now asked for the google
cloud console ID, which is needed to create a subscription.

Home Assistant manages the lifecycle of a subscription only when it is created
by the ConfigFlow. Otherwise (if specified in configuration.yaml) it treats
it similarly as before.

These are the considerations or failure modes taken into account:
- Subscription is created with reasonable default values as previously recommended (e.g. retion only keeps 5-15 minutes of backlog messages)
- Subscriptions are created with a naming scheme that makes it clear they came from home assistant, and with a random
  string
- Subscriptions are cleaned up when the ConfigEntry is removed. If removal fails, a subscription that is orphaned will
  be deleted after 30 days
- If the subscription gets into a bad state or deleted, the user can go through the re-auth flow to re-create it.
- Users can still specifcy a CONF_SUBSCRIBER_ID in the configuration.yaml, and
skip automatic subscriber creation

* Remove unnecessary nest config flow diffs and merge in upstream changes

* Incorporate review feedback into nest subscription config flow

* Update text wording in nest config flow
2021-11-29 22:41:29 -08:00
Allen Porter 0991a30125
Pre-factor nest subscriber to library (#59462)
* Pre-factor nest subscriber to library

Move the nest subscriber to a library that can be reused in a future PR:
- From ConfigFlow for creating subscriptions
- On nest removal to delete subscriptions

This is pulled out of PR #59260 to make that easier to review.

* Resolve pylint error in nest api subscriber

* Remove duplicate constants
2021-11-14 16:08:22 -08:00
Allen Porter dbfe0cad52
Refactor nest test ConfigEntry setup in config flow tests (#59459)
* Refactor nest ConfigEntry creation in tests into a helper

This is pulled out of PR#59260 to make that overall diff smaller.

* Add typing consistently on new functions
2021-11-14 10:12:25 -08:00
Allen Porter fa4e890696
Revamp nest authentication config flows and remove need for redirect urls (#59033)
* Add support for Installed Auth authentication flows.

Add support for additional credential types to make configuration simpler for
end users. The existing Web App auth flow requires users to configure
redirect urls with Google that has a very high security bar: requires ssl,
and a publicly resolvable dns name.

The new Installed App flow requires the user to copy/paste an access code
and is the same flow used by the `google` calendar integration. This also
allows us to let users create one authentication credential to use with
multiple google integrations.

* Remove hard migration for nest config entries, using soft migration

* Add comment explaining soft migration

* Revet changes to common.py made obsolete by removing migration

* Reduce unnecessary diffs in nest common.py

* Update config entries using library method

* Run `python3 -m script.translations develop`

* Revert nest auth domain

* Remove compat function which is no longer needed

* Remove stale nest comment

* Adjust typing for python3.8

* Address PR feedback for nest auth revamp
2021-11-04 15:56:16 -07:00
Allen Porter 9c5a79c641
Add an image placeholder for Nest WebRTC cameras (#58250) 2021-10-28 21:07:29 -07:00
epenet 19eba5a3a0
Use constants for device registry checks (#58514)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2021-10-27 11:34:58 +02:00
Allen Porter f1b082a369
Publish nest event ids in camera related events (#58299) 2021-10-26 10:14:12 -05:00
Ville Skyttä 380cff167e
Use HTTPStatus in components/[nop]* (#58279) 2021-10-23 20:56:30 +02:00
Allen Porter 400e85a299
Rename tests filenames to conform to Home Assistant standards (#58266) 2021-10-22 22:25:55 -07:00
Allen Porter fc7be8aa00
Fix a bug in a nest test that causes side effects for other tests (#58264)
Fix a bug where a constant configuration variable in the common test library
is modified during the test, causing side effects for other tests.

This was found by renaming the tests, which caused other tests to fail.
2021-10-22 21:33:40 -07:00
Michael Davie e481c862a6
Change precision of Nest sensors (#56993)
* Change precision of Nest sensors

* Add comment to temp rounding

Co-authored-by: Allen Porter <allen.porter@gmail.com>

* Update rounding and tests

* Add test for rounding

Co-authored-by: Allen Porter <allen.porter@gmail.com>
2021-10-22 20:31:25 -07:00
Allen Porter 7d6ad6e5e3
Add additional nest stream test coverage (#58013) 2021-10-22 23:30:15 +02:00
Allen Porter 4501906da3
Fix additional nest camera_sdm_tests to use STATE_STREAMING (#57920) 2021-10-17 22:04:12 +02:00
Allen Porter 3d33cad655
Improve nest error handling for websocket streams (#57885) 2021-10-17 19:46:18 +02:00
Allen Porter 95b07c138c
Set `nest` camera always on STATE_STREAMING (#57882) 2021-10-17 19:45:31 +02:00
Allen Porter 1fa6329c2e
Add Nest WebRTC and support Nest Battery Camera and Nest Battery Doorbell (#57299)
* Add WebSocket API for intiting a WebRTC stream

See https://github.com/home-assistant/architecture/discussions/640

* Add nest support for initiating webrtc streams

Add an implementation of async_handle_web_rtc_offer in nest, with test coverage.
Issue #55302

* Rename offer variable to match overriden variable name

* Remove unnecessary checks covered by websocket function

* Update homeassistant/components/camera/__init__.py

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

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-13 03:28:52 -07:00
Allen Porter d0cc890d2b
Add statistics support to nest sensors (#57393)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-10-12 10:56:57 +02:00
Erik Montnemery f6682ba99d
Block tests from opening sockets (#55516) 2021-10-05 14:46:09 -10:00
Erik Montnemery f6526de7b6
Use hass_client_no_auth test fixture in nest tests (#56326) 2021-09-18 23:17:09 +02:00
Allen Porter 160bd74bae
Update DeviceInfo static types (#54276)
* Update nest static types from aditional PR feedback

Update nest and device helper static types based on post-merge discussion in PR #53475

* Remove unused type: ignore in synology

* Remove check for None device type

Remove check for None device type in order to reduce untested code as this is
a case not allowed by the nest python library.
2021-08-08 19:24:36 -07:00
Allen Porter 6376b4be5c
Increase static type coverage for nest integration (#53475)
Co-authored-by: Mick Vleeshouwer <mick@imick.nl>
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-07-27 01:43:52 +02:00
Ville Skyttä 19d25cd901
Change config entry state to an enum (#49654)
* Change config entry state to an enum

* Allow but deprecate EntryState str equality comparison

* Test fixes

* Rename to ConfigEntryState

* Remove str comparability backcompat

* Update new occurrences of strs cropped up during review
2021-05-20 19:19:20 +02:00
Allen Porter bcadccf7aa
Invalidate HLS Stream on nest url refresh failure (#47869)
This will ensure that the HLS stream is re-created and fetches a new url.
2021-03-14 22:49:21 -07:00
Erik Montnemery 84226da404
Update tests i-o to use async_get() instead of async_get_registry() (#47653) 2021-03-09 14:32:08 +01:00
Allen Porter 19f5b467b7
Make FAN_ON use the max duration rather than 15 min default (#46489) 2021-02-23 20:38:52 -06:00
Allen Porter 2bcf87b980
Change the API boundary between camera and stream with initial improvement for nest expiring stream urls (#45431)
* Change the API boundary between stream and camera

Shift more of the stream lifecycle management to the camera.  The motivation is to support stream urls that expire
giving the camera the ability to change the stream once it is created.

* Document stream lifecycle and simplify stream/camera interaction

* Reorder create_stream function to reduce diffs

* Increase test coverage for camera_sdm.py

* Fix ffmpeg typo.

* Add a stream identifier for each stream, managed by camera

* Remove stream record service

* Update homeassistant/components/stream/__init__.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Unroll changes to Stream interface back into camera component

* Fix preload stream to actually start the background worker

* Reduce unncessary diffs for readability

* Remove redundant camera stream start code

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2021-02-08 19:53:28 -08:00
Paulus Schoutsen 9e07910ab0
Mark entities as unavailable when they are removed but are still registered (#45528)
* Mark entities as unavailable when they are removed but are still registered

* Add sync_entity_lifecycle to collection helper

* Remove debug print

* Lint

* Fix tests

* Fix tests

* Update zha

* Update zone

* Fix tests

* Update hyperion

* Update rfxtrx

* Fix tests

* Pass force_remove=True from integrations

Co-authored-by: Erik <erik@montnemery.com>
2021-02-08 10:45:46 +01:00
Allen Porter eebd0d333e
Clear cached nest event images after expiration (#44956)
* Clear cached nest event images after expiration

* Don't share removal cleanup with alarm cleanup

Don't share code across these functions since it would require a dummy timestamp values that is unnecessary.

* Increase test coverage on sdm camera remove

* Update homeassistant/components/nest/camera_sdm.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2021-01-12 22:08:59 -08:00
Ville Skyttä 2fb3be50ab
Make DeviceRegistry.async_get_device connections arg optional (#44897)
* Make async_get_device connections Optional, default None

* Remove unnecessary async_get_device connections arg usages

Some of these were using an incorrect collection type, which didn't
cause issues mostly just due to luck.
2021-01-07 13:49:45 +01:00
Allen Porter 560e3811a3
Generate nest images thumbnails from events (#44638)
* Capture nest still images from events

Use python google-nest-sdm API for fetching images.  Update home assistant
to use the google-nest-sdm API for fetching the image contents generated
by the server.  This uses the existing websession object for server fetches,
reducing the amount of new code and facilites unit testing using the existing
mechanism.

Simplify tests using the image fetch API rather than a snapshot API
2021-01-06 07:02:04 -08:00