Commit graph

46 commits

Author SHA1 Message Date
Erik Montnemery
d495208995
Remove unnecessary block use of pylint disable in onvif (#100194) 2023-09-12 09:19:26 -05:00
J. Nick Koston
00b600bfa8
Fix ONVIF cameras that change the xaddr for the pull point service (#93104) 2023-05-17 13:14:31 +02:00
J. Nick Koston
ef887e529f
Fix onvif cameras that cannot parse relative time (#92711)
* Fix onvif cameras that cannot parse relative time

The spec requires that the camera can parse relative or absolute timestamps
However there are many cameras that cannot parse time correctly.

Much of the event code has been offloaded to the library and
support to determine if the camera has broken time and switch
to absolute timestamps is now built into the library

* adjust verison

* fixes

* bump

* bump

* bump

* more fixes

* preen

* fix resume

* one more fix

* fix race in webhook setup

* bump to 3.1.3 which has more fixes for broken camera firmwares

* bump 3.1.4 for more fixes

* fix

* fix comment

* bump

* fix url limit

* bump

* more fixes

* old hik uses -s
2023-05-14 16:08:39 -04:00
J. Nick Koston
bcbc8539a6
Fix missing ONVIF events when switching from PullPoint to webhooks (#92627)
We now let the PullPoint subscription expire instead of explicitly
unsubscribing when pausing the subscription. We will still unsubscribe
it if Home Assistant is shutdown or the integration is reloaded

Some cameras will cancel ALL subscriptions when we do an unsubscribe
so we want to let the PullPoint subscription expire instead
of explicitly cancelling it.
2023-05-05 14:38:36 -04:00
J. Nick Koston
9a589a3a54
Improve reliability of ONVIF subscription renewals (#92551)
* Improve reliablity of onvif subscription renewals

upstream changelog: https://github.com/hunterjm/python-onvif-zeep-async/compare/v2.0.0...v2.1.0

* ```
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/onvif/client.py", line 75, in _async_wrap_connection_error_retry
    return await func(*args, **kwargs)
  File "/Users/bdraco/home-assistant/homeassistant/components/onvif/event.py", line 441, in _async_call_pullpoint_subscription_renew
    await self._pullpoint_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/zeep/proxy.py", line 64, in __call__
    return await self._proxy._binding.send_async(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 156, in send_async
    response = await client.transport.post_xml(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/zeep/transports.py", line 235, in post_xml
    response = await self.post(address, message, headers)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/zeep/transports.py", line 220, in post
    response = await self.client.post(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/httpx/_client.py", line 1845, in post
    return await self.request(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/httpx/_client.py", line 1530, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/httpx/_client.py", line 1617, in send
    response = await self._send_handling_auth(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/httpx/_client.py", line 1645, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects
    response = await self._send_single_request(request)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/httpx/_client.py", line 1719, in _send_single_request
    response = await transport.handle_async_request(request)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 352, in handle_async_request
    with map_httpcore_exceptions():
  File "/opt/homebrew/Cellar/python@3.10/3.10.10_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadTimeout
```

* adjust timeouts for slower tplink cameras

* tweak

* more debug

* tweak

* adjust message

* tweak

* Revert "tweak"

This reverts commit 10ee2a8de7.

* give time in seconds

* revert

* revert

* Update homeassistant/components/onvif/event.py

* Update homeassistant/components/onvif/event.py
2023-05-05 14:26:58 -04:00
J. Nick Koston
7987b00d89
Fix blocking I/O in the event loop when starting ONVIF (#92518) 2023-05-04 12:05:29 -05:00
J. Nick Koston
20942ab26f
Handle webhook URL rejection in onvif (#92405) 2023-05-03 15:46:53 +02:00
J. Nick Koston
324df197d1
Avoid starting ONVIF PullPoint if the camera reports its unsupported (#92333) 2023-05-01 18:33:52 +02:00
J. Nick Koston
4fcf05c202
Ensure onvif webhook can be registered (#92295) 2023-04-30 18:06:38 +02:00
J. Nick Koston
e25885b943
Improve error reporting in onvif in config flow (#91876) 2023-04-24 15:20:37 +02:00
J. Nick Koston
ddb3955a23
Add guards to onvif for when the PullPoint to Webhook url changes (#91886) 2023-04-24 14:35:45 +02:00
J. Nick Koston
f3838dde3a
Cleanup onvif topic before lookup (#91914)
* Cleanup onvif topic before lookup

Some devices will append . and / to the path. We need
to strip it off to find the correct matcher

fixes #51870

* Update homeassistant/components/onvif/event.py

* Update homeassistant/components/onvif/event.py

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2023-04-23 23:02:08 -04:00
J. Nick Koston
c38839d72f
Suppress events for tns1:MediaControl/VideoEncoderConfiguration with onvif (#91916)
These events are not useful to the integration and generate a
confusing log message
```
2023-04-23 14:01:21.866 INFO (MainThread) [homeassistant.components.onvif] DS-HD1: No registered handler for event from 80:91:33:88:8d:bd: {
    SubscriptionReference: None,
    Topic: {
        _value_1: tns1:MediaControl/VideoEncoderConfiguration,
        Dialect: http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet,
        _attr_1: {
    }
    },
    ProducerReference: None,
    Message: {
        _value_1: {
            Source: {
                SimpleItem: [
                    {
                        Name: VideoEncoderConfigurationToken,
                        Value: VideoEncoderToken_1
                    }
                ],
                ElementItem: [],
                Extension: None,
                _attr_1: None
            },
            Key: None,
            Data: {
                SimpleItem: [],
                ElementItem: [
                    {
                        _value_1: <Element {http://www.onvif.org/ver10/media/wsdl}Configuration at 0x2a9e103c0>,
                        Name: Config
                    }
                ],
                Extension: None,
                _attr_1: None
            },
            Extension: None,
            UtcTime: datetime.datetime(2023, 4, 23, 20, 1, 17, tzinfo=<isodate.tzinfo.Utc object at 0x1696b1270>),
            PropertyOperation: Initialized,
            _attr_1: {
        }
        }
    }
}

```

We now ignore them
2023-04-23 20:54:37 -04:00
J. Nick Koston
bba225abc5
Mark onvif events as stale when the subscription renewal fails (#91567) 2023-04-23 01:14:22 +02:00
J. Nick Koston
3beb6e9718
Add webhook support to onvif (#91485) 2023-04-22 17:49:41 +02:00
Meow
963648a333
Add SetSynchronizationPoint fallback to onvif (#86400)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-15 09:41:34 -10:00
J. Nick Koston
72dfd95831
Fix creating onvif pull point subscriptions when InitialTerminationTime is required (#91470)
* Fix creating onvif pull point subscriptions when InitialTerminationTime is required

fixes #85902

* Bump again because I got it wrong the first time.. this is why retest is good
2023-04-15 15:34:07 -04:00
J. Nick Koston
0b8fb36a7e
Fix onvif binary sensors (#90202)
* Fix httpx client creating a new ssl context with each client

While working on https://github.com/home-assistant/core/issues/83524
it was discovered that each new httpx client creates a new ssl context

f1157dbc41/httpx/_transports/default.py (L261)

If an ssl context is passed in creating a new one is avoided here

f1157dbc41/httpx/_config.py (L110)

This change makes httpx ssl no-verify behavior match aiohttp ssl no-verify
behavior

6da04694fd/aiohttp/connector.py (L892)

aiohttp solved this by wrapping the code that generates the ssl context
in an lru_cache

* compact

* Fix onvif binary sensors

fixes #83524

needs https://github.com/hunterjm/python-onvif-zeep-async/pull/9 first
to avoid recreating the memory leak

* Fix memory leak in onvif

Work around until https://github.com/hunterjm/python-onvif-zeep-async/pull/9

followup to https://github.com/home-assistant/core/pull/83006

* move check

* onvif-zeep-async 1.2.2

* fix unloading
2023-03-25 23:28:38 -04:00
Marc Mueller
60b799aac9
Misc typing improvements (#86550) 2023-01-25 11:05:36 +01:00
Franck Nijhof
baef267f33
String formatting and max line length - Part 3 (#84394) 2022-12-22 13:35:47 +01:00
J. Nick Koston
4239923ea2
Fix memory leak in onvif (#83006)
fixes https://github.com/home-assistant/core/issues/82504
2022-11-30 21:40:59 +01:00
Marc Mueller
63d519c1a8
Spelling updates (#82867) 2022-11-28 16:51:43 +01:00
Diogo Gomes
7999f109d1
Fix ONVIF subscription errors (#81965)
fixes undefined
2022-11-16 12:51:14 +01:00
epenet
b318b9b196
Improve onvif type hints (#73642)
* Remove onvif from mypy ignore list

* Adjust parsers

* Adjust event

* Adjust config_flow
2022-06-20 12:07:33 +02:00
Jason Hunter
29a2df3dfc
Restore ONVIF sensors (#70393)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2022-04-26 22:42:53 -07:00
Dave T
020f94fa56
Handle additional ONVIF messages (Hikvision) (#66357)
* Handle additional onvif messages (hikvision)

* Only convert to local timezone once.

* Code review: put new parser in a better place.

* Remove whitespace

* Code review: Remove ONVIF 'line crossed' parser

* Code review: Unparsed events log info not warning

* Fix isort

* Handle additional onvif messages (hikvision)

* Only convert to local timezone once.

* Code review: put new parser in a better place.

* Remove whitespace

* Code review: Remove ONVIF 'line crossed' parser

* Code review:only return valid datetime,improve try

* Code review: datetime conversions into try blocks

* address PR comments

Co-authored-by: Jason Hunter <hunterjm@gmail.com>
2022-04-21 15:30:35 -04:00
Marc Mueller
62c20860ac
Use assignment expressions 22 (#57971) 2021-10-21 08:33:10 +02:00
Marc Mueller
364767ff22
Import Callable from collections.abc (4) (#56778) 2021-09-29 16:15:36 +02:00
Maciej Bieniek
f212049fc2
Add constructor return type in integrations O-S (#50896) 2021-05-20 15:58:17 +02:00
Franck Nijhof
6932cf9534
Use contextlib.suppress where possible (#48189) 2021-03-23 14:36:43 +01:00
J. Nick Koston
c820dd4cb5
Have pylint warn when user visible log messages do not start with capital letter or end with a period (#48064)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-03-19 09:26:36 -05:00
Marc Mueller
3d2b81a401
Update typing 11 (#48072) 2021-03-18 13:21:46 +01:00
Jason Hunter
f1bb7b4a0f
attempt to renew subscription immediately to stop endless loop if it fails after setup (#42651) 2020-10-31 09:15:11 -04:00
Rihan9
d01a96d1ce
Fix onvif sensor detection and onvif stop service call (#41949)
* Fix stop service call after movement, add new parser for topic: tns1:RuleEngine/MotionRegionDetector/Motion

* Fix PullMessages call and formatting Stop call

* Fix timeout on pullmessages call

* Fix black and flake8 detected issues

* add SetSynchronizationPoint with try/except block
2020-10-19 13:01:34 -04:00
Jason Hunter
5a397312e7
Update ONVIF to Zeep 4.0/httpx (#42020)
* convert to httpx and zeep 4.0

* fix tests

* add onvif-zeep-async to manifest

* pin zeep to fool CI cache

* address review comments
2020-10-18 23:29:53 -04:00
Eric Severance
34cb12d3c9
Addressing feedback from #37711 (#38781) 2020-08-12 09:34:27 -04:00
Eric Severance
49b375ff94
Allow ONVIF devices to resume a PullPoint subscription when the camera reboots (#37711) 2020-08-11 17:53:30 -04:00
Eric Severance
61a911af41
Adapt the ONVIF Renewal termination_time for Amcrest cameras (#37750) 2020-08-11 16:59:26 -04:00
J. Nick Koston
8b06d1d4bd
Prevent onvif from blocking startup (#38256) 2020-07-27 08:51:53 +02:00
Jason Hunter
eb95c5cd2e
update renew logic to work better with cameras responding with invalid termination times by extending the duration (#36393) 2020-06-03 09:51:57 -06:00
Jason Hunter
b0012bd5a6
guard against missing topic (#36108) 2020-05-25 13:37:47 +02:00
Jason Hunter
bd8848e57a
Fix ONVIF config entry unique ID (#36008)
* fallback to device serial number if no mac available

* make password optional to fix #35904

* update tests to reflect new flow

* fix snake case and AsyncMock

* add comments around why weird things are being done
2020-05-24 21:50:50 +02:00
Jason Hunter
0e83cfade1
Fix ONVIF Transport (#35932)
* allow lib to create AsyncTransport

* fix transport close issue
2020-05-22 19:46:11 -04:00
Jason Hunter
aeae4edb74
Fix ONVIF subscription renewal (#35792)
* fix subscription renewal

* catch ValueError for #35762
2020-05-18 23:02:23 -04:00
Jason Hunter
b7ab07c987
additional log info and strings fix (#35622) 2020-05-14 11:25:58 -04:00
Jason Hunter
132bb4e890
ONVIF Event Implementation (#35406)
Initial implementation of ONVIF event sensors
2020-05-11 13:12:12 -04:00