Commit graph

398 commits

Author SHA1 Message Date
J. Nick Koston
c8c1466c06
Fix duplicate ONVIF sensors (#92629)
Some cameras do not configure the video source correctly
when using webhooks but work fine with PullPoint which
results in duplicate sensors
2023-05-05 14:32:55 -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
41515249a0
Fix onvif cameras with invalid encodings in device info (#92450)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2023-05-04 06:48:13 -05:00
J. Nick Koston
322c5152be
Fix onvif setup when time set service is not functional (#92447) 2023-05-04 11:50:12 +02:00
J. Nick Koston
20942ab26f
Handle webhook URL rejection in onvif (#92405) 2023-05-03 15:46:53 +02:00
J. Nick Koston
a9d992c2de
Add support for visitor detections to onvif (#92350) 2023-05-02 12:19:27 +02:00
J. Nick Koston
c0fa078b0b
Start onvif events later (#92354) 2023-05-02 12:17:01 +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
30dd8b9f3a
Retry onvif setup when it is unexpectedly cancelled (#92313)
* Retry onvif setup when it is unexpectedly cancelled

fixes #92308

* Retry onvif setup when it is unexpectedly cancelled

fixes #92308
2023-04-30 23:12:01 -04:00
J. Nick Koston
4fcf05c202
Ensure onvif webhook can be registered (#92295) 2023-04-30 18:06:38 +02:00
J. Nick Koston
193b2694a9
Handle AttributeError from wrong port in ONVIF config flow (#92272)
* Handle AttributeError from wrong port in ONVIF config flow

fixes
```
2023-04-29 19:17:22.289 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/Users/bdraco/home-assistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
  File "/Users/bdraco/home-assistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/Users/bdraco/home-assistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/Users/bdraco/home-assistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/Users/bdraco/home-assistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
  File "/Users/bdraco/home-assistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/Users/bdraco/home-assistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/Users/bdraco/home-assistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/Users/bdraco/home-assistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/Users/bdraco/home-assistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
  File "/Users/bdraco/home-assistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/Users/bdraco/home-assistant/homeassistant/components/onvif/config_flow.py", line 233, in async_step_configure
    errors, description_placeholders = await self.async_setup_profiles()
  File "/Users/bdraco/home-assistant/homeassistant/components/onvif/config_flow.py", line 277, in async_setup_profiles
    await device.update_xaddrs()
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/onvif/client.py", line 433, in update_xaddrs
    capabilities = await devicemgmt.GetCapabilities({"Category": "All"})
  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 164, in send_async
    return self.process_reply(client, operation_obj, response)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/zeep/wsdl/bindings/soap.py", line 204, in process_reply
    doc = parse_xml(content, self.transport, settings=client.settings)
  File "/Users/bdraco/home-assistant/venv/lib/python3.10/site-packages/zeep/loader.py", line 51, in parse_xml
    docinfo = elementtree.getroottree().docinfo
AttributeError: NoneType object has no attribute getroottree
```

* port

* Revert "port"

This reverts commit 4693f3f33a.

* misfire
2023-04-29 21:17:56 -04:00
J. Nick Koston
b0b4134ded
Handle onvif errors when detail is returned as bytes (#92259) 2023-04-29 21:33:25 +02:00
J. Nick Koston
2354f8194e
Add reauth to onvif (#91957)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-04-25 12:20:17 -05:00
J. Nick Koston
c3262ebdb3
Add rule parser for onvif LineDetector and CountAggregation (#91885) 2023-04-24 15:23:59 +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
392a9f32c9
Add fallback to device zone time or no timezone to onvif when setting time fails (#91882) 2023-04-24 14:37:56 +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
6c024405a6
Ensure onvif can still be unloaded if camera fails to unsubscribe (#91887) 2023-04-24 14:13:04 +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
14d2645de2
Avoid creating onvif switches on unsupported devices (#91907)
* Avoid creating onvif switches on unsupported devices

fixes #89064

* cover
2023-04-23 20:56:43 -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
Marc Mueller
06520217bc
Update pylint to 2.17.2 (#91894) 2023-04-23 14:46:48 +02:00
J. Nick Koston
82340907c2
Ensure onvif retries setup if camera fails to respond correctly (#91866) 2023-04-23 01:27:54 +02:00
J. Nick Koston
942a955a77
Handle 404 for media/ptz/image onvif services to allow setup to proceed (#91875) 2023-04-23 01:16:37 +02: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
J. Nick Koston
9be9defbb8
Add more rule parsers to onvif (#91533) 2023-04-17 13:41:15 +02:00
J. Nick Koston
7f7909e0d1
Add dhcp ip update support to onvif (#91474)
* Add dhcp ip update support to onvif

If we know the mac address of the camera we can
update the config entry when the ip changes

* fix lookup

* coverage

* remove unreachable

* remove unreachable

* remove unreachable
2023-04-16 15:55:33 -04:00
J. Nick Koston
cb6ffa5b03
Handle a few more transient onvif errors (#91473) 2023-04-16 14:06:30 +02:00
J. Nick Koston
e7373d979b
Fix onvif failing to reload (#91482) 2023-04-16 14:05:10 +02:00
J. Nick Koston
24538a44fc
Bump onvif-zeep-async to 1.2.11 (#91472) 2023-04-16 13:56:10 +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
025e1792db
Bump onvif-zeep-async to 1.2.5 (#91399) 2023-04-14 08:37:12 +02:00
J. Nick Koston
4f05246654
Bump onvif-zeep-async to 1.2.3 (#90382) 2023-03-28 13:54:33 -10: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
J. Nick Koston
fd460996ba
Bump onvif-zeep-async to 1.2.2 to fix memory leak (#90216) 2023-03-25 09:21:05 -10:00
Erik Montnemery
cc564026fa
Move EntityCategory to homeassistant.const (#87792)
* Move EntityCategory to homeassistant.const

* Fix more imports
2023-02-09 20:15:37 +01:00
Erik Montnemery
1450b44c63
Sort manifests 7 (#87028) 2023-02-08 20:32:43 +01:00
Franck Nijhof
939eef3b28
Remove translations from Core (#87543)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-02-06 15:06:43 +01:00
epenet
bb3e0633a4
Add init return type to integrations (#87523)
Add type hints to integrations
2023-02-06 11:37:25 +01:00
epenet
810367b757
Fix can not typo (#87254) 2023-02-03 11:37:16 +01:00
epenet
9327947332
Improve type hints in onvif (#87184) 2023-02-02 16:25:43 -05:00
Franck Nijhof
5e81d28116
Update black to 23.1.0 (#87188) 2023-02-02 18:35:24 +01:00
epenet
bd6a4d10ea
Use try_parse_enum in integrations (#87085) 2023-02-02 12:34:01 +01:00
Nick Touran
d2e75e4f7a
Add Autofocus, IR lamp, and Wiper switches in ONVIF (#84317)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-01-30 12:08:07 +01:00
Franck Nijhof
c56832bb2c
Enable Ruff SIM300 (#86793) 2023-01-30 11:03:23 +01:00
Marc Mueller
60b799aac9
Misc typing improvements (#86550) 2023-01-25 11:05:36 +01:00
GitHub Action
d1ecc418bb [ci skip] Translation update 2023-01-19 00:25:04 +00:00