Commit Graph

5 Commits (af62660b14a807b773b5ecfc4192523ba98a25ce)

Author SHA1 Message Date
Phil Bruckner 0ed7bc3b8e
Convert amcrest binary sensors from poll to stream (#32818)
* Convert amcrest binary sensors from poll to stream

- Bump amcrest package to 1.6.0.
- For online binary sensor poll camera periodically to test communications in case
  configuration & usage results in no other communication to camera.
- Start a separate thread to call camera's event_stream method since it never returns.
- Convert all received events into signals that cause corresponding sensors to update.
- Use camera's generic event_channels_happened method to update sensors at startup,
  and whenever camera comes back online after being unavailable.

* Changes per review

* Changes per review 2

* Changes per review 3

- Move event stream decoding to amcrest package.
- Change name of event processing threads so global
  counter is no longer required.
- Bump amcrest package to 1.7.0.
2020-03-19 21:07:21 -07:00
Phil Bruckner d1e7ade6db
Make amcrest integration more robust (#30843)
- Bump amcrest package to 1.5.6. Includes networking improvements, no longer
  communicates during Http.__init__(), and allows running snapshot command
  without using stream mode.
- Handle login errors better, and not just at startup.
- Increase network connect & read timeout to 6.05 seconds.
- Increase network read timeout to 20 seconds for snapshot command.
- Run snapshot command in separate task, that cannot be cancelled, to eliminate
  possibility of two snapshot commands running simultaneously (since
  AmcrestCam.async_camera_image can be cancelled.) Also makes sure any exceptions
  from the command are caught properly.
2020-02-06 14:44:48 -06:00
Paulus Schoutsen 4de97abc3a Black 2019-07-31 12:25:30 -07:00
Phil Bruckner 233bc1a108 Improve amcrest error handling and bump amcrest package to 1.5.3 (#24262)
* Improve amcrest error handling and bump amcrest package to 1.5.3

amcrest package update fixes command retry, especially with Digest Authentication, and allows sending snapshot command without channel parameter.

Get rid of persistent_notification.

Errors at startup, other than login errors, are no longer fatal.

Display debug messages about how many times an error has occurred in a row.

Remove initial communications test. If camera is off line at startup this just delays the component setup.

Handle urllib3 errors when getting data from commands that were sent with stream=True.

If errors occur during camera update, try repeating until it works or the camera is determined to be off line.

Drop channel parameter in snapshot command which allows camera to use its default channel, which is different in different camera models and firmware versions.

Make entities unavailable if too many errors occur in a row.

Add new configuration variables to control how many errors in a row should be interpreted as camera being offline, and how frequently to "ping" camera to see when it becomes available again.

Add online binary_sensor option to indicate if camera is available (i.e., responding to commands.)

* Update per review comments

Remove max_errors and recheck_interval configuration variables and used fixed values instead.

Move definition of AmcrestChecker class to module level.

Change should_poll in camera.py to return a fixed value of True and move logic to update method.
2019-06-07 21:46:49 -07:00
Phil Bruckner 86b017e2f0 Add amcrest camera services and deprecate switches (#22949)
* Add amcrest camera services and deprecate switches

- Implement enabling and disabling motion detection from camera platform.
- Add amcrest specific camera services for controlling audio stream, motion recording, continuous recording and camera color mode, as well as moving camera to PTZ preset and starting and stopping PTZ tour function.
- Add camera attributes to indicate the state of the various camera settings controlled by the new services.
- Deprecate switches in favor of camera services and attributes.

* Rename services and move service handling to __init__.py

Rename services from 'camera.amcrest_xxx' to 'amcrest.xxx'. This allows services to be documented in services.yaml.

Add services.yaml.

Reorganize hass.data[DATA_AMCREST] and do some general cleanup to make various platform modules more consistent.

Move service handling code to __init__.py from camera.py.

* Update per review comments, part 1

- Rebase
- Add permission checking to services
- Change cv.ensure_list_csv to cv.ensure_list
- Add comment for "pointless-statement" in setup
- Change handler_services to handled_services
- Remove check if services have alreaday been registered
- Pass ffmpeg instead of hass to AmcrestCam __init__
- Remove writing motion_detection attr from device_state_attributes
- Change service methods from callbacks to coroutines

* Update per review comments, part 2

- Use dispatcher to signal camera entities to run services.
- Reorganize a bit, including moving a few things to new modules const.py & helpers.py.

* Update per review comments, part 3

Move call data extraction from camera.py to __init__.py.
2019-04-24 22:39:49 -07:00