Compare commits

...

312 Commits

Author SHA1 Message Date
Paulus Schoutsen e0a97ec90d 2023.5.3 (#93066) 2023-05-14 13:00:18 -04:00
Paulus Schoutsen 1f6a601fc9 Bumped version to 2023.5.3 2023-05-14 12:11:32 -04:00
Aaron Bach ff14277805 Fix a series of bugs due to Notion API changes (#93039)
* Fix a series of bugs due to Notion API changes

* Simplify

* Reduce blast radius

* Reduce blast radius

* Fix tests
2023-05-14 12:11:22 -04:00
J. Nick Koston 6424dee231 Fix sslv2/sslv3 with unverified connections (#93037)
In #90191 we use the same ssl context for httpx now to avoid
a memory leak, but httpx previously allowed sslv2/sslv3 for
unverified connections

This reverts to the behavior before #90191
2023-05-14 12:11:21 -04:00
J. Nick Koston 13c51e9c34 Disable cleanup_closed for aiohttp.TCPConnector with cpython 3.11.1+ (#93013)
* Disable cleanup_closed for aiohttp.TCPConnector with cpython 3.11.2+

There is currently a relatively fast memory leak when using
cpython 3.11.2+ and cleanup_closed with aiohttp

For my production instance it was leaking ~450MiB per day
of `MemoryBIO`, `SSLProtocol`, `SSLObject`, `_SSLProtocolTransport`
`memoryview`, and `managedbuffer` objects

see https://github.com/aio-libs/aiohttp/issues/7252
see https://github.com/python/cpython/pull/98540

* Update homeassistant/helpers/aiohttp_client.py
2023-05-14 12:11:20 -04:00
puddly 304c34a119 Bump bellows to 0.35.5 to fix Aqara Zigbee connectivity issue (#92999)
Bump bellows to 0.35.5
2023-05-14 12:11:19 -04:00
starkillerOG d840d27f2d Bump reolink-aio to 0.5.15 (#92979) 2023-05-14 12:11:18 -04:00
Michael a8cf3fadaa Fix remove of device when surveillance station is not used in Synology DSM (#92957) 2023-05-14 12:11:17 -04:00
Joost Lekkerkerker a3f3b43c20 Bump python-vehicle to 1.0.1 (#92933) 2023-05-14 12:11:17 -04:00
Robert Hillis b0520ccb94 Bump eternalegypt to 0.0.16 (#92919) 2023-05-14 12:11:16 -04:00
Jonathan Keslin fe308e26dc Bump volvooncall to 0.10.3 to fix sensor type error (#92913) 2023-05-14 12:11:15 -04:00
Michael 60fb71159d Fix uptime sensor deviation detection in Fritz!Tools (#92907) 2023-05-14 12:11:14 -04:00
G Johansson 413dbe89e5 Fix already_configured string in workday (#92901)
* Fix already_configured string in workday

* Fix strings
2023-05-14 12:11:13 -04:00
J. Nick Koston 7abe9f1f9a Bump bluetooth-auto-recovery to 1.2.0 (#92893) 2023-05-14 12:11:12 -04:00
Glenn Waters 252b99f00b Bump UPB integration library to 0.5.4 (#92879) 2023-05-14 12:11:11 -04:00
J. Nick Koston 8e407334b7 Add ONVIF services to diagnostics (#92878) 2023-05-14 12:11:10 -04:00
puddly 91faa31e8c Bump ZHA dependencies (#92870) 2023-05-14 12:11:09 -04:00
Michael Hansen 5e77de35bd Allow "no" to match "nb" in language util (#92862)
* Allow "no" to match "nb"

* Adjust comparison for speed
2023-05-14 12:11:09 -04:00
jjlawren c1b18dcbba Bump sonos-websocket to 0.1.1 (#92834) 2023-05-14 12:11:08 -04:00
Diogo Gomes 3c45bda0e8 Don't try to restore unavailable nor unknown states (#92825) 2023-05-14 12:11:07 -04:00
Álvaro Fernández Rojas 7361c29cba Update aioairzone to v0.5.5 (#92812) 2023-05-14 12:11:06 -04:00
Álvaro Fernández Rojas a551de06c7 Fix Airzone Auto operation mode (#92796) 2023-05-14 12:11:05 -04:00
Erik Montnemery 84ce2f13f2 Fix race in Alexa async_enable_proactive_mode (#92785) 2023-05-14 12:11:04 -04:00
Álvaro Fernández Rojas 5c949bd862 Update aioairzone to v0.5.3 (#92780) 2023-05-14 12:11:03 -04:00
Keilin Bickar 16020d8ab9 Bump asyncsleepiq to 1.3.5 (#92759) 2023-05-14 12:11:02 -04:00
karwosts f866d6100d Fix zwave_js services example data (#92748) 2023-05-14 12:11:01 -04:00
Brandon Rothweiler 8d0da78fab Increase timeout to 30 seconds for Mazda integration (#92744) 2023-05-14 12:11:00 -04:00
J. Nick Koston 7173a4f377 Bump aioesphomeapi to 3.7.4 to fix proxied BLE connections not retrying right away on error (#92741) 2023-05-14 12:11:00 -04:00
Eduard van Valkenburg d4acb2a381 Update deprecated functions in SIA (#92737)
update deprecated functions
2023-05-14 12:10:59 -04:00
Shay Levy b1111eb2c7 Bump aiowebostv to 0.3.3 to fix Python 3.11 support (#92736)
Bump aiowebostv to 0.3.3
2023-05-14 12:10:58 -04:00
Mick Vleeshouwer 4895ca218f Bump pyoverkiz to 1.7.8 (#92702) 2023-05-14 12:10:57 -04:00
Aaron Bach 91e9d21548 Bump aionotion to 2023.05.1 (#92697) 2023-05-14 12:10:56 -04:00
J. Nick Koston 996c6c4a92 Fix onvif reauth when device returns a http 401/403 error (#92690) 2023-05-14 12:10:55 -04:00
J. Nick Koston 96ff24aa2f Always request at least one zone for multi-zone LIFX devices (#92683) 2023-05-14 12:08:33 -04:00
J. Nick Koston dcc5940f9b Fix parallel_updates being acquired too late for entity executor jobs (#92681)
* Fix parallel_updates being acquired too late for entity executor jobs

* tweak
2023-05-14 12:08:33 -04:00
rikroe dd51bba677 Bump bimmer_connected to 0.13.3 (#92648)
Co-authored-by: rikroe <rikroe@users.noreply.github.com>
2023-05-14 12:08:32 -04:00
Luke ac9da5c167 Roborock continue on failed mqtt disconnect (#92502)
continue on async disconnect failure
2023-05-14 12:08:31 -04:00
Paulus Schoutsen e904edb12e 2023.5.2 (#92610) 2023-05-05 15:23:51 -04:00
J. Nick Koston ddebfb3ac5 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:41:00 -04:00
J. Nick Koston fe57901b5f Add support for visitor detections to onvif (#92350) 2023-05-05 14:40:59 -04:00
J. Nick Koston 73d4c73dbb 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:39:32 -04:00
Bram Kragten f1bccef224 Update frontend to 20230503.3 (#92617) 2023-05-05 14:39:31 -04:00
Joost Lekkerkerker cf243fbe11 Lower scan interval for OpenSky (#92593)
* Lower scan interval for opensky to avoid hitting rate limit

* Lower scan interval for opensky to avoid hitting rate limit

* Update homeassistant/components/opensky/sensor.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Update homeassistant/components/opensky/sensor.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2023-05-05 14:39:30 -04:00
J. Nick Koston 35c48d3d0e 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:39:29 -04:00
Paulus Schoutsen 15ef53cd9a Bumped version to 2023.5.2 2023-05-05 08:47:12 -04:00
Erik Montnemery fb29e1a14e Bump hatasmota to 0.6.5 (#92585)
* Bump hatasmota to 0.6.5

* Fix tests
2023-05-05 08:47:08 -04:00
epenet f8c3586f6b Fix hassio get_os_info retry (#92569) 2023-05-05 08:47:07 -04:00
Paulus Schoutsen e8808b5fe7 Re-run expose entities migration if first time failed (#92564)
* Re-run expose entities migration if first time failed

* Count number of exposed entities

* Add tests

---------

Co-authored-by: Erik <erik@montnemery.com>
2023-05-05 08:47:06 -04:00
J. Nick Koston 82c0967716 Bump elkm1-lib to 2.2.2 (#92560)
changelog: https://github.com/gwww/elkm1/compare/2.2.1...2.2.2

fixes #92467
2023-05-05 08:47:05 -04:00
J. Nick Koston 163823d2a5 Allow duplicate state updates when force_update is set on an esphome sensor (#92553)
* Allow duplicate states when force_update is set on an esphome sensor

fixes #91221

* Update homeassistant/components/esphome/entry_data.py

Co-authored-by: pdw-mb <pdw@mythic-beasts.com>

---------

Co-authored-by: pdw-mb <pdw@mythic-beasts.com>
2023-05-05 08:47:04 -04:00
puddly 2dd1ce2047 Handle invalid ZHA cluster handlers (#92543)
* Do not crash on startup when an invalid cluster handler is encountered

* Add a unit test
2023-05-05 08:47:03 -04:00
J. Nick Koston 241cacde62 Bump aioesphomeapi to 13.7.3 to fix disconnecting while handshake is in progress (#92537)
Bump aioesphomeapi to 13.7.3

fixes #92432
2023-05-05 08:47:02 -04:00
Erik Montnemery 8a11ee81c4 Improve cloud migration (#92520)
* Improve cloud migration

* Tweak

* Use entity_ids func

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2023-05-05 08:47:01 -04:00
J. Nick Koston e3762724a3 Fix blocking I/O in the event loop when starting ONVIF (#92518) 2023-05-05 08:47:00 -04:00
karwosts b973825833 Fix scene service examples (#92501) 2023-05-05 08:46:59 -04:00
Eduard van Valkenburg b2fcbbe50e Fix for SIA Code not being handled well (#92469)
* updated sia requirements

* updates because of changes in package

* linting and other small fixes

* fix for unknown code

* added same to alarm_control_panel
2023-05-05 08:46:58 -04:00
Francesco Carnielli d96b37a004 Fix power sensor state_class in Netatmo integration (#92468) 2023-05-05 08:46:57 -04:00
DDanii affece8857 Fix transmission error handling (#91548)
* transmission error handle fix

* added unexpected case tests
2023-05-05 08:46:56 -04:00
Paulus Schoutsen bce18bf61a 2023.5.1 (#92513) 2023-05-04 12:45:55 -04:00
Paulus Schoutsen eda0731e60 Bumped version to 2023.5.1 2023-05-04 10:23:58 -04:00
Bram Kragten 238c87055f Update frontend to 20230503.2 (#92508) 2023-05-04 10:23:53 -04:00
Erik Montnemery 4b4464a3de Force migration of cloud settings to exposed_entities (#92499) 2023-05-04 10:23:52 -04:00
J. Nick Koston a07fbdd61c Bump bluetooth-auto-recovery 1.1.2 (#92495)
Improve handling when getting the power state times out

https://github.com/Bluetooth-Devices/bluetooth-auto-recovery/compare/v1.1.1...v1.1.2
2023-05-04 10:23:52 -04:00
J. Nick Koston 3126ebe9d6 Fix lifx light strips when color zones are not initially populated (#92487)
fixes #92456
2023-05-04 10:23:51 -04:00
Aaron Bach 89aec9d356 Bump aionotion to 2023.05.0 (#92451) 2023-05-04 10:23:49 -04:00
J. Nick Koston 0cfa566ff6 Fix onvif cameras with invalid encodings in device info (#92450)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2023-05-04 10:23:49 -04:00
J. Nick Koston fffece95f5 Fix onvif setup when time set service is not functional (#92447) 2023-05-04 10:23:48 -04:00
Franck Nijhof c61e29709c 2023.5.0 (#92422) 2023-05-03 20:46:28 +02:00
Michael Hansen 458fe17a48 Bump voip-utils to 0.0.7 (#92372) 2023-05-03 20:02:45 +02:00
Franck Nijhof 15fdefd23b Bumped version to 2023.5.0 2023-05-03 19:44:53 +02:00
Michael Hansen 576f9600b5 Pass OPUS payload ID through VoIP (#92421) 2023-05-03 19:44:34 +02:00
Franck Nijhof 7a62574360 Bumped version to 2023.5.0b9 2023-05-03 18:59:42 +02:00
Erik Montnemery 0251d677d8 Migrate cloud settings for all Google entities (#92416) 2023-05-03 18:59:32 +02:00
Michael Hansen 2cd9b94ecb Skip unexposed entities in intent handlers (#92415)
* Filter intent handler entities by exposure

* Add test for skipping unexposed entities
2023-05-03 18:59:29 +02:00
Erik Montnemery 3cd2ab2319 Migrate cloud settings for all Alexa entities (#92413)
* Migrate cloud settings for all Alexa entities

* Also set settings for unknown entities
2023-05-03 18:59:25 +02:00
J. Nick Koston 4f0d403393 Bump bluetooth-auto-recovery to 1.1.1 (#92412)
* Bump bluetooth-auto-recovery to 1.1.0

https://github.com/Bluetooth-Devices/bluetooth-auto-recovery/releases/tag/v1.1.0

In https://github.com/home-assistant/operating-system/issues/2485 is was discovered that a more aggressive reset strategy is needed due to a yet unsolved bug in the linux 6.1.x kernel series

* bump to 1.1.1 since event 47 cannot be decoded (newer kernels only)
2023-05-03 18:59:22 +02:00
Bram Kragten b558cf8b59 Update frontend to 20230503.1 (#92410) 2023-05-03 18:59:18 +02:00
Erik Montnemery 820c7b77ce Update cloud WS API for getting entity (#92409)
* Update cloud WS API for getting entity

* Adjust comment
2023-05-03 18:59:15 +02:00
Erik Montnemery 9d0fc916fc Use exposed_entities API in cloud tests (#92408) 2023-05-03 18:59:11 +02:00
Erik Montnemery 387f07a97f Include all entities in cloud lists (#92406) 2023-05-03 18:59:08 +02:00
J. Nick Koston 44968cfc7c Handle webhook URL rejection in onvif (#92405) 2023-05-03 18:59:04 +02:00
Erik Montnemery c6751bed86 Allow setting google disable 2fa flag on any entity (#92403)
* Allow setting google disable 2fa flag on any entity

* Fix test

* Include disable_2fa flag in cloud/google_assistant/entities/get
2023-05-03 18:59:01 +02:00
Bram Kragten b87e3860d9 Update frontend to 20230503.0 (#92402) 2023-05-03 18:58:57 +02:00
David F. Mulcahey 8ef6bd85f5 Bump ZHA quirks (#92400) 2023-05-03 18:58:54 +02:00
Erik Montnemery ad4fed4f60 Allow exposing any entity to the default conversation agent (#92398)
* Allow exposing any entity to the default conversation agent

* Tweak

* Fix race, update tests

* Update tests
2023-05-03 18:58:51 +02:00
Erik Montnemery 1050895657 Don't use storage collection helper in ExposedEntities (#92396)
* Don't use storage collection helper in ExposedEntities

* Fix tests
2023-05-03 18:58:47 +02:00
Erik Montnemery c31d657206 Improve exposed entities tests (#92389) 2023-05-03 18:58:44 +02:00
repaxan 88343bed77 Add ZHA binding for window coverings (#92387) 2023-05-03 18:58:40 +02:00
Artem Draft 51a10a84da Bump pybravia to 0.3.3 (#92378) 2023-05-03 18:58:35 +02:00
Paulus Schoutsen 5f3bbf2804 Bumped version to 2023.5.0b8 2023-05-02 22:39:38 -04:00
Paulus Schoutsen b8eebf085c Fix deserialize bug + add test coverage (#92382) 2023-05-02 22:39:33 -04:00
Franck Nijhof cdfd53e1cc Bumped version to 2023.5.0b7 2023-05-02 22:44:32 +02:00
Bram Kragten ca147dd97e Update frontend to 20230502.0 (#92373) 2023-05-02 22:43:23 +02:00
Erik Montnemery 5b1278d885 Allow exposing entities not in the entity registry to assistants (#92363) 2023-05-02 22:43:19 +02:00
J. Nick Koston 0db28dcf4d Start onvif events later (#92354) 2023-05-02 22:43:15 +02:00
Raman Gupta 7c651665c5 Clean up zwave_js.cover (#92353) 2023-05-02 22:43:12 +02:00
J. Nick Koston 2f3964e3ce Bump ulid-transform to 0.7.2 (#92344) 2023-05-02 22:43:08 +02:00
John Pettitt eef95fa0d4 Increase default timeout in sense (#90556)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-05-02 22:43:03 +02:00
Franck Nijhof 43a1eb043b Bumped version to 2023.5.0b6 2023-05-01 22:55:49 +02:00
Bram Kragten 6b77775ed5 Update frontend to 20230501.0 (#92339) 2023-05-01 22:55:34 +02:00
Michael Hansen 7077d23127 Bump voip-utils to 0.0.6 (#92334) 2023-05-01 22:55:31 +02:00
J. Nick Koston c7eac0ebbb Avoid starting ONVIF PullPoint if the camera reports its unsupported (#92333) 2023-05-01 22:55:27 +02:00
David F. Mulcahey 7f13033f69 Don't poll ZHA electrical measurement sensors unnecessarily (#92330) 2023-05-01 22:55:23 +02:00
Paulus Schoutsen eba201e71b Add voip configuration url (#92326) 2023-05-01 22:55:20 +02:00
G Johansson 1e9d777201 Fix db_url issue in SQL (#92324)
* db_url fix

* Add test

* assert entry.options
2023-05-01 22:55:16 +02:00
J. Nick Koston 030b7f8a37 Bump sqlalchemy to 2.0.12 (#92315)
changelog: https://docs.sqlalchemy.org/en/20/changelog/changelog_20.html#change-2.0.12
2023-05-01 22:55:12 +02:00
J. Nick Koston 8cbc69fc92 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-05-01 22:55:08 +02:00
J. Nick Koston 2a5f5ea039 Reduce size of migration transactions to accommodate slow/busy systems (#92312)
* Reduce size of migration transactions to accommodate slow/busy systems

related issue #91489

* handle overloaded RPIs better
2023-05-01 22:55:04 +02:00
Michael Hansen 0ba662e7bc Allow configuring SIP port in VoIP (#92210)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-05-01 22:54:59 +02:00
Franck Nijhof 05530d656a Bumped version to 2023.5.0b5 2023-04-30 20:16:39 +02:00
Jan Bouwhuis 2b2be6a333 Fix mqtt not available when starting snips (#92296) 2023-04-30 20:16:28 +02:00
J. Nick Koston 5bd54490ea Ensure onvif webhook can be registered (#92295) 2023-04-30 20:16:25 +02:00
J. Nick Koston 00a28caa6d Bump bleak to 0.20.2 (#92294) 2023-04-30 20:16:21 +02:00
J. Nick Koston c4aa6ba262 Bump beacontools to fix conflict with construct<2.10 and >=2.8.16 (#92293) 2023-04-30 20:16:18 +02:00
J. Nick Koston 7a90db903b Prevent pysnmp from being installed as it does not work with newer python (#92292) 2023-04-30 20:16:14 +02:00
Robert Hillis fe279c8593 Add missing fstrings in Local Calendar (#92288) 2023-04-30 20:16:10 +02:00
Maximilian ddf5a9fbcc Bump pynina to 0.3.0 (#92286) 2023-04-30 20:16:07 +02:00
J. Nick Koston 093d5d6176 Fix august lock state when API reports locking and locked with the same timestamp (#92276) 2023-04-30 20:16:01 +02:00
Paulus Schoutsen eb586c7144 Bumped version to 2023.5.0b4 2023-04-29 21:23:22 -04:00
J. Nick Koston ec15a03706 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:23:16 -04:00
J. Nick Koston 24b851c184 Auto repair incorrect collation on MySQL schema (#92270)
* Auto repair incorrect collation on MySQL schema

As we do more union queries in 2023.5.x if there is a mismatch
between collations on tables, they will fail with an error
that is hard for the user to figure out how to fix

`Error executing query: (MySQLdb.OperationalError) (1271, "Illegal mix of collations for operation UNION")`

This was reported in the #beta channel and by PM from others
so the problem is not isolated to a single user

https://discord.com/channels/330944238910963714/427516175237382144/1100908739910963272

* test with ascii since older maraidb versions may not work otherwise

* Revert "test with ascii since older maraidb versions may not work otherwise"

This reverts commit 787fda1aefcd8418a28a8a8f430e7e7232218ef8.t

* older version need to check collation_server because the collation is not reflected if its the default
2023-04-29 21:23:15 -04:00
Michael a8539b89e8 Fix call deflection update in Fritz!Tools (#92267)
fix
2023-04-29 21:23:14 -04:00
Jan Bouwhuis 8cf1ed81a8 Fix MQTT certificate files setup (#92266) 2023-04-29 21:23:13 -04:00
Robert Hillis fe452452e6 Fix Google Mail Sensor key error (#92262)
Fix Google Mail key error
2023-04-29 21:23:13 -04:00
Michael Hansen c632d27197 Add VoIP error tone (#92260)
* Play error tone when pipeline error occurs

* Play listening tone at the start of each cycle
2023-04-29 21:23:12 -04:00
J. Nick Koston 6a6eba1ca3 Handle onvif errors when detail is returned as bytes (#92259) 2023-04-29 21:23:11 -04:00
J. Nick Koston a5241b3118 Pin pyasn1 and pysnmplib since pyasn1 0.5.0 has breaking changes and pysnmp-pyasn1 and pyasn1 are both using the pyasn1 namespace (#92254) 2023-04-29 21:23:10 -04:00
Franck Nijhof 3bab40753d Bumped version to 2023.5.0b3 2023-04-29 19:03:08 +02:00
J. Nick Koston 546c68196e Bump pyunifiprotect to 4.8.3 (#92251) 2023-04-29 19:02:59 +02:00
Bouwe Westerdijk 379db033af Bump plugwise to v0.31.1 (#92249) 2023-04-29 19:02:55 +02:00
Franck Nijhof 4b9355e1ca Fix unknown/unavailable source sensor in Filter entities (#92241) 2023-04-29 19:02:52 +02:00
Franck Nijhof 89eca22b93 Fix history YAML deprecation (#92238) 2023-04-29 19:02:48 +02:00
Allen Porter 2cb665a1d9 Add more detail to invalid rrule calendar error message (#92222)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-04-29 19:02:45 +02:00
Michael Davie 1d54a0ed3d Bump env_canada to 0.5.34 (#92216)
Bump env_canada to v.0.5.34
2023-04-29 19:02:41 +02:00
jjlawren 7af1521812 Bump sonos-websocket to 0.1.0 (#92209)
Bump sonos-websocket to 0.1.0
2023-04-29 19:02:38 +02:00
Tom Harris c8cc6bfbb7 Fix Insteon scenes with disabled entities (#92137) 2023-04-29 19:02:34 +02:00
Rajeevan 401e61588c Fix solaredge-local protobuf exception (#92090) 2023-04-29 19:02:31 +02:00
Michael 3f948da2af Turn AVM FRITZ!Box Tools call deflection switches into coordinator entities (#91913)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2023-04-29 19:02:27 +02:00
Mick Vleeshouwer aafbc64e02 Revert "Add silent option for DynamicShutter (ogp:Shutter) in Overkiz" (#91354) 2023-04-29 19:02:24 +02:00
rikroe e460bc7ecb Move BMW Target SoC to number platform (#91081)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: rikroe <rikroe@users.noreply.github.com>
2023-04-29 19:02:19 +02:00
Franck Nijhof 1b39abe3bc Bumped version to 2023.5.0b2 2023-04-28 21:42:27 +02:00
J. Nick Koston 29bff59707 Fix missing preset_mode feature in bond fans (#92202) 2023-04-28 21:42:18 +02:00
Jean-François Roy faa8f38fa8 Add missing PRESET_MODE feature to BAF fans (#92200) 2023-04-28 21:42:15 +02:00
Paul Bottein 1f6dbe96f6 Update frontend to 20230428.0 (#92190) 2023-04-28 21:42:12 +02:00
Jan Bouwhuis 98075da069 Fix mqtt subscribe debouncer initial delay too long when birth message is disabled (#92188)
Fix mqtt subscribe deboucer initial delay
2023-04-28 21:42:08 +02:00
David F. Mulcahey 652bb8ef95 Fix ZHA device triggers (#92186)
* Fix missing endpoint data on ZHA events

* revert to flat structure

* update test
2023-04-28 21:42:05 +02:00
Nolan Gilley 96d2b53798 Upgrade lakeside to 0.13 (#92173) 2023-04-28 21:42:01 +02:00
Raman Gupta 25d621ab94 Bump pyvizio to 0.1.61 (#92161) 2023-04-28 21:41:58 +02:00
Erik Montnemery fa3f19e7bf Keep expose setting in sync for assist (#92158)
* Keep expose setting in sync for assist

* Fix initialization, add test

* Fix tests

* Add AgentManager.async_setup

* Fix typo

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-04-28 21:41:53 +02:00
jjlawren 412ea937ff Properly resolve media_source URLs for Sonos announcements (#92154)
Properly resolve media_source URLs for Sonos announcements
2023-04-28 21:41:46 +02:00
Luke b7f5c144a8 Bump Roborock to 0.8.3 (#92151) 2023-04-28 21:41:42 +02:00
J. Nick Koston 658128c892 Fix ignored apple tvs being scanned over and over (#92150) 2023-04-28 21:41:38 +02:00
J. Nick Koston ff2f6029ce Ensure purge can cleanup old format detached states in the database (#92145) 2023-04-28 21:41:35 +02:00
puddly 8017a04efe Fix ZHA startup failure with the Konke button (#92144)
* Ensure devices with bad cluster subclasses do not prevent startup

* Explicitly unit test an affected SML001 device

* Do not use invalid `hue_occupancy` attribute name

* Actually remove `hue_occupancy`

* Bump ZHA dependencies
2023-04-28 21:41:31 +02:00
G Johansson ef350949fd Fix options flow Workday (#92140)
* Fix options flow workday

* simpler
2023-04-28 21:41:26 +02:00
Luke 7b1b3970b1 Bump roborock to 0.8.1 for beta fixes (#92131)
* bump to 0.8.1

* add tests for new config flow errors

* removed logs for known errors
2023-04-28 21:40:35 +02:00
Franck Nijhof e03f3c05b3 Bumped version to 2023.5.0b1 2023-04-27 19:59:11 +02:00
Franck Nijhof 3e8e2c68b9 Add add-on discovery URL and title to Wyoming integration (#92129) 2023-04-27 19:58:56 +02:00
J. Nick Koston 54e52182ab Bump sqlalchemy to 2.0.11 to fix a critical regression with postgresql (#92126) 2023-04-27 19:58:53 +02:00
Paul Bottein c35872531f Update frontend to 20230427.0 (#92123) 2023-04-27 19:58:49 +02:00
Erik Montnemery 7d5c90a81e Add WS command cloud/alexa/entities/get (#92121)
* Add WS command cloud/alexa/entities/get

* Fix bugs, add test
2023-04-27 19:58:46 +02:00
Thijs W 1f52b71477 Fix frontier_silicon not retrying setup and missing strings (#92111)
Address late review comments for frontier_silicon config flow
2023-04-27 19:58:43 +02:00
Erik Montnemery 9a7f7ef35c Avoid exposing unsupported entities to Alexa (#92107)
* Avoid exposing unsupported entities to Alexa

* Update homeassistant/components/cloud/alexa_config.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2023-04-27 19:58:39 +02:00
Erik Montnemery a41128dae3 Avoid exposing unsupported entities to Google Assistant (#92105)
* Avoid exposing unsupported entities to Google Assistant

* Add Google Assistant specific support sets

* Add test
2023-04-27 19:58:36 +02:00
Raman Gupta 5c3094520d Fix vizio integration_type (#92103) 2023-04-27 19:58:32 +02:00
Paulus Schoutsen 8db1d13c71 Use pipeline ID in event (#92100)
* Use pipeline ID in event

* Fix tests
2023-04-27 19:58:28 +02:00
Paulus Schoutsen 47c6cb88a4 Fix capitalization names Assist entities (#92098)
* Fix capitalization names Assist entities

* Adjust names to be 'in progress'

* Update tests/components/esphome/test_binary_sensor.py

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

---------

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-04-27 19:58:25 +02:00
Michael a1d4740785 Fix reconfigure by SSDP or Zeroconf discovery in Synology DSM (#92088) 2023-04-27 19:58:22 +02:00
Franck Nijhof b3d685cc31 Update YARL to 1.9.2 (#92086) 2023-04-27 19:58:19 +02:00
avee87 019f26a17c Remove name attribute from transmission services manifest (#92083) 2023-04-27 19:58:15 +02:00
puddly 9970af5fe9 Add a channel changing API to ZHA (#92076)
* Expose channel changing over the websocket API

* Expose channel changing as a service

* Type annotate some existing unit test fixtures

* Add unit tests

* Rename `api.change_channel` to `api.async_change_channel`

* Expand on channel migration in the service description

* Remove channel changing service, we only really need the websocket API

* Update homeassistant/components/zha/websocket_api.py

* Black

---------

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2023-04-27 19:58:12 +02:00
Michael Hansen f7e72ef62b Bump intents to 2023.4.26 (#92070)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-04-27 19:58:08 +02:00
Jesse Hills a445e29bca ESPHome voice assistant: Version 2 - Stream raw tts audio back to device for playback (#92052)
* Send raw audio back

* Update tests

* More tests

* Fix docstrings and remove unused patches

* More tests

* MORE

* Only set raw for v2
2023-04-27 19:58:04 +02:00
Jesse Hills ba69e29e8f Set pipeline_id from pipeline select (#92085) 2023-04-27 19:57:23 +02:00
Franck Nijhof 45d826c941 Bumped version to 2023.5.0b0 2023-04-26 21:56:02 +02:00
Franck Nijhof 583453f327 Merge branch 'master' into dev 2023-04-26 21:53:40 +02:00
Arturo 75be1b4ff9 Remove bridged matter devices when matter bridge is removed (#91995)
* Removes bridged matter devices when matter bridge is removed

* Didn't have the fetch the config entry since that is already provided to us

* Switched to a safer method of removing the child devices
2023-04-26 21:44:40 +02:00
puddly 2bbebeb925 Add a warning step to ZHA's config flow to advise against some radios (#92078) 2023-04-26 21:40:46 +02:00
puddly 4f660cc5f5 Allow the ZHA default light transition time to be configured as a float (#92075) 2023-04-26 21:24:06 +02:00
Marcel van der Veldt 3c44c7416f Fix Matter cover deviceclass and inverted position (#92063) 2023-04-26 21:21:31 +02:00
Bram Kragten e7e50243d1 Update frontend to 20230426.0 (#92074) 2023-04-26 21:19:06 +02:00
Franck Nijhof b6a3ffb20f Revert "Fail TTS tests if default TTS cache dir exists (#92023)" (#92079) 2023-04-26 21:18:17 +02:00
Jan Bouwhuis 5a78684998 Fix large imap_content event warning by truncating the email text body to 2 KiB (#92066) 2023-04-26 18:44:22 +02:00
J. Nick Koston ead761dfa2 Ensure device_automation can handle RequirementsNotFound (#92037) 2023-04-26 18:43:38 +02:00
Erik Montnemery 330a7afdfc Teach switch_as_x about exposed entities (#92059) 2023-04-26 18:42:49 +02:00
J. Nick Koston ec5f50913a Retry creating esphome update entities later if dashboard is unavailable (#92042) 2023-04-26 18:41:00 +02:00
J. Nick Koston f33e8c518f Ensure lutron_caseta logbook platform does not raise when integration is not loaded (#91978) 2023-04-26 18:39:42 +02:00
Bram Kragten aa4544accb Add assist pipeline and language selectors (#92030) 2023-04-26 18:39:02 +02:00
Jan Bouwhuis f6d8859dd2 Add codeowner for imap integration (#92067) 2023-04-26 18:21:58 +02:00
Erik Montnemery ce99319ea5 Add LED settings support to Home Assistant Yellow (#86451)
* Add LED control support to Home Assistant Yellow

* Fix the handlers

* Remove switch platform

* Allow configuring LED settings from the options flow

* Add missing translations

* Add tests

* Add tests
2023-04-26 11:02:52 -04:00
Ondřej Kolenatý 64e4414a5e Add today's remaining production estimate (#91965) 2023-04-26 15:58:28 +02:00
Erik Montnemery 32ffedd365 Fail TTS tests if default TTS cache dir exists (#92023)
Fail tests if default tts cache dir exists
2023-04-26 15:28:48 +02:00
Erik Montnemery 904ce226fb Tweak response of /api/cloud/login (#92058) 2023-04-26 15:28:08 +02:00
Franck Nijhof 565b26e884 Fix tts add-on discovery for Wyoming (#92064) 2023-04-26 08:04:46 -05:00
Matthias Alphart 0b9fbb1800 Fix typo in Nextcloud YAML deprecation message (#92060) 2023-04-26 13:51:47 +02:00
Erik Montnemery 2750a5c3e6 Make assist_pipeline an after dependency of cloud (#92057) 2023-04-26 13:45:32 +02:00
Paulus Schoutsen cdbdf1ba4f 2023.4.6 (#91833) 2023-04-21 20:31:05 -04:00
J. Nick Koston d58f62cb5e Remove old migration tests that have been replaced (#91842)
These tests were moved to test_migration_from_schema_32.py in `dev`
and have changed. Remove the old tests as they are no longer
correct
2023-04-21 19:12:21 -04:00
Paulus Schoutsen f1c4605fba Bumped version to 2023.4.6 2023-04-21 14:58:46 -04:00
Paulus Schoutsen deb55a74da Disallow uploading files to bypass the media dirs (#91817) 2023-04-21 14:58:42 -04:00
Allen Porter 30da629285 Relax the constraint that events must have a consistent timezone for start/end (#91788) 2023-04-21 14:58:41 -04:00
Stephan Uhle 26b28001c5 Bump pysml to 0.0.10 (#91773) 2023-04-21 14:58:40 -04:00
Nathan Spencer 64f8059f00 Bump pylitterbot to 2023.4.0 (#91759) 2023-04-21 14:58:39 -04:00
Jan Bouwhuis 8363183943 Do not wait for mqtt at startup mqtt_statestream (#91721) 2023-04-21 14:58:38 -04:00
Teemu R e19279fda5 Bump python-songpal dependency (#91708) 2023-04-21 14:58:38 -04:00
J. Nick Koston 591ffe2340 Fallback to generating a new ULID on migraiton if context is missing or invalid (#91704)
* Fallback to generating a new ULID on migraiton if context is missing or invalid

It was discovered that postgresql will do a full scan if
there is a low cardinality on the index because of missing
context ids. We will now generate a ULID for the timestamp
of the row if the context data is missing or invalid

fixes #91514

* tests

* tweak

* tweak

* preen
2023-04-21 14:58:37 -04:00
Shay Levy fc4e8e5e7b Bump aioshelly to 5.3.2 (#91679) 2023-04-21 14:58:36 -04:00
J. Nick Koston 36d2accb5b Handle long format context UUIDs during migration (#91657)
In https://github.com/home-assistant/core/issues/91514 is was discovered
these exist in older versions
2023-04-21 14:58:07 -04:00
epenet 38de9765df Bump renault-api to 0.1.13 (#91609) 2023-04-21 14:55:51 -04:00
Duco Sebel 6b02892c28 Handle UnsupportedError in HomeWizard (#91608)
* Handle UnsupportedEror

* Make error message more clear

* Remove debug line, whoops
2023-04-21 14:55:50 -04:00
Tom Harris c544da7426 Fix Insteon thermostat issue (#91568)
* Bump pyinsteon

* Bump pyinsteon

* Bump pyinsteon
2023-04-21 14:55:49 -04:00
Aaron Godfrey 71f0f53ddc Fix tasks with no due date from not triggering on calendar state. (#91196)
Fix tasks with no due date.

Prior to this change we were setting the start date/time to utc rather
than the user's timezone.
2023-04-21 14:55:48 -04:00
J. Nick Koston 03c517b066 Add a guard against selecting all entities in state_changes_during_period (#91585)
Add a guard against selecting all entities in state_changes_during_period

This cannot happen in `dev` because we require entity ids
2023-04-18 09:26:41 -04:00
Paulus Schoutsen b05fcd7904 2023.4.5 (#91544) 2023-04-17 22:20:19 -04:00
Franck Nijhof 940861e2be Bumped version to 2023.4.5 2023-04-17 15:37:08 +02:00
Christopher Bailey 559ce6a275 Bump unifiprotect to 4.8.1 (#91522) 2023-04-17 15:36:51 +02:00
rappenze 273e1fd2be Fix state mapping in fibaro climate (#91505) 2023-04-17 15:36:48 +02:00
Ben Morton 5ddc18f8ed Resolve issue with switchbot blind tilt devices getting stuck in opening/closing state (#91495) 2023-04-17 15:36:44 +02:00
J. Nick Koston 489a6e766b Fix onvif failing to reload (#91482) 2023-04-17 15:36:40 +02:00
starkillerOG 572f2cc167 Reolink ONVIF move read to primary callback (#91478)
* Move read to primary callback

* fix styling

* Do not raise on ConnectionResetError

* Split request.text() to .read() and decode("utf-8")
2023-04-17 15:36:37 +02:00
J. Nick Koston 5321c60058 Handle a few more transient onvif errors (#91473) 2023-04-17 15:36:33 +02:00
J. Nick Koston 00a86757fa Bump onvif-zeep-async to 1.2.11 (#91472) 2023-04-17 15:36:30 +02:00
J. Nick Koston b06d624d43 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-17 15:36:26 +02:00
Michael Davie 89b1d5bb68 Bump env_canada to v0.5.33 (#91468) 2023-04-17 15:36:22 +02:00
Erik Montnemery bf389440dc Save Thread dataset store when changing preferred dataset (#91411) 2023-04-17 15:36:18 +02:00
puddly 2b9cc39d2b Fix attribute reporting config failures in ZHA (#91403) 2023-04-17 15:36:15 +02:00
J. Nick Koston afe3fd5ec0 Bump onvif-zeep-async to 1.2.5 (#91399) 2023-04-17 15:36:11 +02:00
Aidan Timson e29d5a1356 Fix listener running in foreground for System Bridge integration (#91391)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-17 15:36:08 +02:00
rich-kettlewell 5f7b447d7a Tado set_water_heater_timer should use water_heater domain (#91364) 2023-04-17 15:36:03 +02:00
epenet 0e3f462bfb Add missing mock in sharkiq tests (#91325) 2023-04-17 15:33:52 +02:00
starkillerOG 8feab57d59 Reolink prevent ONVIF push being lost due to ConnectionResetError (#91070)
* Make "Connection lost" error less likely

* Handle connection loss during ONVIF event reading

* tweak

* fix styling

* catch asyncio.CancelledError from request.text()

* missing ()

* re-raise cancelation for proper cleanup

* Simplify

* Also set webhook_reachable if connection lost

* fix styntax

* Send HTTP_OK directly after data read done

* protect agains garbage collection

* Protect shielded task (inner) not shielded future (outer)

* fix black

* Make sure exceptions are logged

* fix spelling

* fix black

* fix spelling

* Simplify using hass.async_create_task

* clarify comment

* Eleborate comment

* Update homeassistant/components/reolink/host.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Apply suggestions from bdraco

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-17 15:28:25 +02:00
Mark Adkins 2bda40d352 Fix SharkIQ token expiration (#89357) 2023-04-17 15:27:44 +02:00
Meow 47398f03dd Add SetSynchronizationPoint fallback to onvif (#86400)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-17 15:22:17 +02:00
Franck Nijhof 3f0f5dc303 2023.4.4 (#91356) 2023-04-13 15:32:45 +02:00
Franck Nijhof b5ac3ee288 Bumped version to 2023.4.4 2023-04-13 13:50:25 +02:00
Bram Kragten 51c99d26b4 Update frontend to 20230411.1 (#91344) 2023-04-13 13:50:10 +02:00
J. Nick Koston f77ce413be Bump aiolifx to 0.8.10 (#91324) 2023-04-13 13:50:06 +02:00
Duco Sebel 7a8159052e Bump python-homewizard-energy to 2.0.1 (#91097) 2023-04-13 13:50:02 +02:00
Paulus Schoutsen 8ec6afb85a 2023.4.3 (#91316) 2023-04-12 21:50:11 -04:00
Franck Nijhof bbf2d0e6ad Remove codecov from Python test requirements (#91295) 2023-04-12 20:51:59 -04:00
tronikos c073cee049 Google Assistant SDK: Fix broadcast command for Portuguese (#91293)
Fix broadcast command for pt
2023-04-12 20:51:58 -04:00
Paulus Schoutsen e9f1148c0a Bumped version to 2023.4.3 2023-04-12 20:35:59 -04:00
J. Nick Koston a420007e80 Restore use of local timezone for MariaDB/MySQL in SQL integration (#91313)
* Use local timezone for recorder connection

The fix in #90335 had an unexpected side effect of
using UTC for the timezone since all recorder operations
use UTC. Since only sqlite much use the database executor
we can use a seperate connection pool which uses local time

This also ensures that the engines are disposed of
when Home Assistant is shutdown as previously we
did not cleanly disconnect

* coverage

* fix unclean shutdown in config flow

* tweaks
2023-04-12 20:35:50 -04:00
puddly 64a9bfcc22 Bump ZHA dependencies (#91291) 2023-04-12 20:35:49 -04:00
codyhackw fd53eda5c6 Update Inovelli Blue Series switch support in ZHA (#91254)
Co-authored-by: David F. Mulcahey <david.mulcahey@icloud.com>
2023-04-12 20:35:49 -04:00
Erik Montnemery d6574b4a2e Fix switch_as_x name (#91232) 2023-04-12 20:35:48 -04:00
Bram Kragten 8eb75beb96 Update frontend to 20230411.0 (#91219) 2023-04-12 20:35:47 -04:00
Erik Montnemery 68920a12aa Flush conversation name cache when an entity is renamed (#91214) 2023-04-12 20:35:46 -04:00
Aaron Bach a806e070a2 Bump pytile to 2023.04.0 (#91191) 2023-04-12 20:35:45 -04:00
David F. Mulcahey a87c78ca20 Cleanup ZHA from Zigpy deprecated property removal (#91180) 2023-04-12 20:35:44 -04:00
Aidan Timson 48df638f5d Reduce startup time for System Bridge integration (#91171) 2023-04-12 20:35:43 -04:00
Allen Porter c601266f9c Fix all day event coercion logic (#91169) 2023-04-12 20:35:42 -04:00
starkillerOG 30d615f206 Reolink config flow fix custom port when USE_HTTPS not selected (#91137)
give USE_HTTPS a default
2023-04-12 20:35:41 -04:00
J. Nick Koston 2db8d70c2f Fix false positive in SQL sensor full table scan check (#91134) 2023-04-12 20:35:40 -04:00
J. Nick Koston 3efffe7688 Bump ulid-transform to 0.6.3 (#91133)
* Bump ulid-transform to 0.6.2

changelog: https://github.com/bdraco/ulid-transform/compare/v0.6.0...v0.6.2

32bit fixes

fixes #91092

* 0.6.3
2023-04-12 20:35:39 -04:00
Allen Porter dc777f78b8 Relax calendar event validation to allow existing zero duration events (#91129)
Relax event valudation to allow existing zero duration events
2023-04-12 20:35:38 -04:00
Michael Davie 4cd00da319 Bump env_canada to 0.5.32 (#91126) 2023-04-12 20:35:37 -04:00
Robert Hillis 3f6486db3e Bump aiopyarr to 23.4.0 (#91110) 2023-04-12 20:35:36 -04:00
Diogo Gomes 2d41fe837c Track availability of source sensor in utility meter (#91035)
* track availability of source sensor

* address review comments
2023-04-12 20:35:35 -04:00
Pascal Reeb 34394d90c0 Fall back to polling if webhook cannot be registered on Nuki (#91013)
fix(nuki): throw warning if webhook cannot be created
2023-04-12 20:35:34 -04:00
Anthony Mattas fa29aea68e Fix configuring Flo instances (#90990)
* Update config_flow.py

Used constant string for consistency

* Update config_flow.py

Removed code for location ID and name the integration using the username

* Update manifest.json

Updated codeowners

* Update config_flow.py

* Update config_flow.py

Formatted with black

* Update manifest.json

Updated codeowners

* Update test_config_flow.py

Updated test
2023-04-12 20:35:33 -04:00
Paulus Schoutsen 7928b31087 2023.4.2 (#91111) 2023-04-08 23:41:48 -04:00
J. Nick Koston e792350be6 Fix fnvhash import in schema 32 test backport (#91112) 2023-04-08 23:41:19 -04:00
Paulus Schoutsen 5f0553dd22 Bumped version to 2023.4.2 2023-04-08 22:58:28 -04:00
J. Nick Koston 8f6b77235e Make the device_tracker more forgiving when passed an empty ip address string (#91101)
This has come up over and over and over again

fixes #87165 fixes #51980
2023-04-08 22:56:49 -04:00
J. Nick Koston 8ababc75d4 Bump flux_led to 0.28.37 (#91099)
changes: https://github.com/Danielhiversen/flux_led/releases/tag/0.28.37
2023-04-08 22:56:48 -04:00
J. Nick Koston 0a8f399655 Fix context_user_id round trip when calling to_native (#91098)
We do not actually use this in the history or logbook
APIs so nothing broke but there was a bug here for anyone
calling this directly

fixes #91090
2023-04-08 22:56:47 -04:00
Michael Davie 19567e7fee Bump env_canada to v0.5.31 (#91094) 2023-04-08 22:56:46 -04:00
Garrett 3a137cb24c Bump subarulink to 0.7.6 (#91064) 2023-04-08 22:56:45 -04:00
Allen Porter 935af6904d Bump gcal_sync to 4.1.4 (#91062) 2023-04-08 22:56:44 -04:00
Allen Porter 4fed5ad21c Make location optional in google calendar create service (#91061) 2023-04-08 22:56:44 -04:00
J. Nick Koston 9dc15687b5 Bump zeroconf to 0.56.0 (#91060) 2023-04-08 22:56:43 -04:00
J. Nick Koston 38a0eca223 Bump zeroconf to 0.55.0 (#90987) 2023-04-08 22:56:42 -04:00
David F. Mulcahey 6836e0b511 Fix Smartthings acceleration sensor in ZHA (#91056) 2023-04-08 22:55:52 -04:00
David F. Mulcahey cab88b72b8 Bump ZHA quirks lib (#91054) 2023-04-08 22:55:51 -04:00
Steven Looman 07421927ec Make sure upnp-router is also initialized when first seen through an advertisement (#91037) 2023-04-08 22:55:50 -04:00
Diogo Gomes 828a2779a0 Delay utility_meter until HA has started (#91017)
* increase information for end user

* only warn after home assistant has started

* delay utility_meter until HA has startED
2023-04-08 22:55:49 -04:00
Joost Lekkerkerker 7392a5780c Bump roombapy to 1.6.8 (#91012)
* Update roombapy to 1.6.7

* Update roombapy to 1.6.8
2023-04-08 22:55:48 -04:00
Aaron Bach 804270a797 Bump aioambient to 2023.04.0 (#90991) 2023-04-08 22:55:47 -04:00
J. Nick Koston 7f5f286648 Bump vallox-websocket-api to 3.2.1 (#90980)
unblocks https://github.com/home-assistant/core/pull/90901
which will finally fix the races in websockets
2023-04-08 22:55:46 -04:00
J. Nick Koston 0a70a29e92 Resume entity id post migration after a restart (#90973)
* Restart entity id post migration after a restart

If the entity migration finished and Home Assistant was
restarted during the post migration it would never be resumed
which means the old index and space would never be recovered

* add migration resume test
2023-04-08 22:55:46 -04:00
J. Nick Koston dc2f2e8d3f Raise an issue for legacy SQL queries that will cause full table scans (#90971)
* Raise an issue for SQL queries that will cause full table scans

* Raise an issue for SQL queries that will cause full table scans

* Raise an issue for SQL queries that will cause full table scans

* Raise an issue for SQL queries that will cause full table scans

* Update homeassistant/components/sql/sensor.py

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

* coverage

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2023-04-08 22:55:45 -04:00
J. Nick Koston 6522a3ad1b Bump websockets constraint to 11.0.1+ (#90901) 2023-04-08 22:55:44 -04:00
PatrickGlesner be65d4f33e Fix NMBS AttributeError (#90525)
* Fix NMBS AttributeError (Issue #90505)

* Set and use API_FAILURE

* Configure the logger to track API failures

* Remove broad exceptions and rewite logging
2023-04-08 22:55:43 -04:00
Paulus Schoutsen 0c15c75781 2023.4.1 (#90956) 2023-04-06 17:52:14 -04:00
Heikki Partanen 2bf51a033b Fix verisure autolock (#90960)
Fix verisure autolock #90959
2023-04-06 20:54:40 +00:00
Steven Rollason cfd8695aaa Fix command_template sensor value_template not being used if json_attributes set (#90603)
* Allow value_template to be used if json_attributes set

* Set state to None if no value_template and json_attributes used

* Refactor check for no value_template when json_attributes used

* Updated and additional unit test

* Updated to set _attr_native_value and return if value_template is None

* Update unit test docstring

* Updated test docstring based on feedback
2023-04-06 20:49:32 +00:00
Jan Bouwhuis e8a6a2e105 Fix error after losing an imap connection (#90966)
Cleanup first after losing an imap connection
2023-04-06 20:46:54 +00:00
Allen Porter 73a960af34 Bump gcal_sync to 4.1.3 (#90968) 2023-04-06 20:44:52 +00:00
Allen Porter bbb571fdf8 Coerce previously persisted local calendars to have valid durations (#90970) 2023-04-06 20:42:00 +00:00
J. Nick Koston c944be8215 Fix state being cleared on disconnect with deep sleep esphome devices (#90925)
* Fix state being cleared on disconnect with deep sleep esphome devices

fixes #90923

* fix logic
2023-04-06 20:39:04 +00:00
J. Nick Koston 5e903e04cf Avoid writing state to all esphome entities at shutdown (#90555) 2023-04-06 20:39:00 +00:00
starkillerOG 6884b0a421 Bump reolink-aio to 0.5.10 (#90963)
* use is_doorbell instead of is_doorbell_enabled

* Bump reolink-aio to 0.5.10
2023-04-06 14:35:39 -04:00
Aaron Bach a1c7159304 Bump aioambient to 2022.10.0 (#90940)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-06 14:34:25 -04:00
epenet d65791027f Fix flaky test in vesync (#90921)
* Fix flaky test in vesync

* Move sorting to the test
2023-04-06 14:34:24 -04:00
Paulus Schoutsen 5ffa0cba39 Bumped version to 2023.4.1 2023-04-06 13:21:13 -04:00
Bram Kragten f5be600383 Update frontend to 20230406.1 (#90951) 2023-04-06 13:21:07 -04:00
Pascal Reeb 9b2e26c270 Handle NoURLAvailableError in Nuki component (#90927)
* fix(nuki): handle NoURLAvailableError

* only try internal URLs
2023-04-06 13:21:06 -04:00
stickpin e25edea815 Return empty available programs list if an appliance is off during initial configuration (#90905) 2023-04-06 13:21:05 -04:00
J. Nick Koston 849000d5ac Bump aiodiscover to 1.4.16 (#90903) 2023-04-06 13:21:04 -04:00
Aaron Bach cb06541fda Bump simplisafe-python to 2023.04.0 (#90896)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-06 13:21:03 -04:00
J. Nick Koston 70d1e733f6 Fix entity_id migration query failing with MySQL 8.0.30 (#90895) 2023-04-06 13:21:02 -04:00
J. Nick Koston 0b3012071e Guard against invalid ULIDs in contexts while recording events (#90889) 2023-04-06 13:21:01 -04:00
J. Nick Koston 42b7ed115f Bump ulid-transform 0.6.0 (#90888)
* Bump ulid-transform 0.6.0

changelog: https://github.com/bdraco/ulid-transform/compare/v0.5.1...v0.6.0

to find the source of the invalid ulids in https://github.com/home-assistant/core/issues/90887
2023-04-06 13:21:00 -04:00
J. Nick Koston 513a13f369 Fix missing bluetooth client wrapper in bleak_retry_connector (#90885) 2023-04-06 13:20:59 -04:00
Michael f341d0787e Migrate entity unique ids in PI-Hole (#90883)
* migrate entity unique ids

* Update homeassistant/components/pi_hole/__init__.py

---------

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2023-04-06 13:20:58 -04:00
J. Nick Koston c8ee45b53c Add MariaDB deadlock retry wrapper to database timestamp column migrations (#90880)
Add deadlock retry wrapper to timestamp column migrations

fixes #90819
2023-04-06 13:20:57 -04:00
J. Nick Koston b4e2dd4e06 Add constraint for websockets to <11.0 (#90868) 2023-04-06 13:20:56 -04:00
J. Nick Koston c663d8754b Generate a seperate log message per dumped object for profiler.dump_log_objects (#90867)
Since some objects are very large we can generate overly large log messages
```
Event data for system_log_event exceed maximum size of 32768 bytes. This can cause database performance issues; Event data will not be stored
```

Reported in https://ptb.discord.com/channels/330944238910963714/427516175237382144/1093069996101472306
2023-04-06 13:20:55 -04:00
Tom Harris 968a4e4818 Fix issue with Insteon All-Link Database loading (#90858)
Bump to 1.4.1
2023-04-06 13:20:54 -04:00
saschaabraham 833b95722e Bump fritzconnection to 1.12.0 (#90799) 2023-04-06 13:20:53 -04:00
mkmer 096e814929 Handle Uncaught exceptions in async_update Honeywell (#90746) 2023-04-06 13:20:52 -04:00
327 changed files with 7181 additions and 1814 deletions
+3 -2
View File
@@ -550,8 +550,8 @@ build.json @home-assistant/supervisor
/tests/components/image_processing/ @home-assistant/core
/homeassistant/components/image_upload/ @home-assistant/core
/tests/components/image_upload/ @home-assistant/core
/homeassistant/components/imap/ @engrbm87
/tests/components/imap/ @engrbm87
/homeassistant/components/imap/ @engrbm87 @jbouwh
/tests/components/imap/ @engrbm87 @jbouwh
/homeassistant/components/incomfort/ @zxdavb
/homeassistant/components/influxdb/ @mdegat01
/tests/components/influxdb/ @mdegat01
@@ -783,6 +783,7 @@ build.json @home-assistant/supervisor
/homeassistant/components/netdata/ @fabaff
/homeassistant/components/netgear/ @hacf-fr @Quentame @starkillerOG
/tests/components/netgear/ @hacf-fr @Quentame @starkillerOG
/homeassistant/components/netgear_lte/ @tkdrob
/homeassistant/components/network/ @home-assistant/core
/tests/components/network/ @home-assistant/core
/homeassistant/components/nexia/ @bdraco
+15 -15
View File
@@ -3,12 +3,12 @@ from __future__ import annotations
from typing import Any, Final
from aioairzone.common import OperationMode
from aioairzone.common import OperationAction, OperationMode
from aioairzone.const import (
API_MODE,
API_ON,
API_SET_POINT,
AZD_DEMAND,
AZD_ACTION,
AZD_HUMIDITY,
AZD_MASTER,
AZD_MODE,
@@ -39,12 +39,13 @@ from .const import API_TEMPERATURE_STEP, DOMAIN, TEMP_UNIT_LIB_TO_HASS
from .coordinator import AirzoneUpdateCoordinator
from .entity import AirzoneZoneEntity
HVAC_ACTION_LIB_TO_HASS: Final[dict[OperationMode, HVACAction]] = {
OperationMode.STOP: HVACAction.OFF,
OperationMode.COOLING: HVACAction.COOLING,
OperationMode.HEATING: HVACAction.HEATING,
OperationMode.FAN: HVACAction.FAN,
OperationMode.DRY: HVACAction.DRYING,
HVAC_ACTION_LIB_TO_HASS: Final[dict[OperationAction, HVACAction]] = {
OperationAction.COOLING: HVACAction.COOLING,
OperationAction.DRYING: HVACAction.DRYING,
OperationAction.FAN: HVACAction.FAN,
OperationAction.HEATING: HVACAction.HEATING,
OperationAction.IDLE: HVACAction.IDLE,
OperationAction.OFF: HVACAction.OFF,
}
HVAC_MODE_LIB_TO_HASS: Final[dict[OperationMode, HVACMode]] = {
OperationMode.STOP: HVACMode.OFF,
@@ -156,14 +157,13 @@ class AirzoneClimate(AirzoneZoneEntity, ClimateEntity):
"""Update climate attributes."""
self._attr_current_temperature = self.get_airzone_value(AZD_TEMP)
self._attr_current_humidity = self.get_airzone_value(AZD_HUMIDITY)
self._attr_hvac_action = HVAC_ACTION_LIB_TO_HASS[
self.get_airzone_value(AZD_ACTION)
]
if self.get_airzone_value(AZD_ON):
mode = self.get_airzone_value(AZD_MODE)
self._attr_hvac_mode = HVAC_MODE_LIB_TO_HASS[mode]
if self.get_airzone_value(AZD_DEMAND):
self._attr_hvac_action = HVAC_ACTION_LIB_TO_HASS[mode]
else:
self._attr_hvac_action = HVACAction.IDLE
self._attr_hvac_mode = HVAC_MODE_LIB_TO_HASS[
self.get_airzone_value(AZD_MODE)
]
else:
self._attr_hvac_action = HVACAction.OFF
self._attr_hvac_mode = HVACMode.OFF
self._attr_target_temperature = self.get_airzone_value(AZD_TEMP_SET)
@@ -11,5 +11,5 @@
"documentation": "https://www.home-assistant.io/integrations/airzone",
"iot_class": "local_polling",
"loggers": ["aioairzone"],
"requirements": ["aioairzone==0.5.2"]
"requirements": ["aioairzone==0.5.5"]
}
+10 -12
View File
@@ -3,7 +3,7 @@ from abc import ABC, abstractmethod
import asyncio
import logging
from homeassistant.core import CALLBACK_TYPE, callback
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.helpers.storage import Store
from .const import DOMAIN
@@ -17,11 +17,12 @@ _LOGGER = logging.getLogger(__name__)
class AbstractConfig(ABC):
"""Hold the configuration for Alexa."""
_unsub_proactive_report: asyncio.Task[CALLBACK_TYPE] | None = None
_unsub_proactive_report: CALLBACK_TYPE | None = None
def __init__(self, hass):
def __init__(self, hass: HomeAssistant) -> None:
"""Initialize abstract config."""
self.hass = hass
self._enable_proactive_mode_lock = asyncio.Lock()
self._store = None
async def async_initialize(self):
@@ -67,20 +68,17 @@ class AbstractConfig(ABC):
async def async_enable_proactive_mode(self):
"""Enable proactive mode."""
_LOGGER.debug("Enable proactive mode")
if self._unsub_proactive_report is None:
self._unsub_proactive_report = self.hass.async_create_task(
async_enable_proactive_mode(self.hass, self)
async with self._enable_proactive_mode_lock:
if self._unsub_proactive_report is not None:
return
self._unsub_proactive_report = await async_enable_proactive_mode(
self.hass, self
)
try:
await self._unsub_proactive_report
except Exception:
self._unsub_proactive_report = None
raise
async def async_disable_proactive_mode(self):
"""Disable proactive mode."""
_LOGGER.debug("Disable proactive mode")
if unsub_func := await self._unsub_proactive_report:
if unsub_func := self._unsub_proactive_report:
unsub_func()
self._unsub_proactive_report = None
@@ -60,6 +60,7 @@ class AlexaConfig(AbstractConfig):
"""Return an identifier for the user that represents this config."""
return ""
@core.callback
def should_expose(self, entity_id):
"""If an entity should be exposed."""
if not self._config[CONF_FILTER].empty_filter:
@@ -324,18 +324,29 @@ class AppleTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
all_identifiers = set(self.atv.all_identifiers)
discovered_ip_address = str(self.atv.address)
for entry in self._async_current_entries():
if not all_identifiers.intersection(
existing_identifiers = set(
entry.data.get(CONF_IDENTIFIERS, [entry.unique_id])
):
)
if not all_identifiers.intersection(existing_identifiers):
continue
if entry.data.get(CONF_ADDRESS) != discovered_ip_address:
combined_identifiers = existing_identifiers | all_identifiers
if entry.data.get(
CONF_ADDRESS
) != discovered_ip_address or combined_identifiers != set(
entry.data.get(CONF_IDENTIFIERS, [])
):
self.hass.config_entries.async_update_entry(
entry,
data={**entry.data, CONF_ADDRESS: discovered_ip_address},
)
self.hass.async_create_task(
self.hass.config_entries.async_reload(entry.entry_id)
data={
**entry.data,
CONF_ADDRESS: discovered_ip_address,
CONF_IDENTIFIERS: list(combined_identifiers),
},
)
if entry.source != config_entries.SOURCE_IGNORE:
self.hass.async_create_task(
self.hass.config_entries.async_reload(entry.entry_id)
)
if not allow_exist:
raise DeviceAlreadyConfigured()
@@ -23,6 +23,7 @@ from homeassistant.helpers.collection import (
StorageCollection,
StorageCollectionWebsocket,
)
from homeassistant.helpers.singleton import singleton
from homeassistant.helpers.storage import Store
from homeassistant.util import (
dt as dt_util,
@@ -369,7 +370,7 @@ class PipelineRun:
def start(self) -> None:
"""Emit run start event."""
data = {
"pipeline": self.pipeline.name,
"pipeline": self.pipeline.id,
"language": self.language,
}
if self.runner_data is not None:
@@ -956,7 +957,8 @@ class PipelineRunDebug:
)
async def async_setup_pipeline_store(hass: HomeAssistant) -> None:
@singleton(DOMAIN)
async def async_setup_pipeline_store(hass: HomeAssistant) -> PipelineData:
"""Set up the pipeline storage collection."""
pipeline_store = PipelineStorageCollection(
Store(hass, STORAGE_VERSION, STORAGE_KEY)
@@ -969,4 +971,4 @@ async def async_setup_pipeline_store(hass: HomeAssistant) -> None:
PIPELINE_FIELDS,
PIPELINE_FIELDS,
).async_setup(hass)
hass.data[DOMAIN] = PipelineData({}, pipeline_store)
return PipelineData({}, pipeline_store)
@@ -1,8 +1,13 @@
{
"entity": {
"binary_sensor": {
"assist_in_progress": {
"name": "Assist in progress"
}
},
"select": {
"pipeline": {
"name": "Assist Pipeline",
"name": "Assist pipeline",
"state": {
"preferred": "Preferred"
}
+1 -1
View File
@@ -4,7 +4,7 @@ from __future__ import annotations
import logging
from typing import Any
from atenpdu import AtenPE, AtenPEError
from atenpdu import AtenPE, AtenPEError # pylint: disable=import-error
import voluptuous as vol
from homeassistant.components.switch import (
+5 -5
View File
@@ -3,6 +3,7 @@ import asyncio
import logging
from aiohttp import ClientError
from yalexs.util import get_latest_activity
from homeassistant.core import callback
from homeassistant.helpers.debounce import Debouncer
@@ -169,12 +170,11 @@ class ActivityStream(AugustSubscriberMixin):
device_id = activity.device_id
activity_type = activity.activity_type
device_activities = self._latest_activities.setdefault(device_id, {})
lastest_activity = device_activities.get(activity_type)
# Ignore activities that are older than the latest one
# Ignore activities that are older than the latest one unless it is a non
# locking or unlocking activity with the exact same start time.
if (
lastest_activity
and lastest_activity.activity_start_time >= activity.activity_start_time
get_latest_activity(activity, device_activities.get(activity_type))
!= activity
):
continue
+18 -9
View File
@@ -5,7 +5,7 @@ from typing import Any
from aiohttp import ClientResponseError
from yalexs.activity import SOURCE_PUBNUB, ActivityType
from yalexs.lock import LockStatus
from yalexs.util import update_lock_detail_from_activity
from yalexs.util import get_latest_activity, update_lock_detail_from_activity
from homeassistant.components.lock import ATTR_CHANGED_BY, LockEntity
from homeassistant.config_entries import ConfigEntry
@@ -90,17 +90,26 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
@callback
def _update_from_data(self):
"""Get the latest state of the sensor and update activity."""
lock_activity = self._data.activity_stream.get_latest_device_activity(
self._device_id,
{ActivityType.LOCK_OPERATION, ActivityType.LOCK_OPERATION_WITHOUT_OPERATOR},
activity_stream = self._data.activity_stream
device_id = self._device_id
if lock_activity := activity_stream.get_latest_device_activity(
device_id,
{ActivityType.LOCK_OPERATION},
):
self._attr_changed_by = lock_activity.operated_by
lock_activity_without_operator = activity_stream.get_latest_device_activity(
device_id,
{ActivityType.LOCK_OPERATION_WITHOUT_OPERATOR},
)
if lock_activity is not None:
self._attr_changed_by = lock_activity.operated_by
update_lock_detail_from_activity(self._detail, lock_activity)
# If the source is pubnub the lock must be online since its a live update
if lock_activity.source == SOURCE_PUBNUB:
if latest_activity := get_latest_activity(
lock_activity_without_operator, lock_activity
):
if latest_activity.source == SOURCE_PUBNUB:
# If the source is pubnub the lock must be online since its a live update
self._detail.set_online(True)
update_lock_detail_from_activity(self._detail, latest_activity)
bridge_activity = self._data.activity_stream.get_latest_device_activity(
self._device_id, {ActivityType.BRIDGE_OPERATION}
@@ -28,5 +28,5 @@
"documentation": "https://www.home-assistant.io/integrations/august",
"iot_class": "cloud_push",
"loggers": ["pubnub", "yalexs"],
"requirements": ["yalexs==1.3.2", "yalexs-ble==2.1.16"]
"requirements": ["yalexs==1.3.3", "yalexs-ble==2.1.16"]
}
+5 -1
View File
@@ -39,7 +39,11 @@ async def async_setup_entry(
class BAFFan(BAFEntity, FanEntity):
"""BAF ceiling fan component."""
_attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.DIRECTION
_attr_supported_features = (
FanEntityFeature.SET_SPEED
| FanEntityFeature.DIRECTION
| FanEntityFeature.PRESET_MODE
)
_attr_preset_modes = [PRESET_MODE_AUTO]
_attr_speed_count = SPEED_COUNT
@@ -15,10 +15,10 @@
],
"quality_scale": "internal",
"requirements": [
"bleak==0.20.1",
"bleak==0.20.2",
"bleak-retry-connector==3.0.2",
"bluetooth-adapters==0.15.3",
"bluetooth-auto-recovery==1.0.3",
"bluetooth-auto-recovery==1.2.0",
"bluetooth-data-tools==0.4.0",
"dbus-fast==1.85.0"
]
@@ -41,6 +41,7 @@ PLATFORMS = [
Platform.DEVICE_TRACKER,
Platform.LOCK,
Platform.NOTIFY,
Platform.NUMBER,
Platform.SELECT,
Platform.SENSOR,
]
@@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/bmw_connected_drive",
"iot_class": "cloud_polling",
"loggers": ["bimmer_connected"],
"requirements": ["bimmer_connected==0.13.0"]
"requirements": ["bimmer_connected==0.13.3"]
}
@@ -0,0 +1,120 @@
"""Number platform for BMW."""
from collections.abc import Callable, Coroutine
from dataclasses import dataclass
import logging
from typing import Any
from bimmer_connected.models import MyBMWAPIError
from bimmer_connected.vehicle import MyBMWVehicle
from homeassistant.components.number import (
NumberDeviceClass,
NumberEntity,
NumberEntityDescription,
NumberMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import BMWBaseEntity
from .const import DOMAIN
from .coordinator import BMWDataUpdateCoordinator
_LOGGER = logging.getLogger(__name__)
@dataclass
class BMWRequiredKeysMixin:
"""Mixin for required keys."""
value_fn: Callable[[MyBMWVehicle], float | int | None]
remote_service: Callable[[MyBMWVehicle, float | int], Coroutine[Any, Any, Any]]
@dataclass
class BMWNumberEntityDescription(NumberEntityDescription, BMWRequiredKeysMixin):
"""Describes BMW number entity."""
is_available: Callable[[MyBMWVehicle], bool] = lambda _: False
dynamic_options: Callable[[MyBMWVehicle], list[str]] | None = None
mode: NumberMode = NumberMode.AUTO
NUMBER_TYPES: list[BMWNumberEntityDescription] = [
BMWNumberEntityDescription(
key="target_soc",
name="Target SoC",
device_class=NumberDeviceClass.BATTERY,
is_available=lambda v: v.is_remote_set_target_soc_enabled,
native_max_value=100.0,
native_min_value=20.0,
native_step=5.0,
mode=NumberMode.SLIDER,
value_fn=lambda v: v.fuel_and_battery.charging_target,
remote_service=lambda v, o: v.remote_services.trigger_charging_settings_update(
target_soc=int(o)
),
icon="mdi:battery-charging-medium",
),
]
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the MyBMW number from config entry."""
coordinator: BMWDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
entities: list[BMWNumber] = []
for vehicle in coordinator.account.vehicles:
if not coordinator.read_only:
entities.extend(
[
BMWNumber(coordinator, vehicle, description)
for description in NUMBER_TYPES
if description.is_available(vehicle)
]
)
async_add_entities(entities)
class BMWNumber(BMWBaseEntity, NumberEntity):
"""Representation of BMW Number entity."""
entity_description: BMWNumberEntityDescription
def __init__(
self,
coordinator: BMWDataUpdateCoordinator,
vehicle: MyBMWVehicle,
description: BMWNumberEntityDescription,
) -> None:
"""Initialize an BMW Number."""
super().__init__(coordinator, vehicle)
self.entity_description = description
self._attr_unique_id = f"{vehicle.vin}-{description.key}"
self._attr_mode = description.mode
@property
def native_value(self) -> float | None:
"""Return the entity value to represent the entity state."""
return self.entity_description.value_fn(self.vehicle)
async def async_set_native_value(self, value: float) -> None:
"""Update to the vehicle."""
_LOGGER.debug(
"Executing '%s' on vehicle '%s' to value '%s'",
self.entity_description.key,
self.vehicle.vin,
value,
)
try:
await self.entity_description.remote_service(self.vehicle, value)
except MyBMWAPIError as ex:
raise HomeAssistantError(ex) from ex
@@ -9,7 +9,7 @@ from bimmer_connected.vehicle.charging_profile import ChargingMode
from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, UnitOfElectricCurrent
from homeassistant.const import UnitOfElectricCurrent
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@@ -37,19 +37,6 @@ class BMWSelectEntityDescription(SelectEntityDescription, BMWRequiredKeysMixin):
SELECT_TYPES: dict[str, BMWSelectEntityDescription] = {
# --- Generic ---
"target_soc": BMWSelectEntityDescription(
key="target_soc",
name="Target SoC",
is_available=lambda v: v.is_remote_set_target_soc_enabled,
options=[str(i * 5 + 20) for i in range(17)],
current_option=lambda v: str(v.fuel_and_battery.charging_target),
remote_service=lambda v, o: v.remote_services.trigger_charging_settings_update(
target_soc=int(o)
),
icon="mdi:battery-charging-medium",
unit_of_measurement=PERCENTAGE,
),
"ac_limit": BMWSelectEntityDescription(
key="ac_limit",
name="AC Charging Limit",
+2 -1
View File
@@ -89,7 +89,8 @@ class BondFan(BondEntity, FanEntity):
features |= FanEntityFeature.SET_SPEED
if self._device.supports_direction():
features |= FanEntityFeature.DIRECTION
if self._device.has_action(Action.BREEZE_ON):
features |= FanEntityFeature.PRESET_MODE
return features
@property
@@ -7,7 +7,7 @@
"integration_type": "device",
"iot_class": "local_polling",
"loggers": ["pybravia"],
"requirements": ["pybravia==0.3.2"],
"requirements": ["pybravia==0.3.3"],
"ssdp": [
{
"st": "urn:schemas-sony-com:service:ScalarWebAPI:1",
@@ -164,7 +164,7 @@ def _validate_rrule(value: Any) -> str:
try:
rrulestr(value)
except ValueError as err:
raise vol.Invalid(f"Invalid rrule: {str(err)}") from err
raise vol.Invalid(f"Invalid rrule '{value}': {err}") from err
# Example format: FREQ=DAILY;UNTIL=...
rule_parts = dict(s.split("=", 1) for s in value.split(";"))
+111 -19
View File
@@ -20,14 +20,19 @@ from homeassistant.components.alexa import (
errors as alexa_errors,
state_report as alexa_state_report,
)
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.homeassistant.exposed_entities import (
async_expose_entity,
async_get_assistant_settings,
async_listen_entity_updates,
async_should_expose,
)
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES
from homeassistant.core import HomeAssistant, callback, split_entity_id
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er, start
from homeassistant.helpers.entity import get_device_class
from homeassistant.helpers.event import async_call_later
from homeassistant.setup import async_setup_component
from homeassistant.util.dt import utcnow
@@ -51,6 +56,73 @@ CLOUD_ALEXA = f"{CLOUD_DOMAIN}.{ALEXA_DOMAIN}"
SYNC_DELAY = 1
SUPPORTED_DOMAINS = {
"alarm_control_panel",
"alert",
"automation",
"button",
"camera",
"climate",
"cover",
"fan",
"group",
"humidifier",
"image_processing",
"input_boolean",
"input_button",
"input_number",
"light",
"lock",
"media_player",
"number",
"scene",
"script",
"switch",
"timer",
"vacuum",
}
SUPPORTED_BINARY_SENSOR_DEVICE_CLASSES = {
BinarySensorDeviceClass.DOOR,
BinarySensorDeviceClass.GARAGE_DOOR,
BinarySensorDeviceClass.MOTION,
BinarySensorDeviceClass.OPENING,
BinarySensorDeviceClass.PRESENCE,
BinarySensorDeviceClass.WINDOW,
}
SUPPORTED_SENSOR_DEVICE_CLASSES = {
SensorDeviceClass.TEMPERATURE,
}
def entity_supported(hass: HomeAssistant, entity_id: str) -> bool:
"""Return if the entity is supported.
This is called when migrating from legacy config format to avoid exposing
all binary sensors and sensors.
"""
domain = split_entity_id(entity_id)[0]
if domain in SUPPORTED_DOMAINS:
return True
try:
device_class = get_device_class(hass, entity_id)
except HomeAssistantError:
# The entity no longer exists
return False
if (
domain == "binary_sensor"
and device_class in SUPPORTED_BINARY_SENSOR_DEVICE_CLASSES
):
return True
if domain == "sensor" and device_class in SUPPORTED_SENSOR_DEVICE_CLASSES:
return True
return False
class CloudAlexaConfig(alexa_config.AbstractConfig):
"""Alexa Configuration."""
@@ -127,35 +199,50 @@ class CloudAlexaConfig(alexa_config.AbstractConfig):
# Don't migrate if there's a YAML config
return
entity_registry = er.async_get(self.hass)
for entity_id, entry in entity_registry.entities.items():
if CLOUD_ALEXA in entry.options:
continue
options = {"should_expose": self._should_expose_legacy(entity_id)}
entity_registry.async_update_entity_options(entity_id, CLOUD_ALEXA, options)
for entity_id in {
*self.hass.states.async_entity_ids(),
*self._prefs.alexa_entity_configs,
}:
async_expose_entity(
self.hass,
CLOUD_ALEXA,
entity_id,
self._should_expose_legacy(entity_id),
)
async def async_initialize(self):
"""Initialize the Alexa config."""
await super().async_initialize()
if self._prefs.alexa_settings_version != ALEXA_SETTINGS_VERSION:
if self._prefs.alexa_settings_version < 2:
self._migrate_alexa_entity_settings_v1()
await self._prefs.async_update(
alexa_settings_version=ALEXA_SETTINGS_VERSION
async def on_hass_started(hass):
if self._prefs.alexa_settings_version != ALEXA_SETTINGS_VERSION:
if self._prefs.alexa_settings_version < 2 or (
# Recover from a bug we had in 2023.5.0 where entities didn't get exposed
self._prefs.alexa_settings_version < 3
and not any(
settings.get("should_expose", False)
for settings in async_get_assistant_settings(
hass, CLOUD_ALEXA
).values()
)
):
self._migrate_alexa_entity_settings_v1()
await self._prefs.async_update(
alexa_settings_version=ALEXA_SETTINGS_VERSION
)
async_listen_entity_updates(
self.hass, CLOUD_ALEXA, self._async_exposed_entities_updated
)
async def hass_started(hass):
async def on_hass_start(hass):
if self.enabled and ALEXA_DOMAIN not in self.hass.config.components:
await async_setup_component(self.hass, ALEXA_DOMAIN, {})
start.async_at_start(self.hass, hass_started)
start.async_at_start(self.hass, on_hass_start)
start.async_at_started(self.hass, on_hass_started)
self._prefs.async_listen_updates(self._async_prefs_updated)
async_listen_entity_updates(
self.hass, CLOUD_ALEXA, self._async_exposed_entities_updated
)
self.hass.bus.async_listen(
er.EVENT_ENTITY_REGISTRY_UPDATED,
self._handle_entity_registry_updated,
@@ -183,10 +270,15 @@ class CloudAlexaConfig(alexa_config.AbstractConfig):
# Backwards compat
if (default_expose := self._prefs.alexa_default_expose) is None:
return not auxiliary_entity
return not auxiliary_entity and entity_supported(self.hass, entity_id)
return not auxiliary_entity and split_entity_id(entity_id)[0] in default_expose
return (
not auxiliary_entity
and split_entity_id(entity_id)[0] in default_expose
and entity_supported(self.hass, entity_id)
)
@callback
def should_expose(self, entity_id):
"""If an entity should be exposed."""
if not self._config[CONF_FILTER].empty_filter:
+125 -28
View File
@@ -7,12 +7,18 @@ from typing import Any
from hass_nabucasa import Cloud, cloud_api
from hass_nabucasa.google_report_state import ErrorResponse
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.google_assistant import DOMAIN as GOOGLE_DOMAIN
from homeassistant.components.google_assistant.helpers import AbstractConfig
from homeassistant.components.homeassistant.exposed_entities import (
async_expose_entity,
async_get_assistant_settings,
async_get_entity_settings,
async_listen_entity_updates,
async_set_assistant_option,
async_should_expose,
)
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES
from homeassistant.core import (
CoreState,
@@ -21,7 +27,9 @@ from homeassistant.core import (
callback,
split_entity_id,
)
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr, entity_registry as er, start
from homeassistant.helpers.entity import get_device_class
from homeassistant.setup import async_setup_component
from .const import (
@@ -39,6 +47,73 @@ _LOGGER = logging.getLogger(__name__)
CLOUD_GOOGLE = f"{CLOUD_DOMAIN}.{GOOGLE_DOMAIN}"
SUPPORTED_DOMAINS = {
"alarm_control_panel",
"button",
"camera",
"climate",
"cover",
"fan",
"group",
"humidifier",
"input_boolean",
"input_button",
"input_select",
"light",
"lock",
"media_player",
"scene",
"script",
"select",
"switch",
"vacuum",
}
SUPPORTED_BINARY_SENSOR_DEVICE_CLASSES = {
BinarySensorDeviceClass.DOOR,
BinarySensorDeviceClass.GARAGE_DOOR,
BinarySensorDeviceClass.LOCK,
BinarySensorDeviceClass.MOTION,
BinarySensorDeviceClass.OPENING,
BinarySensorDeviceClass.PRESENCE,
BinarySensorDeviceClass.WINDOW,
}
SUPPORTED_SENSOR_DEVICE_CLASSES = {
SensorDeviceClass.AQI,
SensorDeviceClass.CO,
SensorDeviceClass.CO2,
SensorDeviceClass.HUMIDITY,
SensorDeviceClass.PM10,
SensorDeviceClass.PM25,
SensorDeviceClass.TEMPERATURE,
SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
}
def _supported_legacy(hass: HomeAssistant, entity_id: str) -> bool:
"""Return if the entity is supported.
This is called when migrating from legacy config format to avoid exposing
all binary sensors and sensors.
"""
domain = split_entity_id(entity_id)[0]
if domain in SUPPORTED_DOMAINS:
return True
device_class = get_device_class(hass, entity_id)
if (
domain == "binary_sensor"
and device_class in SUPPORTED_BINARY_SENSOR_DEVICE_CLASSES
):
return True
if domain == "sensor" and device_class in SUPPORTED_SENSOR_DEVICE_CLASSES:
return True
return False
class CloudGoogleConfig(AbstractConfig):
"""HA Cloud Configuration for Google Assistant."""
@@ -101,34 +176,56 @@ class CloudGoogleConfig(AbstractConfig):
# Don't migrate if there's a YAML config
return
entity_registry = er.async_get(self.hass)
for entity_id, entry in entity_registry.entities.items():
if CLOUD_GOOGLE in entry.options:
continue
options = {"should_expose": self._should_expose_legacy(entity_id)}
if _2fa_disabled := (self._2fa_disabled_legacy(entity_id) is not None):
options[PREF_DISABLE_2FA] = _2fa_disabled
entity_registry.async_update_entity_options(
entity_id, CLOUD_GOOGLE, options
for entity_id in {
*self.hass.states.async_entity_ids(),
*self._prefs.google_entity_configs,
}:
async_expose_entity(
self.hass,
CLOUD_GOOGLE,
entity_id,
self._should_expose_legacy(entity_id),
)
if _2fa_disabled := (self._2fa_disabled_legacy(entity_id) is not None):
async_set_assistant_option(
self.hass,
CLOUD_GOOGLE,
entity_id,
PREF_DISABLE_2FA,
_2fa_disabled,
)
async def async_initialize(self):
"""Perform async initialization of config."""
await super().async_initialize()
if self._prefs.google_settings_version != GOOGLE_SETTINGS_VERSION:
if self._prefs.google_settings_version < 2:
self._migrate_google_entity_settings_v1()
await self._prefs.async_update(
google_settings_version=GOOGLE_SETTINGS_VERSION
async def on_hass_started(hass: HomeAssistant) -> None:
if self._prefs.google_settings_version != GOOGLE_SETTINGS_VERSION:
if self._prefs.google_settings_version < 2 or (
# Recover from a bug we had in 2023.5.0 where entities didn't get exposed
self._prefs.google_settings_version < 3
and not any(
settings.get("should_expose", False)
for settings in async_get_assistant_settings(
hass, CLOUD_GOOGLE
).values()
)
):
self._migrate_google_entity_settings_v1()
await self._prefs.async_update(
google_settings_version=GOOGLE_SETTINGS_VERSION
)
async_listen_entity_updates(
self.hass, CLOUD_GOOGLE, self._async_exposed_entities_updated
)
async def hass_started(hass):
async def on_hass_start(hass: HomeAssistant) -> None:
if self.enabled and GOOGLE_DOMAIN not in self.hass.config.components:
await async_setup_component(self.hass, GOOGLE_DOMAIN, {})
start.async_at_start(self.hass, hass_started)
start.async_at_start(self.hass, on_hass_start)
start.async_at_started(self.hass, on_hass_started)
# Remove any stored user agent id that is not ours
remove_agent_user_ids = []
@@ -140,9 +237,6 @@ class CloudGoogleConfig(AbstractConfig):
await self.async_disconnect_agent_user(agent_user_id)
self._prefs.async_listen_updates(self._async_prefs_updated)
async_listen_entity_updates(
self.hass, CLOUD_GOOGLE, self._async_exposed_entities_updated
)
self.hass.bus.async_listen(
er.EVENT_ENTITY_REGISTRY_UPDATED,
self._handle_entity_registry_updated,
@@ -180,9 +274,13 @@ class CloudGoogleConfig(AbstractConfig):
# Backwards compat
if default_expose is None:
return not auxiliary_entity
return not auxiliary_entity and _supported_legacy(self.hass, entity_id)
return not auxiliary_entity and split_entity_id(entity_id)[0] in default_expose
return (
not auxiliary_entity
and split_entity_id(entity_id)[0] in default_expose
and _supported_legacy(self.hass, entity_id)
)
def _should_expose_entity_id(self, entity_id):
"""If an entity should be exposed."""
@@ -215,14 +313,13 @@ class CloudGoogleConfig(AbstractConfig):
def should_2fa(self, state):
"""If an entity should be checked for 2FA."""
entity_registry = er.async_get(self.hass)
registry_entry = entity_registry.async_get(state.entity_id)
if not registry_entry:
try:
settings = async_get_entity_settings(self.hass, state.entity_id)
except HomeAssistantError:
# Handle the entity has been removed
return False
assistant_options = registry_entry.options.get(CLOUD_GOOGLE, {})
assistant_options = settings.get(CLOUD_GOOGLE, {})
return not assistant_options.get(PREF_DISABLE_2FA, DEFAULT_DISABLE_2FA)
async def async_report_state(self, message, agent_user_id: str):
@@ -308,7 +405,7 @@ class CloudGoogleConfig(AbstractConfig):
self.async_schedule_google_sync_all()
@callback
def _handle_device_registry_updated(self, event: Event) -> None:
async def _handle_device_registry_updated(self, event: Event) -> None:
"""Handle when device registry updated."""
if (
not self.enabled
+58 -28
View File
@@ -1,6 +1,7 @@
"""The HTTP api to control the cloud integration."""
import asyncio
from collections.abc import Mapping
from contextlib import suppress
import dataclasses
from functools import wraps
from http import HTTPStatus
@@ -21,14 +22,16 @@ from homeassistant.components.alexa import (
errors as alexa_errors,
)
from homeassistant.components.google_assistant import helpers as google_helpers
from homeassistant.components.homeassistant import exposed_entities
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.util.location import async_detect_location_info
from .alexa_config import entity_supported as entity_supported_by_alexa
from .const import (
DOMAIN,
PREF_ALEXA_REPORT_STATE,
@@ -73,6 +76,7 @@ async def async_setup(hass):
websocket_api.async_register_command(hass, google_assistant_list)
websocket_api.async_register_command(hass, google_assistant_update)
websocket_api.async_register_command(hass, alexa_get)
websocket_api.async_register_command(hass, alexa_list)
websocket_api.async_register_command(hass, alexa_sync)
@@ -198,12 +202,16 @@ class CloudLoginView(HomeAssistantView):
cloud = hass.data[DOMAIN]
await cloud.login(data["email"], data["password"])
if (cloud_pipeline_id := cloud_assist_pipeline(hass)) is None:
# Make sure the pipeline store is loaded, needed because assist_pipeline
# is an after dependency of cloud
await assist_pipeline.async_setup_pipeline_store(hass)
new_cloud_pipeline_id: str | None = None
if (cloud_assist_pipeline(hass)) is None:
if cloud_pipeline := await assist_pipeline.async_create_default_pipeline(
hass, DOMAIN, DOMAIN
):
cloud_pipeline_id = cloud_pipeline.id
return self.json({"success": True, "cloud_pipeline": cloud_pipeline_id})
new_cloud_pipeline_id = cloud_pipeline.id
return self.json({"success": True, "cloud_pipeline": new_cloud_pipeline_id})
class CloudLogoutView(HomeAssistantView):
@@ -560,15 +568,14 @@ async def google_assistant_get(
"""Get data for a single google assistant entity."""
cloud = hass.data[DOMAIN]
gconf = await cloud.client.get_google_config()
entity_registry = er.async_get(hass)
entity_id: str = msg["entity_id"]
state = hass.states.get(entity_id)
if not entity_registry.async_is_registered(entity_id) or not state:
if not state:
connection.send_error(
msg["id"],
websocket_api.const.ERR_NOT_FOUND,
f"{entity_id} unknown or not in the entity registry",
f"{entity_id} unknown",
)
return
@@ -581,10 +588,16 @@ async def google_assistant_get(
)
return
assistant_options: Mapping[str, Any] = {}
with suppress(HomeAssistantError, KeyError):
settings = exposed_entities.async_get_entity_settings(hass, entity_id)
assistant_options = settings[CLOUD_GOOGLE]
result = {
"entity_id": entity.entity_id,
"traits": [trait.name for trait in entity.traits()],
"might_2fa": entity.might_2fa_traits(),
PREF_DISABLE_2FA: assistant_options.get(PREF_DISABLE_2FA),
}
connection.send_result(msg["id"], result)
@@ -603,14 +616,11 @@ async def google_assistant_list(
"""List all google assistant entities."""
cloud = hass.data[DOMAIN]
gconf = await cloud.client.get_google_config()
entity_registry = er.async_get(hass)
entities = google_helpers.async_get_entities(hass, gconf)
result = []
for entity in entities:
if not entity_registry.async_is_registered(entity.entity_id):
continue
result.append(
{
"entity_id": entity.entity_id,
@@ -639,28 +649,51 @@ async def google_assistant_update(
msg: dict[str, Any],
) -> None:
"""Update google assistant entity config."""
entity_registry = er.async_get(hass)
entity_id: str = msg["entity_id"]
if not (registry_entry := entity_registry.async_get(entity_id)):
assistant_options: Mapping[str, Any] = {}
with suppress(HomeAssistantError, KeyError):
settings = exposed_entities.async_get_entity_settings(hass, entity_id)
assistant_options = settings[CLOUD_GOOGLE]
disable_2fa = msg[PREF_DISABLE_2FA]
if assistant_options.get(PREF_DISABLE_2FA) == disable_2fa:
return
exposed_entities.async_set_assistant_option(
hass, CLOUD_GOOGLE, entity_id, PREF_DISABLE_2FA, disable_2fa
)
connection.send_result(msg["id"])
@websocket_api.require_admin
@_require_cloud_login
@websocket_api.websocket_command(
{
"type": "cloud/alexa/entities/get",
"entity_id": str,
}
)
@websocket_api.async_response
@_ws_handle_cloud_errors
async def alexa_get(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,
msg: dict[str, Any],
) -> None:
"""Get data for a single alexa entity."""
entity_id: str = msg["entity_id"]
if entity_id in CLOUD_NEVER_EXPOSED_ENTITIES or not entity_supported_by_alexa(
hass, entity_id
):
connection.send_error(
msg["id"],
websocket_api.const.ERR_NOT_ALLOWED,
f"can't configure {entity_id}",
websocket_api.const.ERR_NOT_SUPPORTED,
f"{entity_id} not supported by Alexa",
)
return
disable_2fa = msg[PREF_DISABLE_2FA]
assistant_options: Mapping[str, Any]
if (
assistant_options := registry_entry.options.get(CLOUD_GOOGLE, {})
) and assistant_options.get(PREF_DISABLE_2FA) == disable_2fa:
return
assistant_options = assistant_options | {PREF_DISABLE_2FA: disable_2fa}
entity_registry.async_update_entity_options(
entity_id, CLOUD_GOOGLE, assistant_options
)
connection.send_result(msg["id"])
@@ -677,14 +710,11 @@ async def alexa_list(
"""List all alexa entities."""
cloud = hass.data[DOMAIN]
alexa_config = await cloud.client.get_alexa_config()
entity_registry = er.async_get(hass)
entities = alexa_entities.async_get_entities(hass, alexa_config)
result = []
for entity in entities:
if not entity_registry.async_is_registered(entity.entity_id):
continue
result.append(
{
"entity_id": entity.entity_id,
+2 -2
View File
@@ -1,9 +1,9 @@
{
"domain": "cloud",
"name": "Home Assistant Cloud",
"after_dependencies": ["google_assistant", "alexa"],
"after_dependencies": ["assist_pipeline", "google_assistant", "alexa"],
"codeowners": ["@home-assistant/cloud"],
"dependencies": ["assist_pipeline", "homeassistant", "http", "webhook"],
"dependencies": ["homeassistant", "http", "webhook"],
"documentation": "https://www.home-assistant.io/integrations/cloud",
"integration_type": "system",
"iot_class": "cloud_push",
+2 -2
View File
@@ -41,8 +41,8 @@ STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1
STORAGE_VERSION_MINOR = 2
ALEXA_SETTINGS_VERSION = 2
GOOGLE_SETTINGS_VERSION = 2
ALEXA_SETTINGS_VERSION = 3
GOOGLE_SETTINGS_VERSION = 3
class CloudPreferencesStore(Store):
@@ -23,7 +23,7 @@ from homeassistant.util import language as language_util
from .agent import AbstractConversationAgent, ConversationInput, ConversationResult
from .const import HOME_ASSISTANT_AGENT
from .default_agent import DefaultAgent
from .default_agent import DefaultAgent, async_setup as async_setup_default_agent
__all__ = [
"DOMAIN",
@@ -93,7 +93,9 @@ CONFIG_SCHEMA = vol.Schema(
@core.callback
def _get_agent_manager(hass: HomeAssistant) -> AgentManager:
"""Get the active agent."""
return AgentManager(hass)
manager = AgentManager(hass)
manager.async_setup()
return manager
@core.callback
@@ -389,7 +391,11 @@ class AgentManager:
"""Initialize the conversation agents."""
self.hass = hass
self._agents: dict[str, AbstractConversationAgent] = {}
self._default_agent_init_lock = asyncio.Lock()
self._builtin_agent_init_lock = asyncio.Lock()
def async_setup(self) -> None:
"""Set up the conversation agents."""
async_setup_default_agent(self.hass)
async def async_get_agent(
self, agent_id: str | None = None
@@ -402,7 +408,7 @@ class AgentManager:
if self._builtin_agent is not None:
return self._builtin_agent
async with self._default_agent_init_lock:
async with self._builtin_agent_init_lock:
if self._builtin_agent is not None:
return self._builtin_agent
@@ -1,4 +1,5 @@
"""Const for conversation integration."""
DOMAIN = "conversation"
DEFAULT_EXPOSED_ATTRIBUTES = {"device_class"}
HOME_ASSISTANT_AGENT = "homeassistant"
@@ -21,19 +21,21 @@ from homeassistant.components.homeassistant.exposed_entities import (
async_listen_entity_updates,
async_should_expose,
)
from homeassistant.const import ATTR_DEVICE_CLASS
from homeassistant.const import MATCH_ALL
from homeassistant.helpers import (
area_registry as ar,
device_registry as dr,
entity_registry as er,
intent,
start,
template,
translation,
)
from homeassistant.helpers.event import async_track_state_change
from homeassistant.util.json import JsonObjectType, json_loads_object
from .agent import AbstractConversationAgent, ConversationInput, ConversationResult
from .const import DOMAIN
from .const import DEFAULT_EXPOSED_ATTRIBUTES, DOMAIN
_LOGGER = logging.getLogger(__name__)
_DEFAULT_ERROR_TEXT = "Sorry, I couldn't understand that"
@@ -73,6 +75,34 @@ def _get_language_variations(language: str) -> Iterable[str]:
yield lang
@core.callback
def async_setup(hass: core.HomeAssistant) -> None:
"""Set up entity registry listener for the default agent."""
entity_registry = er.async_get(hass)
for entity_id in entity_registry.entities:
async_should_expose(hass, DOMAIN, entity_id)
@core.callback
def async_entity_state_listener(
changed_entity: str,
old_state: core.State | None,
new_state: core.State | None,
):
"""Set expose flag on new entities."""
if old_state is not None or new_state is None:
return
async_should_expose(hass, DOMAIN, changed_entity)
@core.callback
def async_hass_started(hass: core.HomeAssistant) -> None:
"""Set expose flag on all entities."""
for state in hass.states.async_all():
async_should_expose(hass, DOMAIN, state.entity_id)
async_track_state_change(hass, MATCH_ALL, async_entity_state_listener)
start.async_at_started(hass, async_hass_started)
class DefaultAgent(AbstractConversationAgent):
"""Default agent for conversation agent."""
@@ -110,6 +140,11 @@ class DefaultAgent(AbstractConversationAgent):
self._async_handle_entity_registry_changed,
run_immediately=True,
)
self.hass.bus.async_listen(
core.EVENT_STATE_CHANGED,
self._async_handle_state_changed,
run_immediately=True,
)
async_listen_entity_updates(
self.hass, DOMAIN, self._async_exposed_entities_updated
)
@@ -166,6 +201,7 @@ class DefaultAgent(AbstractConversationAgent):
user_input.text,
user_input.context,
language,
assistant=DOMAIN,
)
except intent.IntentHandleError:
_LOGGER.exception("Intent handling error")
@@ -455,12 +491,19 @@ class DefaultAgent(AbstractConversationAgent):
@core.callback
def _async_handle_entity_registry_changed(self, event: core.Event) -> None:
"""Clear names list cache when an entity registry entry has changed."""
if event.data["action"] == "update" and not any(
if event.data["action"] != "update" or not any(
field in event.data["changes"] for field in _ENTITY_REGISTRY_UPDATE_FIELDS
):
return
self._slot_lists = None
@core.callback
def _async_handle_state_changed(self, event: core.Event) -> None:
"""Clear names list cache when a state is added or removed from the state machine."""
if event.data.get("old_state") and event.data.get("new_state"):
return
self._slot_lists = None
@core.callback
def _async_exposed_entities_updated(self) -> None:
"""Handle updated preferences."""
@@ -472,31 +515,39 @@ class DefaultAgent(AbstractConversationAgent):
return self._slot_lists
area_ids_with_entities: set[str] = set()
all_entities = er.async_get(self.hass)
entities = [
entity
for entity in all_entities.entities.values()
if async_should_expose(self.hass, DOMAIN, entity.entity_id)
entity_registry = er.async_get(self.hass)
states = [
state
for state in self.hass.states.async_all()
if async_should_expose(self.hass, DOMAIN, state.entity_id)
]
devices = dr.async_get(self.hass)
# Gather exposed entity names
entity_names = []
for entity in entities:
for state in states:
# Checked against "requires_context" and "excludes_context" in hassil
context = {"domain": entity.domain}
if entity.device_class:
context[ATTR_DEVICE_CLASS] = entity.device_class
context = {"domain": state.domain}
if state.attributes:
# Include some attributes
for attr in DEFAULT_EXPOSED_ATTRIBUTES:
if attr not in state.attributes:
continue
context[attr] = state.attributes[attr]
entity = entity_registry.async_get(state.entity_id)
if not entity:
# Default name
entity_names.append((state.name, state.name, context))
continue
if entity.aliases:
for alias in entity.aliases:
entity_names.append((alias, alias, context))
# Default name
name = entity.async_friendly_name(self.hass) or entity.entity_id.replace(
"_", " "
)
entity_names.append((name, name, context))
entity_names.append((state.name, state.name, context))
if entity.area_id:
# Expose area too
@@ -7,5 +7,5 @@
"integration_type": "system",
"iot_class": "local_push",
"quality_scale": "internal",
"requirements": ["hassil==1.0.6", "home-assistant-intents==2023.4.17-1"]
"requirements": ["hassil==1.0.6", "home-assistant-intents==2023.4.26"]
}
@@ -29,7 +29,10 @@ from homeassistant.helpers import (
)
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import IntegrationNotFound
from homeassistant.requirements import async_get_integration_with_requirements
from homeassistant.requirements import (
RequirementsNotFound,
async_get_integration_with_requirements,
)
from .const import ( # noqa: F401
CONF_IS_OFF,
@@ -171,6 +174,10 @@ async def async_get_device_automation_platform(
raise InvalidDeviceAutomationConfig(
f"Integration '{domain}' not found"
) from err
except RequirementsNotFound as err:
raise InvalidDeviceAutomationConfig(
f"Integration '{domain}' could not be loaded"
) from err
except ImportError as err:
raise InvalidDeviceAutomationConfig(
f"Integration '{domain}' does not support device automation "
@@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/eddystone_temperature",
"iot_class": "local_polling",
"loggers": ["beacontools"],
"requirements": ["beacontools[scan]==1.2.3", "construct==2.10.56"]
"requirements": ["beacontools[scan]==2.1.0", "construct==2.10.56"]
}
+1 -1
View File
@@ -15,5 +15,5 @@
"documentation": "https://www.home-assistant.io/integrations/elkm1",
"iot_class": "local_push",
"loggers": ["elkm1_lib"],
"requirements": ["elkm1-lib==2.2.1"]
"requirements": ["elkm1-lib==2.2.2"]
}
@@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/environment_canada",
"iot_class": "cloud_polling",
"loggers": ["env_canada"],
"requirements": ["env_canada==0.5.33"]
"requirements": ["env_canada==0.5.34"]
}
+18 -11
View File
@@ -288,39 +288,46 @@ async def async_setup_entry( # noqa: C901
voice_assistant_udp_server: VoiceAssistantUDPServer | None = None
def handle_pipeline_event(
def _handle_pipeline_event(
event_type: VoiceAssistantEventType, data: dict[str, str] | None
) -> None:
"""Handle a voice assistant pipeline event."""
cli.send_voice_assistant_event(event_type, data)
async def handle_pipeline_start() -> int | None:
def _handle_pipeline_finished() -> None:
nonlocal voice_assistant_udp_server
entry_data.async_set_assist_pipeline_state(False)
if voice_assistant_udp_server is not None:
voice_assistant_udp_server.close()
voice_assistant_udp_server = None
async def _handle_pipeline_start() -> int | None:
"""Start a voice assistant pipeline."""
nonlocal voice_assistant_udp_server
if voice_assistant_udp_server is not None:
return None
voice_assistant_udp_server = VoiceAssistantUDPServer(hass)
voice_assistant_udp_server = VoiceAssistantUDPServer(
hass, entry_data, _handle_pipeline_event, _handle_pipeline_finished
)
port = await voice_assistant_udp_server.start_server()
hass.async_create_background_task(
voice_assistant_udp_server.run_pipeline(handle_pipeline_event),
voice_assistant_udp_server.run_pipeline(),
"esphome.voice_assistant_udp_server.run_pipeline",
)
entry_data.async_set_assist_pipeline_state(True)
return port
async def handle_pipeline_stop() -> None:
async def _handle_pipeline_stop() -> None:
"""Stop a voice assistant pipeline."""
nonlocal voice_assistant_udp_server
entry_data.async_set_assist_pipeline_state(False)
if voice_assistant_udp_server is not None:
voice_assistant_udp_server.stop()
voice_assistant_udp_server = None
async def on_connect() -> None:
"""Subscribe to states and list entities on successful API login."""
@@ -369,8 +376,8 @@ async def async_setup_entry( # noqa: C901
if device_info.voice_assistant_version:
entry_data.disconnect_callbacks.append(
await cli.subscribe_voice_assistant(
handle_pipeline_start,
handle_pipeline_stop,
_handle_pipeline_start,
_handle_pipeline_stop,
)
)
@@ -34,7 +34,7 @@ async def async_setup_entry(
entry_data = DomainData.get(hass).get_entry_data(entry)
assert entry_data.device_info is not None
if entry_data.device_info.voice_assistant_version:
async_add_entities([EsphomeCallActiveBinarySensor(entry_data)])
async_add_entities([EsphomeAssistInProgressBinarySensor(entry_data)])
class EsphomeBinarySensor(
@@ -68,12 +68,12 @@ class EsphomeBinarySensor(
return super().available
class EsphomeCallActiveBinarySensor(EsphomeAssistEntity, BinarySensorEntity):
class EsphomeAssistInProgressBinarySensor(EsphomeAssistEntity, BinarySensorEntity):
"""A binary sensor implementation for ESPHome for use with assist_pipeline."""
entity_description = BinarySensorEntityDescription(
key="call_active",
translation_key="call_active",
key="assist_in_progress",
translation_key="assist_in_progress",
)
@property
+12 -2
View File
@@ -25,6 +25,7 @@ from aioesphomeapi import (
NumberInfo,
SelectInfo,
SensorInfo,
SensorState,
SwitchInfo,
TextSensorInfo,
UserService,
@@ -240,9 +241,18 @@ class RuntimeEntryData:
current_state_by_type = self.state[state_type]
current_state = current_state_by_type.get(key, _SENTINEL)
subscription_key = (state_type, key)
if current_state == state and subscription_key not in stale_state:
if (
current_state == state
and subscription_key not in stale_state
and not (
type(state) is SensorState # pylint: disable=unidiomatic-typecheck
and (platform_info := self.info.get(Platform.SENSOR))
and (entity_info := platform_info.get(state.key))
and (cast(SensorInfo, entity_info)).force_update
)
):
_LOGGER.debug(
"%s: ignoring duplicate update with and key %s: %s",
"%s: ignoring duplicate update with key %s: %s",
self.name,
key,
state,
@@ -15,7 +15,7 @@
"iot_class": "local_push",
"loggers": ["aioesphomeapi", "noiseprotocol"],
"requirements": [
"aioesphomeapi==13.7.2",
"aioesphomeapi==13.7.4",
"bluetooth-data-tools==0.4.0",
"esphome-dashboard-api==1.2.3"
],
@@ -48,8 +48,8 @@
},
"entity": {
"binary_sensor": {
"call_active": {
"name": "Call Active"
"assist_in_progress": {
"name": "[%key:component::assist_pipeline::entity::binary_sensor::assist_in_progress::name%]"
}
},
"select": {
+24 -19
View File
@@ -13,7 +13,7 @@ from homeassistant.components.update import (
UpdateEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo
@@ -33,35 +33,36 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up ESPHome update based on a config entry."""
dashboard = async_get_dashboard(hass)
if dashboard is None:
if (dashboard := async_get_dashboard(hass)) is None:
return
entry_data = DomainData.get(hass).get_entry_data(entry)
unsub = None
unsubs: list[CALLBACK_TYPE] = []
async def setup_update_entity() -> None:
@callback
def _async_setup_update_entity() -> None:
"""Set up the update entity."""
nonlocal unsub
nonlocal unsubs
assert dashboard is not None
# Keep listening until device is available
if not entry_data.available:
if not entry_data.available or not dashboard.last_update_success:
return
if unsub is not None:
unsub() # type: ignore[unreachable]
for unsub in unsubs:
unsub()
unsubs.clear()
assert dashboard is not None
async_add_entities([ESPHomeUpdateEntity(entry_data, dashboard)])
if entry_data.available:
await setup_update_entity()
if entry_data.available and dashboard.last_update_success:
_async_setup_update_entity()
return
unsub = async_dispatcher_connect(
hass, entry_data.signal_device_updated, setup_update_entity
)
unsubs = [
async_dispatcher_connect(
hass, entry_data.signal_device_updated, _async_setup_update_entity
),
dashboard.async_add_listener(_async_setup_update_entity),
]
class ESPHomeUpdateEntity(CoordinatorEntity[ESPHomeDashboard], UpdateEntity):
@@ -88,7 +89,11 @@ class ESPHomeUpdateEntity(CoordinatorEntity[ESPHomeDashboard], UpdateEntity):
# If the device has deep sleep, we can't assume we can install updates
# as the ESP will not be connectable (by design).
if coordinator.supports_update and not self._device_info.has_deep_sleep:
if (
coordinator.last_update_success
and coordinator.supports_update
and not self._device_info.has_deep_sleep
):
self._attr_supported_features = UpdateEntityFeature.INSTALL
@property
@@ -8,21 +8,26 @@ import socket
from typing import cast
from aioesphomeapi import VoiceAssistantEventType
import async_timeout
from homeassistant.components import stt
from homeassistant.components import stt, tts
from homeassistant.components.assist_pipeline import (
PipelineEvent,
PipelineEventType,
async_pipeline_from_audio_stream,
select as pipeline_select,
)
from homeassistant.components.media_player import async_process_play_media_url
from homeassistant.core import Context, HomeAssistant, callback
from .const import DOMAIN
from .entry_data import RuntimeEntryData
from .enum_mapper import EsphomeEnumMapper
_LOGGER = logging.getLogger(__name__)
UDP_PORT = 0 # Set to 0 to let the OS pick a free random port
UDP_MAX_PACKET_SIZE = 1024
_VOICE_ASSISTANT_EVENT_TYPES: EsphomeEnumMapper[
VoiceAssistantEventType, PipelineEventType
@@ -47,12 +52,26 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
started = False
queue: asyncio.Queue[bytes] | None = None
transport: asyncio.DatagramTransport | None = None
remote_addr: tuple[str, int] | None = None
def __init__(self, hass: HomeAssistant) -> None:
def __init__(
self,
hass: HomeAssistant,
entry_data: RuntimeEntryData,
handle_event: Callable[[VoiceAssistantEventType, dict[str, str] | None], None],
handle_finished: Callable[[], None],
) -> None:
"""Initialize UDP receiver."""
self.context = Context()
self.hass = hass
assert entry_data.device_info is not None
self.device_info = entry_data.device_info
self.queue = asyncio.Queue()
self.handle_event = handle_event
self.handle_finished = handle_finished
self._tts_done = asyncio.Event()
async def start_server(self) -> int:
"""Start accepting connections."""
@@ -86,6 +105,10 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
@callback
def datagram_received(self, data: bytes, addr: tuple[str, int]) -> None:
"""Handle incoming UDP packet."""
if not self.started:
return
if self.remote_addr is None:
self.remote_addr = addr
if self.queue is not None:
self.queue.put_nowait(data)
@@ -95,12 +118,18 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
(Other than BlockingIOError or InterruptedError.)
"""
_LOGGER.error("ESPHome Voice Assistant UDP server error received: %s", exc)
self.handle_finished()
@callback
def stop(self) -> None:
"""Stop the receiver."""
if self.queue is not None:
self.queue.put_nowait(b"")
self.started = False
def close(self) -> None:
"""Close the receiver."""
if self.queue is not None:
self.queue = None
if self.transport is not None:
self.transport.close()
@@ -113,54 +142,112 @@ class VoiceAssistantUDPServer(asyncio.DatagramProtocol):
while data := await self.queue.get():
yield data
def _event_callback(self, event: PipelineEvent) -> None:
"""Handle pipeline events."""
try:
event_type = _VOICE_ASSISTANT_EVENT_TYPES.from_hass(event.type)
except KeyError:
_LOGGER.warning("Received unknown pipeline event type: %s", event.type)
return
data_to_send = None
if event_type == VoiceAssistantEventType.VOICE_ASSISTANT_STT_END:
assert event.data is not None
data_to_send = {"text": event.data["stt_output"]["text"]}
elif event_type == VoiceAssistantEventType.VOICE_ASSISTANT_TTS_START:
assert event.data is not None
data_to_send = {"text": event.data["tts_input"]}
elif event_type == VoiceAssistantEventType.VOICE_ASSISTANT_TTS_END:
assert event.data is not None
path = event.data["tts_output"]["url"]
url = async_process_play_media_url(self.hass, path)
data_to_send = {"url": url}
if self.device_info.voice_assistant_version >= 2:
media_id = event.data["tts_output"]["media_id"]
self.hass.async_create_background_task(
self._send_tts(media_id), "esphome_voice_assistant_tts"
)
else:
self._tts_done.set()
elif event_type == VoiceAssistantEventType.VOICE_ASSISTANT_ERROR:
assert event.data is not None
data_to_send = {
"code": event.data["code"],
"message": event.data["message"],
}
self.handle_finished()
self.handle_event(event_type, data_to_send)
async def run_pipeline(
self,
handle_event: Callable[[VoiceAssistantEventType, dict[str, str] | None], None],
pipeline_timeout: float = 30.0,
) -> None:
"""Run the Voice Assistant pipeline."""
try:
tts_audio_output = (
"raw" if self.device_info.voice_assistant_version >= 2 else "mp3"
)
async with async_timeout.timeout(pipeline_timeout):
await async_pipeline_from_audio_stream(
self.hass,
context=self.context,
event_callback=self._event_callback,
stt_metadata=stt.SpeechMetadata(
language="", # set in async_pipeline_from_audio_stream
format=stt.AudioFormats.WAV,
codec=stt.AudioCodecs.PCM,
bit_rate=stt.AudioBitRates.BITRATE_16,
sample_rate=stt.AudioSampleRates.SAMPLERATE_16000,
channel=stt.AudioChannels.CHANNEL_MONO,
),
stt_stream=self._iterate_packets(),
pipeline_id=pipeline_select.get_chosen_pipeline(
self.hass, DOMAIN, self.device_info.mac_address
),
tts_audio_output=tts_audio_output,
)
@callback
def handle_pipeline_event(event: PipelineEvent) -> None:
"""Handle pipeline events."""
# Block until TTS is done sending
await self._tts_done.wait()
try:
event_type = _VOICE_ASSISTANT_EVENT_TYPES.from_hass(event.type)
except KeyError:
_LOGGER.warning("Received unknown pipeline event type: %s", event.type)
_LOGGER.debug("Pipeline finished")
except asyncio.TimeoutError:
_LOGGER.warning("Pipeline timeout")
finally:
self.handle_finished()
async def _send_tts(self, media_id: str) -> None:
"""Send TTS audio to device via UDP."""
try:
if self.transport is None:
return
data_to_send = None
if event_type == VoiceAssistantEventType.VOICE_ASSISTANT_STT_END:
assert event.data is not None
data_to_send = {"text": event.data["stt_output"]["text"]}
elif event_type == VoiceAssistantEventType.VOICE_ASSISTANT_TTS_START:
assert event.data is not None
data_to_send = {"text": event.data["tts_input"]}
elif event_type == VoiceAssistantEventType.VOICE_ASSISTANT_TTS_END:
assert event.data is not None
path = event.data["tts_output"]["url"]
url = async_process_play_media_url(self.hass, path)
data_to_send = {"url": url}
elif event_type == VoiceAssistantEventType.VOICE_ASSISTANT_ERROR:
assert event.data is not None
data_to_send = {
"code": event.data["code"],
"message": event.data["message"],
}
_extension, audio_bytes = await tts.async_get_media_source_audio(
self.hass,
media_id,
)
handle_event(event_type, data_to_send)
_LOGGER.debug("Sending %d bytes of audio", len(audio_bytes))
await async_pipeline_from_audio_stream(
self.hass,
context=self.context,
event_callback=handle_pipeline_event,
stt_metadata=stt.SpeechMetadata(
language="",
format=stt.AudioFormats.WAV,
codec=stt.AudioCodecs.PCM,
bit_rate=stt.AudioBitRates.BITRATE_16,
sample_rate=stt.AudioSampleRates.SAMPLERATE_16000,
channel=stt.AudioChannels.CHANNEL_MONO,
),
stt_stream=self._iterate_packets(),
)
bytes_per_sample = stt.AudioBitRates.BITRATE_16 // 8
sample_offset = 0
samples_left = len(audio_bytes) // bytes_per_sample
while samples_left > 0:
bytes_offset = sample_offset * bytes_per_sample
chunk: bytes = audio_bytes[bytes_offset : bytes_offset + 1024]
samples_in_chunk = len(chunk) // bytes_per_sample
samples_left -= samples_in_chunk
self.transport.sendto(chunk, self.remote_addr)
await asyncio.sleep(
samples_in_chunk / stt.AudioSampleRates.SAMPLERATE_16000 * 0.99
)
sample_offset += samples_in_chunk
finally:
self._tts_done.set()
+1 -1
View File
@@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/eufy",
"iot_class": "local_polling",
"loggers": ["lakeside"],
"requirements": ["lakeside==0.12"]
"requirements": ["lakeside==0.13"]
}
+9 -2
View File
@@ -236,11 +236,18 @@ class SensorFilter(SensorEntity):
self.async_write_ha_state()
return
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
self._state = new_state.state
if new_state.state == STATE_UNKNOWN:
self._state = None
self.async_write_ha_state()
return
if new_state.state == STATE_UNAVAILABLE:
self._attr_available = False
self.async_write_ha_state()
return
self._attr_available = True
temp_state = _State(new_state.last_updated, new_state.state)
try:
@@ -28,6 +28,15 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = (
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=1,
),
ForecastSolarSensorEntityDescription(
key="energy_production_today_remaining",
name="Estimated energy production - remaining today",
state=lambda estimate: estimate.energy_production_today_remaining,
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=1,
),
ForecastSolarSensorEntityDescription(
key="energy_production_tomorrow",
name="Estimated energy production - tomorrow",
@@ -34,6 +34,7 @@ async def async_get_config_entry_diagnostics(
},
"data": {
"energy_production_today": coordinator.data.energy_production_today,
"energy_production_today_remaining": coordinator.data.energy_production_today_remaining,
"energy_production_tomorrow": coordinator.data.energy_production_tomorrow,
"energy_current_hour": coordinator.data.energy_current_hour,
"power_production_now": coordinator.data.power_production_now,
@@ -80,7 +80,10 @@ class FritzBoxBinarySensor(FritzBoxBaseCoordinatorEntity, BinarySensorEntity):
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
if isinstance(
state := self.coordinator.data.get(self.entity_description.key), bool
state := self.coordinator.data["entity_states"].get(
self.entity_description.key
),
bool,
):
return state
return None
+45 -19
View File
@@ -19,6 +19,7 @@ from fritzconnection.core.exceptions import (
from fritzconnection.lib.fritzhosts import FritzHosts
from fritzconnection.lib.fritzstatus import FritzStatus
from fritzconnection.lib.fritzwlan import DEFAULT_PASSWORD_LENGTH, FritzGuestWLAN
import xmltodict
from homeassistant.components.device_tracker import (
CONF_CONSIDER_HOME,
@@ -137,8 +138,15 @@ class HostInfo(TypedDict):
status: bool
class UpdateCoordinatorDataType(TypedDict):
"""Update coordinator data type."""
call_deflections: dict[int, dict]
entity_states: dict[str, StateType | bool]
class FritzBoxTools(
update_coordinator.DataUpdateCoordinator[dict[str, bool | StateType]]
update_coordinator.DataUpdateCoordinator[UpdateCoordinatorDataType]
):
"""FritzBoxTools class."""
@@ -173,6 +181,7 @@ class FritzBoxTools(
self.password = password
self.port = port
self.username = username
self.has_call_deflections: bool = False
self._model: str | None = None
self._current_firmware: str | None = None
self._latest_firmware: str | None = None
@@ -243,6 +252,8 @@ class FritzBoxTools(
)
self.device_is_router = self.fritz_status.has_wan_enabled
self.has_call_deflections = "X_AVM-DE_OnTel1" in self.connection.services
def register_entity_updates(
self, key: str, update_fn: Callable[[FritzStatus, StateType], Any]
) -> Callable[[], None]:
@@ -259,20 +270,30 @@ class FritzBoxTools(
self._entity_update_functions[key] = update_fn
return unregister_entity_updates
async def _async_update_data(self) -> dict[str, bool | StateType]:
async def _async_update_data(self) -> UpdateCoordinatorDataType:
"""Update FritzboxTools data."""
enity_data: dict[str, bool | StateType] = {}
entity_data: UpdateCoordinatorDataType = {
"call_deflections": {},
"entity_states": {},
}
try:
await self.async_scan_devices()
for key, update_fn in self._entity_update_functions.items():
_LOGGER.debug("update entity %s", key)
enity_data[key] = await self.hass.async_add_executor_job(
update_fn, self.fritz_status, self.data.get(key)
entity_data["entity_states"][
key
] = await self.hass.async_add_executor_job(
update_fn, self.fritz_status, self.data["entity_states"].get(key)
)
if self.has_call_deflections:
entity_data[
"call_deflections"
] = await self.async_update_call_deflections()
except FRITZ_EXCEPTIONS as ex:
raise update_coordinator.UpdateFailed(ex) from ex
_LOGGER.debug("enity_data: %s", enity_data)
return enity_data
_LOGGER.debug("enity_data: %s", entity_data)
return entity_data
@property
def unique_id(self) -> str:
@@ -354,6 +375,23 @@ class FritzBoxTools(
"""Retrieve latest device information from the FRITZ!Box."""
return await self.hass.async_add_executor_job(self._update_device_info)
async def async_update_call_deflections(
self,
) -> dict[int, dict[str, Any]]:
"""Call GetDeflections action from X_AVM-DE_OnTel service."""
raw_data = await self.hass.async_add_executor_job(
partial(self.connection.call_action, "X_AVM-DE_OnTel1", "GetDeflections")
)
if not raw_data:
return {}
xml_data = xmltodict.parse(raw_data["NewDeflectionList"])
if xml_data.get("List") and (items := xml_data["List"].get("Item")) is not None:
if not isinstance(items, list):
items = [items]
return {int(item["DeflectionId"]): item for item in items}
return {}
async def _async_get_wan_access(self, ip_address: str) -> bool | None:
"""Get WAN access rule for given IP address."""
try:
@@ -772,18 +810,6 @@ class AvmWrapper(FritzBoxTools):
"WLANConfiguration", str(index), "GetInfo"
)
async def async_get_ontel_num_deflections(self) -> dict[str, Any]:
"""Call GetNumberOfDeflections action from X_AVM-DE_OnTel service."""
return await self._async_service_call(
"X_AVM-DE_OnTel", "1", "GetNumberOfDeflections"
)
async def async_get_ontel_deflections(self) -> dict[str, Any]:
"""Call GetDeflections action from X_AVM-DE_OnTel service."""
return await self._async_service_call("X_AVM-DE_OnTel", "1", "GetDeflections")
async def async_set_wlan_configuration(
self, index: int, turn_on: bool
) -> dict[str, Any]:
+1 -1
View File
@@ -309,4 +309,4 @@ class FritzBoxSensor(FritzBoxBaseCoordinatorEntity, SensorEntity):
@property
def native_value(self) -> StateType:
"""Return the value reported by the sensor."""
return self.coordinator.data.get(self.entity_description.key)
return self.coordinator.data["entity_states"].get(self.entity_description.key)
+92 -72
View File
@@ -4,10 +4,8 @@ from __future__ import annotations
import logging
from typing import Any
import xmltodict
from homeassistant.components.network import async_get_source_ip
from homeassistant.components.switch import SwitchEntity
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback
@@ -15,6 +13,7 @@ from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import slugify
from .common import (
@@ -47,31 +46,15 @@ async def _async_deflection_entities_list(
_LOGGER.debug("Setting up %s switches", SWITCH_TYPE_DEFLECTION)
deflections_response = await avm_wrapper.async_get_ontel_num_deflections()
if not deflections_response:
if (
call_deflections := avm_wrapper.data.get("call_deflections")
) is None or not isinstance(call_deflections, dict):
_LOGGER.debug("The FRITZ!Box has no %s options", SWITCH_TYPE_DEFLECTION)
return []
_LOGGER.debug(
"Specific %s response: GetNumberOfDeflections=%s",
SWITCH_TYPE_DEFLECTION,
deflections_response,
)
if deflections_response["NewNumberOfDeflections"] == 0:
_LOGGER.debug("The FRITZ!Box has no %s options", SWITCH_TYPE_DEFLECTION)
return []
if not (deflection_list := await avm_wrapper.async_get_ontel_deflections()):
return []
items = xmltodict.parse(deflection_list["NewDeflectionList"])["List"]["Item"]
if not isinstance(items, list):
items = [items]
return [
FritzBoxDeflectionSwitch(avm_wrapper, device_friendly_name, dict_of_deflection)
for dict_of_deflection in items
FritzBoxDeflectionSwitch(avm_wrapper, device_friendly_name, cd_id)
for cd_id in call_deflections
]
@@ -273,6 +256,61 @@ async def async_setup_entry(
)
class FritzBoxBaseCoordinatorSwitch(CoordinatorEntity, SwitchEntity):
"""Fritz switch coordinator base class."""
coordinator: AvmWrapper
entity_description: SwitchEntityDescription
_attr_has_entity_name = True
def __init__(
self,
avm_wrapper: AvmWrapper,
device_name: str,
description: SwitchEntityDescription,
) -> None:
"""Init device info class."""
super().__init__(avm_wrapper)
self.entity_description = description
self._device_name = device_name
self._attr_unique_id = f"{avm_wrapper.unique_id}-{description.key}"
@property
def device_info(self) -> DeviceInfo:
"""Return the device information."""
return DeviceInfo(
configuration_url=f"http://{self.coordinator.host}",
connections={(CONNECTION_NETWORK_MAC, self.coordinator.mac)},
identifiers={(DOMAIN, self.coordinator.unique_id)},
manufacturer="AVM",
model=self.coordinator.model,
name=self._device_name,
sw_version=self.coordinator.current_firmware,
)
@property
def data(self) -> dict[str, Any]:
"""Return entity data from coordinator data."""
raise NotImplementedError()
@property
def available(self) -> bool:
"""Return availability based on data availability."""
return super().available and bool(self.data)
async def _async_handle_turn_on_off(self, turn_on: bool) -> None:
"""Handle switch state change request."""
raise NotImplementedError()
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on switch."""
await self._async_handle_turn_on_off(turn_on=True)
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off switch."""
await self._async_handle_turn_on_off(turn_on=False)
class FritzBoxBaseSwitch(FritzBoxBaseEntity):
"""Fritz switch base class."""
@@ -417,69 +455,51 @@ class FritzBoxPortSwitch(FritzBoxBaseSwitch, SwitchEntity):
return bool(resp is not None)
class FritzBoxDeflectionSwitch(FritzBoxBaseSwitch, SwitchEntity):
class FritzBoxDeflectionSwitch(FritzBoxBaseCoordinatorSwitch):
"""Defines a FRITZ!Box Tools PortForward switch."""
_attr_entity_category = EntityCategory.CONFIG
def __init__(
self,
avm_wrapper: AvmWrapper,
device_friendly_name: str,
dict_of_deflection: Any,
deflection_id: int,
) -> None:
"""Init Fritxbox Deflection class."""
self._avm_wrapper = avm_wrapper
self.dict_of_deflection = dict_of_deflection
self._attributes = {}
self.id = int(self.dict_of_deflection["DeflectionId"])
self._attr_entity_category = EntityCategory.CONFIG
switch_info = SwitchInfo(
description=f"Call deflection {self.id}",
friendly_name=device_friendly_name,
self.deflection_id = deflection_id
description = SwitchEntityDescription(
key=f"call_deflection_{self.deflection_id}",
name=f"Call deflection {self.deflection_id}",
icon="mdi:phone-forward",
type=SWITCH_TYPE_DEFLECTION,
callback_update=self._async_fetch_update,
callback_switch=self._async_switch_on_off_executor,
)
super().__init__(self._avm_wrapper, device_friendly_name, switch_info)
super().__init__(avm_wrapper, device_friendly_name, description)
async def _async_fetch_update(self) -> None:
"""Fetch updates."""
@property
def data(self) -> dict[str, Any]:
"""Return call deflection data."""
return self.coordinator.data["call_deflections"].get(self.deflection_id, {})
resp = await self._avm_wrapper.async_get_ontel_deflections()
if not resp:
self._is_available = False
return
@property
def extra_state_attributes(self) -> dict[str, str]:
"""Return device attributes."""
return {
"type": self.data["Type"],
"number": self.data["Number"],
"deflection_to_number": self.data["DeflectionToNumber"],
"mode": self.data["Mode"][1:],
"outgoing": self.data["Outgoing"],
"phonebook_id": self.data["PhonebookID"],
}
self.dict_of_deflection = xmltodict.parse(resp["NewDeflectionList"])["List"][
"Item"
]
if isinstance(self.dict_of_deflection, list):
self.dict_of_deflection = self.dict_of_deflection[self.id]
@property
def is_on(self) -> bool | None:
"""Switch status."""
return self.data.get("Enable") == "1"
_LOGGER.debug(
"Specific %s response: NewDeflectionList=%s",
SWITCH_TYPE_DEFLECTION,
self.dict_of_deflection,
)
self._attr_is_on = self.dict_of_deflection["Enable"] == "1"
self._is_available = True
self._attributes["type"] = self.dict_of_deflection["Type"]
self._attributes["number"] = self.dict_of_deflection["Number"]
self._attributes["deflection_to_number"] = self.dict_of_deflection[
"DeflectionToNumber"
]
# Return mode sample: "eImmediately"
self._attributes["mode"] = self.dict_of_deflection["Mode"][1:]
self._attributes["outgoing"] = self.dict_of_deflection["Outgoing"]
self._attributes["phonebook_id"] = self.dict_of_deflection["PhonebookID"]
async def _async_switch_on_off_executor(self, turn_on: bool) -> None:
async def _async_handle_turn_on_off(self, turn_on: bool) -> None:
"""Handle deflection switch."""
await self._avm_wrapper.async_set_deflection_enable(self.id, turn_on)
await self.coordinator.async_set_deflection_enable(self.deflection_id, turn_on)
class FritzBoxProfileSwitch(FritzDeviceBase, SwitchEntity):
@@ -20,5 +20,5 @@
"documentation": "https://www.home-assistant.io/integrations/frontend",
"integration_type": "system",
"quality_scale": "internal",
"requirements": ["home-assistant-frontend==20230411.1"]
"requirements": ["home-assistant-frontend==20230503.3"]
}
@@ -8,7 +8,7 @@ from afsapi import AFSAPI, ConnectionError as FSConnectionError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
from homeassistant.exceptions import ConfigEntryNotReady
from .const import CONF_PIN, CONF_WEBFSAPI_URL, DOMAIN
@@ -28,7 +28,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
try:
await afsapi.get_power()
except FSConnectionError as exception:
raise PlatformNotReady from exception
raise ConfigEntryNotReady from exception
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = afsapi
@@ -25,7 +25,10 @@
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
}
},
"issues": {
@@ -43,10 +43,10 @@ class GoogleMailSensor(GoogleMailEntity, SensorEntity):
"""Get the vacation data."""
service = await self.auth.get_resource()
settings: HttpRequest = service.users().settings().getVacation(userId="me")
data = await self.hass.async_add_executor_job(settings.execute)
data: dict = await self.hass.async_add_executor_job(settings.execute)
if data["enableAutoReply"]:
value = datetime.fromtimestamp(int(data["endTime"]) / 1000, tz=timezone.utc)
if data["enableAutoReply"] and (end := data.get("endTime")):
value = datetime.fromtimestamp(int(end) / 1000, tz=timezone.utc)
else:
value = None
self._attr_native_value = value
+5 -2
View File
@@ -85,9 +85,12 @@ from .handler import ( # noqa: F401
async_get_addon_discovery_info,
async_get_addon_info,
async_get_addon_store_info,
async_get_yellow_settings,
async_install_addon,
async_reboot_host,
async_restart_addon,
async_set_addon_options,
async_set_yellow_settings,
async_start_addon,
async_stop_addon,
async_uninstall_addon,
@@ -587,7 +590,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
await async_setup_addon_panel(hass, hassio)
# Setup hardware integration for the detected board type
async def _async_setup_hardware_integration(hass):
async def _async_setup_hardware_integration(_: datetime) -> None:
"""Set up hardaware integration for the detected board type."""
if (os_info := get_os_info(hass)) is None:
# os info not yet fetched from supervisor, retry later
@@ -607,7 +610,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
)
)
await _async_setup_hardware_integration(hass)
await _async_setup_hardware_integration(datetime.now())
hass.async_create_task(
hass.config_entries.flow.async_init(DOMAIN, context={"source": "system"})
@@ -262,6 +262,37 @@ async def async_apply_suggestion(hass: HomeAssistant, suggestion_uuid: str) -> b
return await hassio.send_command(command, timeout=None)
@api_data
async def async_get_yellow_settings(hass: HomeAssistant) -> dict[str, bool]:
"""Return settings specific to Home Assistant Yellow."""
hassio: HassIO = hass.data[DOMAIN]
return await hassio.send_command("/os/boards/yellow", method="get")
@api_data
async def async_set_yellow_settings(
hass: HomeAssistant, settings: dict[str, bool]
) -> dict:
"""Set settings specific to Home Assistant Yellow.
Returns an empty dict.
"""
hassio: HassIO = hass.data[DOMAIN]
return await hassio.send_command(
"/os/boards/yellow", method="post", payload=settings
)
@api_data
async def async_reboot_host(hass: HomeAssistant) -> dict:
"""Reboot the host.
Returns an empty dict.
"""
hassio: HassIO = hass.data[DOMAIN]
return await hassio.send_command("/host/reboot", method="post", timeout=60)
class HassIO:
"""Small API wrapper for Hass.io."""
+11 -10
View File
@@ -12,6 +12,7 @@ from homeassistant.components import frontend
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.recorder import get_instance, history
from homeassistant.components.recorder.util import session_scope
from homeassistant.const import CONF_EXCLUDE, CONF_INCLUDE
from homeassistant.core import HomeAssistant, valid_entity_id
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entityfilter import INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA
@@ -27,16 +28,16 @@ CONF_ORDER = "use_include_order"
_ONE_DAY = timedelta(days=1)
CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.All(
INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA.extend(
{vol.Optional(CONF_ORDER, default=False): cv.boolean}
),
)
},
),
{
DOMAIN: vol.All(
cv.deprecated(CONF_INCLUDE),
cv.deprecated(CONF_EXCLUDE),
cv.deprecated(CONF_ORDER),
INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA.extend(
{vol.Optional(CONF_ORDER, default=False): cv.boolean}
),
)
},
extra=vol.ALLOW_EXTRA,
)
@@ -3,7 +3,8 @@ from __future__ import annotations
from collections.abc import Callable, Mapping
import dataclasses
from typing import Any
from itertools import chain
from typing import Any, TypedDict
import voluptuous as vol
@@ -77,16 +78,41 @@ class AssistantPreferences:
return {"expose_new": self.expose_new}
@dataclasses.dataclass(frozen=True)
class ExposedEntity:
"""An exposed entity without a unique_id."""
assistants: dict[str, dict[str, Any]]
def to_json(self) -> dict[str, Any]:
"""Return a JSON serializable representation for storage."""
return {
"assistants": self.assistants,
}
class SerializedExposedEntities(TypedDict):
"""Serialized exposed entities storage storage collection."""
assistants: dict[str, dict[str, Any]]
exposed_entities: dict[str, dict[str, Any]]
class ExposedEntities:
"""Control assistant settings."""
"""Control assistant settings.
Settings for entities without a unique_id are stored in the store.
Settings for entities with a unique_id are stored in the entity registry.
"""
_assistants: dict[str, AssistantPreferences]
entities: dict[str, ExposedEntity]
def __init__(self, hass: HomeAssistant) -> None:
"""Initialize."""
self._hass = hass
self._listeners: dict[str, list[Callable[[], None]]] = {}
self._store: Store[dict[str, dict[str, dict[str, Any]]]] = Store(
self._store: Store[SerializedExposedEntities] = Store(
hass, STORAGE_VERSION, STORAGE_KEY
)
@@ -95,7 +121,8 @@ class ExposedEntities:
websocket_api.async_register_command(self._hass, ws_expose_entity)
websocket_api.async_register_command(self._hass, ws_expose_new_entities_get)
websocket_api.async_register_command(self._hass, ws_expose_new_entities_set)
await self.async_load()
websocket_api.async_register_command(self._hass, ws_list_exposed_entities)
await self._async_load_data()
@callback
def async_listen_entity_updates(
@@ -105,30 +132,57 @@ class ExposedEntities:
self._listeners.setdefault(assistant, []).append(listener)
@callback
def async_expose_entity(
self, assistant: str, entity_id: str, should_expose: bool
def async_set_assistant_option(
self, assistant: str, entity_id: str, key: str, value: Any
) -> None:
"""Expose an entity to an assistant.
"""Set an option for an assistant.
Notify listeners if expose flag was changed.
"""
entity_registry = er.async_get(self._hass)
if not (registry_entry := entity_registry.async_get(entity_id)):
raise HomeAssistantError("Unknown entity")
return self._async_set_legacy_assistant_option(
assistant, entity_id, key, value
)
assistant_options: Mapping[str, Any]
if (
assistant_options := registry_entry.options.get(assistant, {})
) and assistant_options.get("should_expose") == should_expose:
) and assistant_options.get(key) == value:
return
assistant_options = assistant_options | {"should_expose": should_expose}
assistant_options = assistant_options | {key: value}
entity_registry.async_update_entity_options(
entity_id, assistant, assistant_options
)
for listener in self._listeners.get(assistant, []):
listener()
def _async_set_legacy_assistant_option(
self, assistant: str, entity_id: str, key: str, value: Any
) -> None:
"""Set an option for an assistant.
Notify listeners if expose flag was changed.
"""
if (
(exposed_entity := self.entities.get(entity_id))
and (assistant_options := exposed_entity.assistants.get(assistant, {}))
and assistant_options.get(key) == value
):
return
if exposed_entity:
new_exposed_entity = self._update_exposed_entity(
assistant, entity_id, key, value
)
else:
new_exposed_entity = self._new_exposed_entity(assistant, key, value)
self.entities[entity_id] = new_exposed_entity
self._async_schedule_save()
for listener in self._listeners.get(assistant, []):
listener()
@callback
def async_get_expose_new_entities(self, assistant: str) -> bool:
"""Check if new entities are exposed to an assistant."""
@@ -150,12 +204,37 @@ class ExposedEntities:
entity_registry = er.async_get(self._hass)
result: dict[str, Mapping[str, Any]] = {}
options: Mapping | None
for entity_id, exposed_entity in self.entities.items():
if options := exposed_entity.assistants.get(assistant):
result[entity_id] = options
for entity_id, entry in entity_registry.entities.items():
if options := entry.options.get(assistant):
result[entity_id] = options
return result
@callback
def async_get_entity_settings(self, entity_id: str) -> dict[str, Mapping[str, Any]]:
"""Get assistant expose settings for an entity."""
entity_registry = er.async_get(self._hass)
result: dict[str, Mapping[str, Any]] = {}
assistant_settings: Mapping
if registry_entry := entity_registry.async_get(entity_id):
assistant_settings = registry_entry.options
elif exposed_entity := self.entities.get(entity_id):
assistant_settings = exposed_entity.assistants
else:
raise HomeAssistantError("Unknown entity")
for assistant in KNOWN_ASSISTANTS:
if options := assistant_settings.get(assistant):
result[assistant] = options
return result
@callback
def async_should_expose(self, assistant: str, entity_id: str) -> bool:
"""Return True if an entity should be exposed to an assistant."""
@@ -166,9 +245,7 @@ class ExposedEntities:
entity_registry = er.async_get(self._hass)
if not (registry_entry := entity_registry.async_get(entity_id)):
# Entities which are not in the entity registry are not exposed
return False
return self._async_should_expose_legacy_entity(assistant, entity_id)
if assistant in registry_entry.options:
if "should_expose" in registry_entry.options[assistant]:
should_expose = registry_entry.options[assistant]["should_expose"]
@@ -187,11 +264,42 @@ class ExposedEntities:
return should_expose
def _async_should_expose_legacy_entity(
self, assistant: str, entity_id: str
) -> bool:
"""Return True if an entity should be exposed to an assistant."""
should_expose: bool
if (
exposed_entity := self.entities.get(entity_id)
) and assistant in exposed_entity.assistants:
if "should_expose" in exposed_entity.assistants[assistant]:
should_expose = exposed_entity.assistants[assistant]["should_expose"]
return should_expose
if self.async_get_expose_new_entities(assistant):
should_expose = self._is_default_exposed(entity_id, None)
else:
should_expose = False
if exposed_entity:
new_exposed_entity = self._update_exposed_entity(
assistant, entity_id, "should_expose", should_expose
)
else:
new_exposed_entity = self._new_exposed_entity(
assistant, "should_expose", should_expose
)
self.entities[entity_id] = new_exposed_entity
self._async_schedule_save()
return should_expose
def _is_default_exposed(
self, entity_id: str, registry_entry: er.RegistryEntry
self, entity_id: str, registry_entry: er.RegistryEntry | None
) -> bool:
"""Return True if an entity is exposed by default."""
if (
if registry_entry and (
registry_entry.entity_category is not None
or registry_entry.hidden_by is not None
):
@@ -201,7 +309,11 @@ class ExposedEntities:
if domain in DEFAULT_EXPOSED_DOMAINS:
return True
device_class = get_device_class(self._hass, entity_id)
try:
device_class = get_device_class(self._hass, entity_id)
except HomeAssistantError:
# The entity no longer exists
return False
if (
domain == "binary_sensor"
and device_class in DEFAULT_EXPOSED_BINARY_SENSOR_DEVICE_CLASSES
@@ -213,17 +325,43 @@ class ExposedEntities:
return False
async def async_load(self) -> None:
def _update_exposed_entity(
self, assistant: str, entity_id: str, key: str, value: Any
) -> ExposedEntity:
"""Update an exposed entity."""
entity = self.entities[entity_id]
assistants = dict(entity.assistants)
old_settings = assistants.get(assistant, {})
assistants[assistant] = old_settings | {key: value}
return ExposedEntity(assistants)
def _new_exposed_entity(
self, assistant: str, key: str, value: Any
) -> ExposedEntity:
"""Create a new exposed entity."""
return ExposedEntity(
assistants={assistant: {key: value}},
)
async def _async_load_data(self) -> SerializedExposedEntities | None:
"""Load from the store."""
data = await self._store.async_load()
assistants: dict[str, AssistantPreferences] = {}
exposed_entities: dict[str, ExposedEntity] = {}
if data:
for domain, preferences in data["assistants"].items():
assistants[domain] = AssistantPreferences(**preferences)
if data and "exposed_entities" in data:
for entity_id, preferences in data["exposed_entities"].items():
exposed_entities[entity_id] = ExposedEntity(**preferences)
self._assistants = assistants
self.entities = exposed_entities
return data
@callback
def _async_schedule_save(self) -> None:
@@ -231,17 +369,19 @@ class ExposedEntities:
self._store.async_delay_save(self._data_to_save, SAVE_DELAY)
@callback
def _data_to_save(self) -> dict[str, dict[str, dict[str, Any]]]:
"""Return data to store in a file."""
data = {}
data["assistants"] = {
domain: preferences.to_json()
for domain, preferences in self._assistants.items()
def _data_to_save(self) -> SerializedExposedEntities:
"""Return JSON-compatible date for storing to file."""
return {
"assistants": {
domain: preferences.to_json()
for domain, preferences in self._assistants.items()
},
"exposed_entities": {
entity_id: entity.to_json()
for entity_id, entity in self.entities.items()
},
}
return data
@callback
@websocket_api.require_admin
@@ -257,7 +397,6 @@ def ws_expose_entity(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
) -> None:
"""Expose an entity to an assistant."""
entity_registry = er.async_get(hass)
entity_ids: str = msg["entity_ids"]
if blocked := next(
@@ -273,28 +412,37 @@ def ws_expose_entity(
)
return
if unknown := next(
(
entity_id
for entity_id in entity_ids
if entity_id not in entity_registry.entities
),
None,
):
connection.send_error(
msg["id"], websocket_api.const.ERR_NOT_FOUND, f"can't expose '{unknown}'"
)
return
exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES]
for entity_id in entity_ids:
for assistant in msg["assistants"]:
exposed_entities.async_expose_entity(
assistant, entity_id, msg["should_expose"]
)
async_expose_entity(hass, assistant, entity_id, msg["should_expose"])
connection.send_result(msg["id"])
@callback
@websocket_api.require_admin
@websocket_api.websocket_command(
{
vol.Required("type"): "homeassistant/expose_entity/list",
}
)
def ws_list_exposed_entities(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
) -> None:
"""Expose an entity to an assistant."""
result: dict[str, Any] = {}
exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES]
entity_registry = er.async_get(hass)
for entity_id in chain(exposed_entities.entities, entity_registry.entities):
result[entity_id] = {}
entity_settings = async_get_entity_settings(hass, entity_id)
for assistant, settings in entity_settings.items():
if "should_expose" not in settings:
continue
result[entity_id][assistant] = settings["should_expose"]
connection.send_result(msg["id"], {"exposed_entities": result})
@callback
@websocket_api.require_admin
@websocket_api.websocket_command(
@@ -348,8 +496,42 @@ def async_get_assistant_settings(
return exposed_entities.async_get_assistant_settings(assistant)
@callback
def async_get_entity_settings(
hass: HomeAssistant, entity_id: str
) -> dict[str, Mapping[str, Any]]:
"""Get assistant expose settings for an entity."""
exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES]
return exposed_entities.async_get_entity_settings(entity_id)
@callback
def async_expose_entity(
hass: HomeAssistant,
assistant: str,
entity_id: str,
should_expose: bool,
) -> None:
"""Get assistant expose settings for an entity."""
async_set_assistant_option(
hass, assistant, entity_id, "should_expose", should_expose
)
@callback
def async_should_expose(hass: HomeAssistant, assistant: str, entity_id: str) -> bool:
"""Return True if an entity should be exposed to an assistant."""
exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES]
return exposed_entities.async_should_expose(assistant, entity_id)
@callback
def async_set_assistant_option(
hass: HomeAssistant, assistant: str, entity_id: str, option: str, value: Any
) -> None:
"""Set an option for an assistant.
Notify listeners if expose flag was changed.
"""
exposed_entities: ExposedEntities = hass.data[DATA_EXPOSED_ENTITIES]
exposed_entities.async_set_assistant_option(assistant, entity_id, option, value)
@@ -1,15 +1,37 @@
"""Config flow for the Home Assistant Yellow integration."""
from __future__ import annotations
import logging
from typing import Any
import aiohttp
import async_timeout
import voluptuous as vol
from homeassistant.components.hassio import (
HassioAPIError,
async_get_yellow_settings,
async_reboot_host,
async_set_yellow_settings,
)
from homeassistant.components.homeassistant_hardware import silabs_multiprotocol_addon
from homeassistant.config_entries import ConfigEntry, ConfigFlow
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import selector
from .const import DOMAIN, ZHA_HW_DISCOVERY_DATA
_LOGGER = logging.getLogger(__name__)
STEP_HW_SETTINGS_SCHEMA = vol.Schema(
{
vol.Required("disk_led"): selector.BooleanSelector(),
vol.Required("heartbeat_led"): selector.BooleanSelector(),
vol.Required("power_led"): selector.BooleanSelector(),
}
)
class HomeAssistantYellowConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Home Assistant Yellow."""
@@ -35,6 +57,82 @@ class HomeAssistantYellowConfigFlow(ConfigFlow, domain=DOMAIN):
class HomeAssistantYellowOptionsFlow(silabs_multiprotocol_addon.OptionsFlowHandler):
"""Handle an option flow for Home Assistant Yellow."""
_hw_settings: dict[str, bool] | None = None
async def async_step_on_supervisor(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle logic when on Supervisor host."""
return self.async_show_menu(
step_id="main_menu",
menu_options=[
"hardware_settings",
"multipan_settings",
],
)
async def async_step_hardware_settings(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle hardware settings."""
if user_input is not None:
if self._hw_settings == user_input:
return self.async_create_entry(data={})
try:
async with async_timeout.timeout(10):
await async_set_yellow_settings(self.hass, user_input)
except (aiohttp.ClientError, TimeoutError, HassioAPIError) as err:
_LOGGER.warning("Failed to write hardware settings", exc_info=err)
return self.async_abort(reason="write_hw_settings_error")
return await self.async_step_confirm_reboot()
try:
async with async_timeout.timeout(10):
self._hw_settings: dict[str, bool] = await async_get_yellow_settings(
self.hass
)
except (aiohttp.ClientError, TimeoutError, HassioAPIError) as err:
_LOGGER.warning("Failed to read hardware settings", exc_info=err)
return self.async_abort(reason="read_hw_settings_error")
schema = self.add_suggested_values_to_schema(
STEP_HW_SETTINGS_SCHEMA, self._hw_settings
)
return self.async_show_form(step_id="hardware_settings", data_schema=schema)
async def async_step_confirm_reboot(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Confirm reboot host."""
return self.async_show_menu(
step_id="reboot_menu",
menu_options=[
"reboot_now",
"reboot_later",
],
)
async def async_step_reboot_now(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Reboot now."""
await async_reboot_host(self.hass)
return self.async_create_entry(data={})
async def async_step_reboot_later(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Reboot later."""
return self.async_create_entry(data={})
async def async_step_multipan_settings(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle multipan settings."""
return await super().async_step_on_supervisor(user_input)
async def _async_serial_port_settings(
self,
) -> silabs_multiprotocol_addon.SerialPortSettings:
@@ -11,9 +11,31 @@
"addon_installed_other_device": {
"title": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::addon_installed_other_device::title%]"
},
"hardware_settings": {
"title": "Configure hardware settings",
"data": {
"disk_led": "Disk LED",
"heartbeat_led": "Heartbeat LED",
"power_led": "Power LED"
}
},
"install_addon": {
"title": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::install_addon::title%]"
},
"main_menu": {
"menu_options": {
"hardware_settings": "[%key:component::homeassistant_yellow::options::step::hardware_settings::title%]",
"multipan_settings": "Configure IEEE 802.15.4 radio multiprotocol support"
}
},
"reboot_menu": {
"title": "Reboot required",
"description": "The settings have changed, but the new settings will not take effect until the system is rebooted",
"menu_options": {
"reboot_later": "Reboot manually later",
"reboot_now": "Reboot now"
}
},
"show_revert_guide": {
"title": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::show_revert_guide::title%]",
"description": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::step::show_revert_guide::description%]"
@@ -31,6 +53,8 @@
"addon_set_config_failed": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::addon_set_config_failed%]",
"addon_start_failed": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::addon_start_failed%]",
"not_hassio": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::not_hassio%]",
"read_hw_settings_error": "Failed to read hardware settings",
"write_hw_settings_error": "Failed to write hardware settings",
"zha_migration_failed": "[%key:component::homeassistant_hardware::silabs_multiprotocol_hardware::options::abort::zha_migration_failed%]"
},
"progress": {
+1 -1
View File
@@ -177,7 +177,7 @@ class ImapDataUpdateCoordinator(DataUpdateCoordinator[int | None]):
"search": self.config_entry.data[CONF_SEARCH],
"folder": self.config_entry.data[CONF_FOLDER],
"date": message.date,
"text": message.text,
"text": message.text[:2048],
"sender": message.sender,
"subject": message.subject,
"headers": message.headers,
+1 -1
View File
@@ -1,7 +1,7 @@
{
"domain": "imap",
"name": "IMAP",
"codeowners": ["@engrbm87"],
"codeowners": ["@engrbm87", "@jbouwh"],
"config_flow": true,
"dependencies": ["repairs"],
"documentation": "https://www.home-assistant.io/integrations/imap",
@@ -18,7 +18,7 @@
"loggers": ["pyinsteon", "pypubsub"],
"requirements": [
"pyinsteon==1.4.2",
"insteon-frontend-home-assistant==0.3.4"
"insteon-frontend-home-assistant==0.3.5"
],
"usb": [
{
+15 -15
View File
@@ -174,23 +174,23 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
async def async_added_to_hass(self) -> None:
"""Handle entity which will be added."""
await super().async_added_to_hass()
if state := await self.async_get_last_state():
try:
self._state = Decimal(state.state)
except (DecimalException, ValueError) as err:
_LOGGER.warning(
"%s could not restore last state %s: %s",
self.entity_id,
state.state,
err,
)
else:
self._attr_device_class = state.attributes.get(ATTR_DEVICE_CLASS)
if self._unit_of_measurement is None:
self._unit_of_measurement = state.attributes.get(
ATTR_UNIT_OF_MEASUREMENT
if (state := await self.async_get_last_state()) is not None:
if state.state == STATE_UNAVAILABLE:
self._attr_available = False
elif state.state != STATE_UNKNOWN:
try:
self._state = Decimal(state.state)
except (DecimalException, ValueError) as err:
_LOGGER.warning(
"%s could not restore last state %s: %s",
self.entity_id,
state.state,
err,
)
self._attr_device_class = state.attributes.get(ATTR_DEVICE_CLASS)
self._unit_of_measurement = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
@callback
def calc_integration(event: Event) -> None:
"""Handle the sensor state changes."""
+3 -1
View File
@@ -140,16 +140,18 @@ class GetStateIntentHandler(intent.IntentHandler):
area=area,
domains=domains,
device_classes=device_classes,
assistant=intent_obj.assistant,
)
)
_LOGGER.debug(
"Found %s state(s) that matched: name=%s, area=%s, domains=%s, device_classes=%s",
"Found %s state(s) that matched: name=%s, area=%s, domains=%s, device_classes=%s, assistant=%s",
len(states),
name,
area,
domains,
device_classes,
intent_obj.assistant,
)
# Create response
+48 -6
View File
@@ -11,6 +11,7 @@ from typing import Any, cast
from aiolifx.aiolifx import (
Light,
Message,
MultiZoneDirection,
MultiZoneEffectType,
TileEffectType,
@@ -56,6 +57,8 @@ from .util import (
LIGHT_UPDATE_INTERVAL = 10
REQUEST_REFRESH_DELAY = 0.35
LIFX_IDENTIFY_DELAY = 3.0
ZONES_PER_COLOR_UPDATE_REQUEST = 8
RSSI_DBM_FW = AwesomeVersion("2.77")
@@ -205,14 +208,53 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
methods, DEFAULT_ATTEMPTS, OVERALL_TIMEOUT
)
def get_number_of_zones(self) -> int:
"""Return the number of zones.
If the number of zones is not yet populated, return 1 since
the device will have a least one zone.
"""
return len(self.device.color_zones) if self.device.color_zones else 1
@callback
def _async_build_color_zones_update_requests(self) -> list[Callable]:
"""Build a color zones update request."""
device = self.device
return [
partial(device.get_color_zones, start_index=zone)
for zone in range(0, len(device.color_zones), 8)
]
calls: list[Callable] = []
for zone in range(
0, self.get_number_of_zones(), ZONES_PER_COLOR_UPDATE_REQUEST
):
def _wrap_get_color_zones(
callb: Callable[[Message, dict[str, Any] | None], None],
get_color_zones_args: dict[str, Any],
) -> None:
"""Capture the callback and make sure resp_set_multizonemultizone is called before."""
def _wrapped_callback(
bulb: Light,
response: Message,
**kwargs: Any,
) -> None:
# We need to call resp_set_multizonemultizone to populate
# the color_zones attribute before calling the callback
device.resp_set_multizonemultizone(response)
# Now call the original callback
callb(bulb, response, **kwargs)
device.get_color_zones(**get_color_zones_args, callb=_wrapped_callback)
calls.append(
partial(
_wrap_get_color_zones,
get_color_zones_args={
"start_index": zone,
"end_index": zone + ZONES_PER_COLOR_UPDATE_REQUEST - 1,
},
)
)
return calls
async def _async_update_data(self) -> None:
"""Fetch all device data from the api."""
@@ -224,7 +266,7 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
):
await self._async_populate_device_info()
num_zones = len(device.color_zones) if device.color_zones is not None else 0
num_zones = self.get_number_of_zones()
features = lifx_features(self.device)
is_extended_multizone = features["extended_multizone"]
is_legacy_multizone = not is_extended_multizone and features["multizone"]
@@ -256,7 +298,7 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
if is_extended_multizone or is_legacy_multizone:
self.active_effect = FirmwareEffect[self.device.effect.get("effect", "OFF")]
if is_legacy_multizone and num_zones != len(device.color_zones):
if is_legacy_multizone and num_zones != self.get_number_of_zones():
# The number of zones has changed so we need
# to update the zones again. This happens rarely.
await self.async_get_color_zones()
+1 -1
View File
@@ -382,7 +382,7 @@ class LIFXMultiZone(LIFXColor):
"""Send a color change to the bulb."""
bulb = self.bulb
color_zones = bulb.color_zones
num_zones = len(color_zones)
num_zones = self.coordinator.get_number_of_zones()
# Zone brightness is not reported when powered off
if not self.is_on and hsbk[HSBK_BRIGHTNESS] is None:
@@ -129,7 +129,7 @@ class LocalCalendarEntity(CalendarEntity):
recurrence_range=range_value,
)
except EventStoreError as err:
raise HomeAssistantError("Error while deleting event: {err}") from err
raise HomeAssistantError(f"Error while deleting event: {err}") from err
await self._async_store()
await self.async_update_ha_state(force_refresh=True)
@@ -153,7 +153,7 @@ class LocalCalendarEntity(CalendarEntity):
recurrence_range=range_value,
)
except EventStoreError as err:
raise HomeAssistantError("Error while updating event: {err}") from err
raise HomeAssistantError(f"Error while updating event: {err}") from err
await self._async_store()
await self.async_update_ha_state(force_refresh=True)
@@ -38,11 +38,15 @@ def async_describe_events(
device_type = data[ATTR_TYPE]
leap_button_number = data[ATTR_LEAP_BUTTON_NUMBER]
dr_device_id = data[ATTR_DEVICE_ID]
lutron_data = get_lutron_data_by_dr_id(hass, dr_device_id)
keypad = lutron_data.keypad_data.dr_device_id_to_keypad.get(dr_device_id)
keypad_id = keypad["lutron_device_id"]
rev_button_map: dict[int, str] | None = None
keypad_button_names_to_leap: dict[int, dict[str, int]] = {}
keypad_id: int = -1
keypad_button_names_to_leap = lutron_data.keypad_data.button_names_to_leap
if lutron_data := get_lutron_data_by_dr_id(hass, dr_device_id):
keypad_data = lutron_data.keypad_data
keypad = keypad_data.dr_device_id_to_keypad.get(dr_device_id)
keypad_id = keypad["lutron_device_id"]
keypad_button_names_to_leap = keypad_data.button_names_to_leap
if not (rev_button_map := LEAP_TO_DEVICE_TYPE_SUBTYPE_MAP.get(device_type)):
if fwd_button_map := keypad_button_names_to_leap.get(keypad_id):
@@ -195,6 +195,17 @@ async def async_remove_config_entry_device(
if node is None:
return True
if node.is_bridge_device:
device_registry = dr.async_get(hass)
devices = dr.async_entries_for_config_entry(
device_registry, config_entry.entry_id
)
for device in devices:
if device.via_device_id == device_entry.id:
device_registry.async_update_device(
device.id, remove_config_entry_id=config_entry.entry_id
)
matter = get_matter(hass)
await matter.matter_client.remove_node(node.node_id)
+23 -19
View File
@@ -8,6 +8,7 @@ from chip.clusters import Objects as clusters
from homeassistant.components.cover import (
ATTR_POSITION,
CoverDeviceClass,
CoverEntity,
CoverEntityDescription,
CoverEntityFeature,
@@ -25,6 +26,12 @@ from .models import MatterDiscoverySchema
# The MASK used for extracting bits 0 to 1 of the byte.
OPERATIONAL_STATUS_MASK = 0b11
# map Matter window cover types to HA device class
TYPE_MAP = {
clusters.WindowCovering.Enums.Type.kAwning: CoverDeviceClass.AWNING,
clusters.WindowCovering.Enums.Type.kDrapery: CoverDeviceClass.CURTAIN,
}
class OperationalStatus(IntEnum):
"""Currently ongoing operations enumeration for coverings, as defined in the Matter spec."""
@@ -56,20 +63,6 @@ class MatterCover(MatterEntity, CoverEntity):
| CoverEntityFeature.SET_POSITION
)
@property
def current_cover_position(self) -> int:
"""Return the current position of cover."""
if self._attr_current_cover_position:
current_position = self._attr_current_cover_position
else:
current_position = self.get_matter_attribute_value(
clusters.WindowCovering.Attributes.CurrentPositionLiftPercentage
)
assert current_position is not None
return current_position
@property
def is_closed(self) -> bool:
"""Return true if cover is closed, else False."""
@@ -91,7 +84,8 @@ class MatterCover(MatterEntity, CoverEntity):
"""Set the cover to a specific position."""
position = kwargs[ATTR_POSITION]
await self.send_device_command(
clusters.WindowCovering.Commands.GoToLiftValue(position)
# value needs to be inverted and is sent in 100ths
clusters.WindowCovering.Commands.GoToLiftPercentage((100 - position) * 100)
)
async def send_device_command(self, command: Any) -> None:
@@ -129,15 +123,25 @@ class MatterCover(MatterEntity, CoverEntity):
self._attr_is_opening = False
self._attr_is_closing = False
self._attr_current_cover_position = self.get_matter_attribute_value(
# current position is inverted in matter (100 is closed, 0 is open)
current_cover_position = self.get_matter_attribute_value(
clusters.WindowCovering.Attributes.CurrentPositionLiftPercentage
)
self._attr_current_cover_position = 100 - current_cover_position
LOGGER.debug(
"Current position: %s for %s",
self._attr_current_cover_position,
"Current position for %s - raw: %s - corrected: %s",
self.entity_id,
current_cover_position,
self.current_cover_position,
)
# map matter type to HA deviceclass
device_type: clusters.WindowCovering.Enums.Type = (
self.get_matter_attribute_value(clusters.WindowCovering.Attributes.Type)
)
self._attr_device_class = TYPE_MAP.get(device_type, CoverDeviceClass.AWNING)
# Discovery schema(s) to map Matter Attributes to HA entities
DISCOVERY_SCHEMAS = [
@@ -149,5 +153,5 @@ DISCOVERY_SCHEMAS = [
clusters.WindowCovering.Attributes.CurrentPositionLiftPercentage,
clusters.WindowCovering.Attributes.OperationalStatus,
),
),
)
]
+1 -1
View File
@@ -51,7 +51,7 @@ PLATFORMS = [
]
async def with_timeout(task, timeout_seconds=10):
async def with_timeout(task, timeout_seconds=30):
"""Run an async task with a timeout."""
async with async_timeout.timeout(timeout_seconds):
return await task
+1 -1
View File
@@ -194,6 +194,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
conf = dict(entry.data)
hass_config = await conf_util.async_hass_config_yaml(hass)
mqtt_yaml = PLATFORM_CONFIG_SCHEMA_BASE(hass_config.get(DOMAIN, {}))
await async_create_certificate_temp_files(hass, conf)
client = MQTT(hass, entry, conf)
if DOMAIN in hass.data:
mqtt_data = get_mqtt_data(hass)
@@ -206,7 +207,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DATA_MQTT] = mqtt_data = MqttData(config=mqtt_yaml, client=client)
client.start(mqtt_data)
await async_create_certificate_temp_files(hass, dict(entry.data))
# Restore saved subscriptions
if mqtt_data.subscriptions_to_restore:
mqtt_data.client.async_restore_tracked_subscriptions(
+3
View File
@@ -740,6 +740,9 @@ class MQTT:
asyncio.run_coroutine_threadsafe(
publish_birth_message(birth_message), self.hass.loop
)
else:
# Update subscribe cooldown period to a shorter time
self._subscribe_debouncer.set_timeout(SUBSCRIBE_COOLDOWN)
async def _async_resubscribe(self) -> None:
"""Resubscribe on reconnect."""
+1 -1
View File
@@ -266,7 +266,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
netatmo_name="power",
entity_registry_enabled_default=True,
native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.TOTAL,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER,
),
)
@@ -1,9 +1,9 @@
{
"domain": "netgear_lte",
"name": "NETGEAR LTE",
"codeowners": [],
"codeowners": ["@tkdrob"],
"documentation": "https://www.home-assistant.io/integrations/netgear_lte",
"iot_class": "local_polling",
"loggers": ["eternalegypt"],
"requirements": ["eternalegypt==0.0.15"]
"requirements": ["eternalegypt==0.0.16"]
}
@@ -31,8 +31,8 @@
},
"issues": {
"deprecated_yaml": {
"title": "The Netxcloud YAML configuration has been deprecated",
"description": "Configuring Netxcloud using YAML has been deprecated.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the `nextcloud` YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
"title": "The Nextcloud YAML configuration has been deprecated",
"description": "Configuring Nextcloud using YAML has been deprecated.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the `nextcloud` YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
}
}
}
+1 -1
View File
@@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/nina",
"iot_class": "cloud_polling",
"loggers": ["pynina"],
"requirements": ["pynina==0.2.0"]
"requirements": ["pynina==0.3.0"]
}
+62 -34
View File
@@ -2,7 +2,7 @@
from __future__ import annotations
import asyncio
from dataclasses import dataclass, field, fields
from dataclasses import dataclass, field
from datetime import timedelta
import logging
import traceback
@@ -10,9 +10,16 @@ from typing import Any
from uuid import UUID
from aionotion import async_get_client
from aionotion.bridge.models import Bridge
from aionotion.bridge.models import Bridge, BridgeAllResponse
from aionotion.errors import InvalidCredentialsError, NotionError
from aionotion.sensor.models import Listener, ListenerKind, Sensor
from aionotion.sensor.models import (
Listener,
ListenerAllResponse,
ListenerKind,
Sensor,
SensorAllResponse,
)
from aionotion.user.models import UserPreferences, UserPreferencesResponse
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
@@ -51,6 +58,11 @@ PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
ATTR_SYSTEM_MODE = "system_mode"
ATTR_SYSTEM_NAME = "system_name"
DATA_BRIDGES = "bridges"
DATA_LISTENERS = "listeners"
DATA_SENSORS = "sensors"
DATA_USER_PREFERENCES = "user_preferences"
DEFAULT_SCAN_INTERVAL = timedelta(minutes=1)
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
@@ -84,6 +96,9 @@ def is_uuid(value: str) -> bool:
class NotionData:
"""Define a manager class for Notion data."""
hass: HomeAssistant
entry: ConfigEntry
# Define a dict of bridges, indexed by bridge ID (an integer):
bridges: dict[int, Bridge] = field(default_factory=dict)
@@ -93,12 +108,40 @@ class NotionData:
# Define a dict of sensors, indexed by sensor UUID (a string):
sensors: dict[str, Sensor] = field(default_factory=dict)
# Define a user preferences response object:
user_preferences: UserPreferences | None = field(default=None)
def update_data_from_response(
self,
response: BridgeAllResponse
| ListenerAllResponse
| SensorAllResponse
| UserPreferencesResponse,
) -> None:
"""Update data from an aionotion response."""
if isinstance(response, BridgeAllResponse):
for bridge in response.bridges:
# If a new bridge is discovered, register it:
if bridge.id not in self.bridges:
_async_register_new_bridge(self.hass, self.entry, bridge)
self.bridges[bridge.id] = bridge
elif isinstance(response, ListenerAllResponse):
self.listeners = {listener.id: listener for listener in response.listeners}
elif isinstance(response, SensorAllResponse):
self.sensors = {sensor.uuid: sensor for sensor in response.sensors}
elif isinstance(response, UserPreferencesResponse):
self.user_preferences = response.user_preferences
def asdict(self) -> dict[str, Any]:
"""Represent this dataclass (and its Pydantic contents) as a dict."""
return {
field.name: [obj.dict() for obj in getattr(self, field.name).values()]
for field in fields(self)
data: dict[str, Any] = {
DATA_BRIDGES: [bridge.dict() for bridge in self.bridges.values()],
DATA_LISTENERS: [listener.dict() for listener in self.listeners.values()],
DATA_SENSORS: [sensor.dict() for sensor in self.sensors.values()],
}
if self.user_preferences:
data[DATA_USER_PREFERENCES] = self.user_preferences.dict()
return data
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@@ -121,11 +164,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_update() -> NotionData:
"""Get the latest data from the Notion API."""
data = NotionData()
data = NotionData(hass=hass, entry=entry)
tasks = {
"bridges": client.bridge.async_all(),
"listeners": client.sensor.async_listeners(),
"sensors": client.sensor.async_all(),
DATA_BRIDGES: client.bridge.async_all(),
DATA_LISTENERS: client.sensor.async_listeners(),
DATA_SENSORS: client.sensor.async_all(),
DATA_USER_PREFERENCES: client.user.async_preferences(),
}
results = await asyncio.gather(*tasks.values(), return_exceptions=True)
@@ -145,16 +189,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
f"There was an unknown error while updating {attr}: {result}"
) from result
for item in result:
if attr == "bridges":
# If a new bridge is discovered, register it:
if item.id not in data.bridges:
_async_register_new_bridge(hass, item, entry)
data.bridges[item.id] = item
elif attr == "listeners":
data.listeners[item.id] = item
else:
data.sensors[item.uuid] = item
data.update_data_from_response(result)
return data
@@ -216,7 +251,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@callback
def _async_register_new_bridge(
hass: HomeAssistant, bridge: Bridge, entry: ConfigEntry
hass: HomeAssistant, entry: ConfigEntry, bridge: Bridge
) -> None:
"""Register a new bridge."""
if name := bridge.name:
@@ -279,6 +314,11 @@ class NotionEntity(CoordinatorEntity[DataUpdateCoordinator[NotionData]]):
and self._listener_id in self.coordinator.data.listeners
)
@property
def listener(self) -> Listener:
"""Return the listener related to this entity."""
return self.coordinator.data.listeners[self._listener_id]
@callback
def _async_update_bridge_id(self) -> None:
"""Update the entity's bridge ID if it has changed.
@@ -310,21 +350,9 @@ class NotionEntity(CoordinatorEntity[DataUpdateCoordinator[NotionData]]):
this_device.id, via_device_id=bridge_device.id
)
@callback
def _async_update_from_latest_data(self) -> None:
"""Update the entity from the latest data."""
raise NotImplementedError
@callback
def _handle_coordinator_update(self) -> None:
"""Respond to a DataUpdateCoordinator update."""
if self._listener_id in self.coordinator.data.listeners:
self._async_update_bridge_id()
self._async_update_from_latest_data()
self.async_write_ha_state()
async def async_added_to_hass(self) -> None:
"""Handle entity which will be added."""
await super().async_added_to_hass()
self._async_update_from_latest_data()
super()._handle_coordinator_update()
@@ -13,7 +13,7 @@ from homeassistant.components.binary_sensor import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import NotionEntity
@@ -37,7 +37,7 @@ from .model import NotionEntityDescriptionMixin
class NotionBinarySensorDescriptionMixin:
"""Define an entity description mixin for binary and regular sensors."""
on_state: Literal["alarm", "critical", "leak", "not_missing", "open"]
on_state: Literal["alarm", "leak", "low", "not_missing", "open"]
@dataclass
@@ -56,7 +56,7 @@ BINARY_SENSOR_DESCRIPTIONS = (
device_class=BinarySensorDeviceClass.BATTERY,
entity_category=EntityCategory.DIAGNOSTIC,
listener_kind=ListenerKind.BATTERY,
on_state="critical",
on_state="low",
),
NotionBinarySensorDescription(
key=SENSOR_DOOR,
@@ -146,17 +146,10 @@ class NotionBinarySensor(NotionEntity, BinarySensorEntity):
entity_description: NotionBinarySensorDescription
@callback
def _async_update_from_latest_data(self) -> None:
"""Fetch new state data for the sensor."""
listener = self.coordinator.data.listeners[self._listener_id]
if listener.status.trigger_value:
state = listener.status.trigger_value
elif listener.insights.primary.value:
state = listener.insights.primary.value
else:
LOGGER.warning("Unknown listener structure: %s", listener)
state = None
self._attr_is_on = self.entity_description.on_state == state
@property
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
if not self.listener.insights.primary.value:
LOGGER.warning("Unknown listener structure: %s", self.listener.dict())
return False
return self.listener.insights.primary.value == self.entity_description.on_state
@@ -16,6 +16,7 @@ CONF_DEVICE_KEY = "device_key"
CONF_HARDWARE_ID = "hardware_id"
CONF_LAST_BRIDGE_HARDWARE_ID = "last_bridge_hardware_id"
CONF_TITLE = "title"
CONF_USER_ID = "user_id"
TO_REDACT = {
CONF_DEVICE_KEY,
@@ -27,6 +28,7 @@ TO_REDACT = {
CONF_TITLE,
CONF_UNIQUE_ID,
CONF_USERNAME,
CONF_USER_ID,
}
@@ -7,5 +7,5 @@
"integration_type": "hub",
"iot_class": "cloud_polling",
"loggers": ["aionotion"],
"requirements": ["aionotion==2023.04.2"]
"requirements": ["aionotion==2023.05.4"]
}
+22 -13
View File
@@ -11,11 +11,11 @@ from homeassistant.components.sensor import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import NotionEntity
from .const import DOMAIN, LOGGER, SENSOR_TEMPERATURE
from .const import DOMAIN, SENSOR_TEMPERATURE
from .model import NotionEntityDescriptionMixin
@@ -63,15 +63,24 @@ async def async_setup_entry(
class NotionSensor(NotionEntity, SensorEntity):
"""Define a Notion sensor."""
@callback
def _async_update_from_latest_data(self) -> None:
"""Fetch new state data for the sensor."""
listener = self.coordinator.data.listeners[self._listener_id]
@property
def native_unit_of_measurement(self) -> str | None:
"""Return the unit of measurement of the sensor."""
if self.listener.listener_kind == ListenerKind.TEMPERATURE:
if not self.coordinator.data.user_preferences:
return None
if self.coordinator.data.user_preferences.celsius_enabled:
return UnitOfTemperature.CELSIUS
return UnitOfTemperature.FAHRENHEIT
return None
if listener.listener_kind == ListenerKind.TEMPERATURE:
self._attr_native_value = round(listener.status.temperature, 1) # type: ignore[attr-defined]
else:
LOGGER.error(
"Unknown listener type for sensor %s",
self.coordinator.data.sensors[self._sensor_id],
)
@property
def native_value(self) -> str | None:
"""Return the value reported by the sensor.
The Notion API only returns a localized string for temperature (e.g. "70°"); we
simply remove the degree symbol:
"""
if not self.listener.status_localized:
return None
return self.listener.status_localized.state[:-1]
+21 -1
View File
@@ -1,4 +1,6 @@
"""The ONVIF integration."""
import asyncio
from http import HTTPStatus
import logging
from httpx import RequestError
@@ -55,8 +57,26 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except ONVIFError as err:
await device.device.close()
raise ConfigEntryNotReady(
f"Could not setup camera {device.device.host}:{device.device.port}: {err}"
f"Could not setup camera {device.device.host}:{device.device.port}: {stringify_onvif_error(err)}"
) from err
except TransportError as err:
await device.device.close()
stringified_onvif_error = stringify_onvif_error(err)
if err.status_code in (
HTTPStatus.UNAUTHORIZED.value,
HTTPStatus.FORBIDDEN.value,
):
raise ConfigEntryAuthFailed(
f"Auth Failed: {stringified_onvif_error}"
) from err
raise ConfigEntryNotReady(
f"Could not setup camera {device.device.host}:{device.device.port}: {stringified_onvif_error}"
) from err
except asyncio.CancelledError as err:
# After https://github.com/agronholm/anyio/issues/374 is resolved
# this may be able to be removed
await device.device.close()
raise ConfigEntryNotReady(f"Setup was unexpectedly canceled: {err}") from err
if not device.available:
raise ConfigEntryNotReady()
+1 -1
View File
@@ -34,7 +34,7 @@ class RebootButton(ONVIFBaseEntity, ButtonEntity):
async def async_press(self) -> None:
"""Send out a SystemReboot command."""
device_mgmt = self.device.device.create_devicemgmt_service()
device_mgmt = await self.device.device.create_devicemgmt_service()
await device_mgmt.SystemReboot()
+16 -3
View File
@@ -142,10 +142,14 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
hass.async_create_task(hass.config_entries.async_reload(entry_id))
return self.async_abort(reason="reauth_successful")
username = (user_input or {}).get(CONF_USERNAME) or entry.data[CONF_USERNAME]
return self.async_show_form(
step_id="reauth_confirm",
data_schema=vol.Schema(
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
{
vol.Required(CONF_USERNAME, default=username): str,
vol.Required(CONF_PASSWORD): str,
}
),
errors=errors,
description_placeholders=description_placeholders,
@@ -275,7 +279,7 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
try:
await device.update_xaddrs()
device_mgmt = device.create_devicemgmt_service()
device_mgmt = await device.create_devicemgmt_service()
# Get the MAC address to use as the unique ID for the config flow
if not self.device_id:
try:
@@ -314,8 +318,17 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
}
)
# Verify there is an H264 profile
media_service = device.create_media_service()
media_service = await device.create_media_service()
profiles = await media_service.GetProfiles()
except AttributeError: # Likely an empty document or 404 from the wrong port
LOGGER.debug(
"%s: No ONVIF service found at %s:%s",
self.onvif_config[CONF_NAME],
self.onvif_config[CONF_HOST],
self.onvif_config[CONF_PORT],
exc_info=True,
)
return {CONF_PORT: "no_onvif_service"}, {}
except Fault as err:
stringified_error = stringify_onvif_error(err)
description_placeholders = {"error": stringified_error}
+150 -87
View File
@@ -6,12 +6,13 @@ from contextlib import suppress
import datetime as dt
import os
import time
from typing import Any
from httpx import RequestError
import onvif
from onvif import ONVIFCamera
from onvif.exceptions import ONVIFError
from zeep.exceptions import Fault, XMLParseError
from zeep.exceptions import Fault, TransportError, XMLParseError, XMLSyntaxError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
@@ -55,6 +56,7 @@ class ONVIFDevice:
self.info: DeviceInfo = DeviceInfo()
self.capabilities: Capabilities = Capabilities()
self.onvif_capabilities: dict[str, Any] | None = None
self.profiles: list[Profile] = []
self.max_resolution: int = 0
self.platforms: list[Platform] = []
@@ -98,6 +100,11 @@ class ONVIFDevice:
# Get all device info
await self.device.update_xaddrs()
LOGGER.debug("%s: xaddrs = %s", self.name, self.device.xaddrs)
# Get device capabilities
self.onvif_capabilities = await self.device.get_capabilities()
await self.async_check_date_and_time()
# Create event manager
@@ -106,9 +113,20 @@ class ONVIFDevice:
# Fetch basic device info and capabilities
self.info = await self.async_get_device_info()
LOGGER.debug("Camera %s info = %s", self.name, self.info)
LOGGER.debug("%s: camera info = %s", self.name, self.info)
#
# We need to check capabilities before profiles, because we need the data
# from capabilities to determine profiles correctly.
#
# We no longer initialize events in capabilities to avoid the problem
# where cameras become slow to respond for a bit after starting events, and
# instead we start events last and than update capabilities.
#
LOGGER.debug("%s: fetching initial capabilities", self.name)
self.capabilities = await self.async_get_capabilities()
LOGGER.debug("Camera %s capabilities = %s", self.name, self.capabilities)
LOGGER.debug("%s: fetching profiles", self.name)
self.profiles = await self.async_get_profiles()
LOGGER.debug("Camera %s profiles = %s", self.name, self.profiles)
@@ -117,7 +135,8 @@ class ONVIFDevice:
raise ONVIFError("No camera profiles found")
if self.capabilities.ptz:
self.device.create_ptz_service()
LOGGER.debug("%s: creating PTZ service", self.name)
await self.device.create_ptz_service()
# Determine max resolution from profiles
self.max_resolution = max(
@@ -126,6 +145,12 @@ class ONVIFDevice:
if profile.video.encoding == "H264"
)
# Start events last since some cameras become slow to respond
# for a bit after starting events
LOGGER.debug("%s: starting events", self.name)
self.capabilities.events = await self.async_start_events()
LOGGER.debug("Camera %s capabilities = %s", self.name, self.capabilities)
async def async_stop(self, event=None):
"""Shut it all down."""
if self.events:
@@ -134,7 +159,7 @@ class ONVIFDevice:
async def async_manually_set_date_and_time(self) -> None:
"""Set Date and Time Manually using SetSystemDateAndTime command."""
device_mgmt = self.device.create_devicemgmt_service()
device_mgmt = await self.device.create_devicemgmt_service()
# Retrieve DateTime object from camera to use as template for Set operation
device_time = await device_mgmt.GetSystemDateAndTime()
@@ -177,82 +202,105 @@ class ONVIFDevice:
async def async_check_date_and_time(self) -> None:
"""Warns if device and system date not synced."""
LOGGER.debug("%s: Setting up the ONVIF device management service", self.name)
device_mgmt = self.device.create_devicemgmt_service()
device_mgmt = await self.device.create_devicemgmt_service()
system_date = dt_util.utcnow()
LOGGER.debug("%s: Retrieving current device date/time", self.name)
try:
system_date = dt_util.utcnow()
device_time = await device_mgmt.GetSystemDateAndTime()
if not device_time:
LOGGER.debug(
"""Couldn't get device '%s' date/time.
GetSystemDateAndTime() return null/empty""",
self.name,
)
return
LOGGER.debug("%s: Device time: %s", self.name, device_time)
tzone = dt_util.DEFAULT_TIME_ZONE
cdate = device_time.LocalDateTime
if device_time.UTCDateTime:
tzone = dt_util.UTC
cdate = device_time.UTCDateTime
elif device_time.TimeZone:
tzone = dt_util.get_time_zone(device_time.TimeZone.TZ) or tzone
if cdate is None:
LOGGER.warning(
"%s: Could not retrieve date/time on this camera", self.name
)
else:
cam_date = dt.datetime(
cdate.Date.Year,
cdate.Date.Month,
cdate.Date.Day,
cdate.Time.Hour,
cdate.Time.Minute,
cdate.Time.Second,
0,
tzone,
)
cam_date_utc = cam_date.astimezone(dt_util.UTC)
LOGGER.debug(
"%s: Device date/time: %s | System date/time: %s",
self.name,
cam_date_utc,
system_date,
)
dt_diff = cam_date - system_date
self._dt_diff_seconds = dt_diff.total_seconds()
# It could be off either direction, so we need to check the absolute value
if abs(self._dt_diff_seconds) > 5:
LOGGER.warning(
(
"The date/time on %s (UTC) is '%s', "
"which is different from the system '%s', "
"this could lead to authentication issues"
),
self.name,
cam_date_utc,
system_date,
)
if device_time.DateTimeType == "Manual":
# Set Date and Time ourselves if Date and Time is set manually in the camera.
await self.async_manually_set_date_and_time()
except RequestError as err:
LOGGER.warning(
"Couldn't get device '%s' date/time. Error: %s", self.name, err
)
return
if not device_time:
LOGGER.debug(
"""Couldn't get device '%s' date/time.
GetSystemDateAndTime() return null/empty""",
self.name,
)
return
LOGGER.debug("%s: Device time: %s", self.name, device_time)
tzone = dt_util.DEFAULT_TIME_ZONE
cdate = device_time.LocalDateTime
if device_time.UTCDateTime:
tzone = dt_util.UTC
cdate = device_time.UTCDateTime
elif device_time.TimeZone:
tzone = dt_util.get_time_zone(device_time.TimeZone.TZ) or tzone
if cdate is None:
LOGGER.warning("%s: Could not retrieve date/time on this camera", self.name)
return
cam_date = dt.datetime(
cdate.Date.Year,
cdate.Date.Month,
cdate.Date.Day,
cdate.Time.Hour,
cdate.Time.Minute,
cdate.Time.Second,
0,
tzone,
)
cam_date_utc = cam_date.astimezone(dt_util.UTC)
LOGGER.debug(
"%s: Device date/time: %s | System date/time: %s",
self.name,
cam_date_utc,
system_date,
)
dt_diff = cam_date - system_date
self._dt_diff_seconds = dt_diff.total_seconds()
# It could be off either direction, so we need to check the absolute value
if abs(self._dt_diff_seconds) < 5:
return
LOGGER.warning(
(
"The date/time on %s (UTC) is '%s', "
"which is different from the system '%s', "
"this could lead to authentication issues"
),
self.name,
cam_date_utc,
system_date,
)
if device_time.DateTimeType != "Manual":
return
# Set Date and Time ourselves if Date and Time is set manually in the camera.
try:
await self.async_manually_set_date_and_time()
except (RequestError, TransportError):
LOGGER.warning("%s: Could not sync date/time on this camera", self.name)
async def async_get_device_info(self) -> DeviceInfo:
"""Obtain information about this device."""
device_mgmt = self.device.create_devicemgmt_service()
device_info = await device_mgmt.GetDeviceInformation()
device_mgmt = await self.device.create_devicemgmt_service()
manufacturer = None
model = None
firmware_version = None
serial_number = None
try:
device_info = await device_mgmt.GetDeviceInformation()
except (XMLParseError, XMLSyntaxError, TransportError) as ex:
# Some cameras have invalid UTF-8 in their device information (TransportError)
# and others have completely invalid XML (XMLParseError, XMLSyntaxError)
LOGGER.warning("%s: Failed to fetch device information: %s", self.name, ex)
else:
manufacturer = device_info.Manufacturer
model = device_info.Model
firmware_version = device_info.FirmwareVersion
serial_number = device_info.SerialNumber
# Grab the last MAC address for backwards compatibility
mac = None
@@ -272,10 +320,10 @@ class ONVIFDevice:
)
return DeviceInfo(
device_info.Manufacturer,
device_info.Model,
device_info.FirmwareVersion,
device_info.SerialNumber,
manufacturer,
model,
firmware_version,
serial_number,
mac,
)
@@ -283,7 +331,7 @@ class ONVIFDevice:
"""Obtain information about the available services on the device."""
snapshot = False
with suppress(*GET_CAPABILITIES_EXCEPTIONS):
media_service = self.device.create_media_service()
media_service = await self.device.create_media_service()
media_capabilities = await media_service.GetServiceCapabilities()
snapshot = media_capabilities and media_capabilities.SnapshotUri
@@ -294,19 +342,34 @@ class ONVIFDevice:
imaging = False
with suppress(*GET_CAPABILITIES_EXCEPTIONS):
self.device.create_imaging_service()
await self.device.create_imaging_service()
imaging = True
events = False
with suppress(*GET_CAPABILITIES_EXCEPTIONS, XMLParseError):
events = await self.events.async_start()
return Capabilities(snapshot=snapshot, ptz=ptz, imaging=imaging)
return Capabilities(snapshot, events, ptz, imaging)
async def async_start_events(self):
"""Start the event handler."""
with suppress(*GET_CAPABILITIES_EXCEPTIONS, XMLParseError):
onvif_capabilities = self.onvif_capabilities or {}
pull_point_support = (onvif_capabilities.get("Events") or {}).get(
"WSPullPointSupport"
)
LOGGER.debug("%s: WSPullPointSupport: %s", self.name, pull_point_support)
return await self.events.async_start(pull_point_support is not False, True)
return False
async def async_get_profiles(self) -> list[Profile]:
"""Obtain media profiles for this device."""
media_service = self.device.create_media_service()
result = await media_service.GetProfiles()
media_service = await self.device.create_media_service()
LOGGER.debug("%s: xaddr for media_service: %s", self.name, media_service.xaddr)
try:
result = await media_service.GetProfiles()
except GET_CAPABILITIES_EXCEPTIONS:
LOGGER.debug(
"%s: Could not get profiles from ONVIF device", self.name, exc_info=True
)
raise
profiles: list[Profile] = []
if not isinstance(result, list):
@@ -345,7 +408,7 @@ class ONVIFDevice:
)
try:
ptz_service = self.device.create_ptz_service()
ptz_service = await self.device.create_ptz_service()
presets = await ptz_service.GetPresets(profile.token)
profile.ptz.presets = [preset.token for preset in presets if preset]
except GET_CAPABILITIES_EXCEPTIONS:
@@ -364,7 +427,7 @@ class ONVIFDevice:
async def async_get_stream_uri(self, profile: Profile) -> str:
"""Get the stream URI for a specified profile."""
media_service = self.device.create_media_service()
media_service = await self.device.create_media_service()
req = media_service.create_type("GetStreamUri")
req.ProfileToken = profile.token
req.StreamSetup = {
@@ -391,7 +454,7 @@ class ONVIFDevice:
LOGGER.warning("PTZ actions are not supported on device '%s'", self.name)
return
ptz_service = self.device.create_ptz_service()
ptz_service = await self.device.create_ptz_service()
pan_val = distance * PAN_FACTOR.get(pan, 0)
tilt_val = distance * TILT_FACTOR.get(tilt, 0)
@@ -513,7 +576,7 @@ class ONVIFDevice:
LOGGER.warning("PTZ actions are not supported on device '%s'", self.name)
return
ptz_service = self.device.create_ptz_service()
ptz_service = await self.device.create_ptz_service()
LOGGER.debug(
"Running Aux Command | Cmd = %s",
@@ -544,7 +607,7 @@ class ONVIFDevice:
)
return
imaging_service = self.device.create_imaging_service()
imaging_service = await self.device.create_imaging_service()
LOGGER.debug("Setting Imaging Setting | Settings = %s", settings)
try:
@@ -27,6 +27,10 @@ async def async_get_config_entry_diagnostics(
"info": asdict(device.info),
"capabilities": asdict(device.capabilities),
"profiles": [asdict(profile) for profile in device.profiles],
"services": {
str(key): service.url for key, service in device.device.services.items()
},
"xaddrs": device.device.xaddrs,
}
data["events"] = {
"webhook_manager_state": device.events.webhook_manager.state,
+96 -87
View File
@@ -9,9 +9,9 @@ import datetime as dt
from aiohttp.web import Request
from httpx import RemoteProtocolError, RequestError, TransportError
from onvif import ONVIFCamera, ONVIFService
from onvif.client import NotificationManager
from onvif.client import NotificationManager, retry_connection_error
from onvif.exceptions import ONVIFError
from zeep.exceptions import Fault, XMLParseError
from zeep.exceptions import Fault, ValidationError, XMLParseError
from homeassistant.components import webhook
from homeassistant.config_entries import ConfigEntry
@@ -35,13 +35,13 @@ from .util import stringify_onvif_error
UNHANDLED_TOPICS: set[str] = {"tns1:MediaControl/VideoEncoderConfiguration"}
SUBSCRIPTION_ERRORS = (Fault, asyncio.TimeoutError, TransportError)
CREATE_ERRORS = (ONVIFError, Fault, RequestError, XMLParseError)
CREATE_ERRORS = (ONVIFError, Fault, RequestError, XMLParseError, ValidationError)
SET_SYNCHRONIZATION_POINT_ERRORS = (*SUBSCRIPTION_ERRORS, TypeError)
UNSUBSCRIBE_ERRORS = (XMLParseError, *SUBSCRIPTION_ERRORS)
RENEW_ERRORS = (ONVIFError, RequestError, XMLParseError, *SUBSCRIPTION_ERRORS)
#
# We only keep the subscription alive for 3 minutes, and will keep
# renewing it every 1.5 minutes. This is to avoid the camera
# We only keep the subscription alive for 10 minutes, and will keep
# renewing it every 8 minutes. This is to avoid the camera
# accumulating subscriptions which will be impossible to clean up
# since ONVIF does not provide a way to list existing subscriptions.
#
@@ -49,12 +49,25 @@ RENEW_ERRORS = (ONVIFError, RequestError, XMLParseError, *SUBSCRIPTION_ERRORS)
# sending events to us, and we will not be able to recover until
# the subscriptions expire or the camera is rebooted.
#
SUBSCRIPTION_TIME = dt.timedelta(minutes=3)
SUBSCRIPTION_RELATIVE_TIME = (
"PT3M" # use relative time since the time on the camera is not reliable
)
SUBSCRIPTION_RENEW_INTERVAL = SUBSCRIPTION_TIME.total_seconds() / 2
SUBSCRIPTION_RENEW_INTERVAL_ON_ERROR = 60.0
SUBSCRIPTION_TIME = dt.timedelta(minutes=10)
# SUBSCRIPTION_RELATIVE_TIME uses a relative time since the time on the camera
# is not reliable. We use 600 seconds (10 minutes) since some cameras cannot
# parse time in the format "PT10M" (10 minutes).
SUBSCRIPTION_RELATIVE_TIME = "PT600S"
# SUBSCRIPTION_RENEW_INTERVAL Must be less than the
# overall timeout of 90 * (SUBSCRIPTION_ATTEMPTS) 2 = 180 seconds
#
# We use 8 minutes between renewals to make sure we never hit the
# 10 minute limit even if the first renewal attempt fails
SUBSCRIPTION_RENEW_INTERVAL = 8 * 60
# The number of attempts to make when creating or renewing a subscription
SUBSCRIPTION_ATTEMPTS = 2
# The time to wait before trying to restart the subscription if it fails
SUBSCRIPTION_RESTART_INTERVAL_ON_ERROR = 60
PULLPOINT_POLL_TIME = dt.timedelta(seconds=60)
PULLPOINT_MESSAGE_LIMIT = 100
@@ -123,11 +136,13 @@ class EventManager:
if not self._listeners:
self.pullpoint_manager.async_cancel_pull_messages()
async def async_start(self) -> bool:
async def async_start(self, try_pullpoint: bool, try_webhook: bool) -> bool:
"""Start polling events."""
# Always start pull point first, since it will populate the event list
event_via_pull_point = await self.pullpoint_manager.async_start()
events_via_webhook = await self.webhook_manager.async_start()
event_via_pull_point = (
try_pullpoint and await self.pullpoint_manager.async_start()
)
events_via_webhook = try_webhook and await self.webhook_manager.async_start()
return events_via_webhook or event_via_pull_point
async def async_stop(self) -> None:
@@ -274,7 +289,13 @@ class PullPointManager:
"""Pause pullpoint subscription."""
LOGGER.debug("%s: Pausing PullPoint manager", self._name)
self.state = PullPointManagerState.PAUSED
self._hass.async_create_task(self._async_cancel_and_unsubscribe())
# Cancel the renew job so we don't renew the subscription
# and stop pulling messages.
self._async_cancel_pullpoint_renew()
self.async_cancel_pull_messages()
# We do not unsubscribe from the pullpoint subscription and instead
# let the subscription expire since some cameras will terminate all
# subscriptions if we unsubscribe which will break the webhook.
@callback
def async_resume(self) -> None:
@@ -325,20 +346,7 @@ class PullPointManager:
async def _async_start_pullpoint(self) -> bool:
"""Start pullpoint subscription."""
try:
try:
started = await self._async_create_pullpoint_subscription()
except RequestError:
#
# We should only need to retry on RemoteProtocolError but some cameras
# are flaky and sometimes do not respond to the Renew request so we
# retry on RequestError as well.
#
# For RemoteProtocolError:
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
# to close the connection at any time, we treat this as a normal and try again
# once since we do not want to declare the camera as not supporting PullPoint
# if it just happened to close the connection at the wrong time.
started = await self._async_create_pullpoint_subscription()
started = await self._async_create_pullpoint_subscription()
except CREATE_ERRORS as err:
LOGGER.debug(
"%s: Device does not support PullPoint service or has too many subscriptions: %s",
@@ -370,16 +378,16 @@ class PullPointManager:
# scheduled when the current one is done if needed.
return
async with self._renew_lock:
next_attempt = SUBSCRIPTION_RENEW_INTERVAL_ON_ERROR
next_attempt = SUBSCRIPTION_RESTART_INTERVAL_ON_ERROR
try:
if (
await self._async_renew_pullpoint()
or await self._async_restart_pullpoint()
):
if await self._async_renew_pullpoint():
next_attempt = SUBSCRIPTION_RENEW_INTERVAL
else:
await self._async_restart_pullpoint()
finally:
self.async_schedule_pullpoint_renew(next_attempt)
@retry_connection_error(SUBSCRIPTION_ATTEMPTS)
async def _async_create_pullpoint_subscription(self) -> bool:
"""Create pullpoint subscription."""
@@ -390,12 +398,12 @@ class PullPointManager:
return False
# Create subscription manager
self._pullpoint_subscription = self._device.create_subscription_service(
self._pullpoint_subscription = await self._device.create_subscription_service(
"PullPointSubscription"
)
# Create the service that will be used to pull messages from the device.
self._pullpoint_service = self._device.create_pullpoint_service()
self._pullpoint_service = await self._device.create_pullpoint_service()
# Initialize events
with suppress(*SET_SYNCHRONIZATION_POINT_ERRORS):
@@ -445,6 +453,11 @@ class PullPointManager:
)
self._pullpoint_subscription = None
@retry_connection_error(SUBSCRIPTION_ATTEMPTS)
async def _async_call_pullpoint_subscription_renew(self) -> None:
"""Call PullPoint subscription Renew."""
await self._pullpoint_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
async def _async_renew_pullpoint(self) -> bool:
"""Renew the PullPoint subscription."""
if (
@@ -456,20 +469,7 @@ class PullPointManager:
# The first time we renew, we may get a Fault error so we
# suppress it. The subscription will be restarted in
# async_restart later.
try:
await self._pullpoint_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
except RequestError:
#
# We should only need to retry on RemoteProtocolError but some cameras
# are flaky and sometimes do not respond to the Renew request so we
# retry on RequestError as well.
#
# For RemoteProtocolError:
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
# to close the connection at any time, we treat this as a normal and try again
# once since we do not want to mark events as stale
# if it just happened to close the connection at the wrong time.
await self._pullpoint_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
await self._async_call_pullpoint_subscription_renew()
LOGGER.debug("%s: Renewed PullPoint subscription", self._name)
return True
except RENEW_ERRORS as err:
@@ -519,7 +519,7 @@ class PullPointManager:
stringify_onvif_error(err),
)
return True
except (XMLParseError, *SUBSCRIPTION_ERRORS) as err:
except Fault as err:
# Device may not support subscriptions so log at debug level
# when we get an XMLParseError
LOGGER.debug(
@@ -530,6 +530,16 @@ class PullPointManager:
# Treat errors as if the camera restarted. Assume that the pullpoint
# subscription is no longer valid.
return False
except (XMLParseError, RequestError, TimeoutError, TransportError) as err:
LOGGER.debug(
"%s: PullPoint subscription encountered an unexpected error and will be retried "
"(this is normal for some cameras): %s",
self._name,
stringify_onvif_error(err),
)
# Avoid renewing the subscription too often since it causes problems
# for some cameras, mainly the Tapo ones.
return True
if self.state != PullPointManagerState.STARTED:
# If the webhook became started working during the long poll,
@@ -653,36 +663,42 @@ class WebHookManager:
self._renew_or_restart_job,
)
@retry_connection_error(SUBSCRIPTION_ATTEMPTS)
async def _async_create_webhook_subscription(self) -> None:
"""Create webhook subscription."""
LOGGER.debug("%s: Creating webhook subscription", self._name)
LOGGER.debug(
"%s: Creating webhook subscription with URL: %s",
self._name,
self._webhook_url,
)
self._notification_manager = self._device.create_notification_manager(
{
"InitialTerminationTime": SUBSCRIPTION_RELATIVE_TIME,
"ConsumerReference": {"Address": self._webhook_url},
}
)
self._webhook_subscription = await self._notification_manager.setup()
try:
self._webhook_subscription = await self._notification_manager.setup()
except ValidationError as err:
# This should only happen if there is a problem with the webhook URL
# that is causing it to not be well formed.
LOGGER.exception(
"%s: validation error while creating webhook subscription: %s",
self._name,
err,
)
raise
await self._notification_manager.start()
LOGGER.debug("%s: Webhook subscription created", self._name)
LOGGER.debug(
"%s: Webhook subscription created with URL: %s",
self._name,
self._webhook_url,
)
async def _async_start_webhook(self) -> bool:
"""Start webhook."""
try:
try:
await self._async_create_webhook_subscription()
except RequestError:
#
# We should only need to retry on RemoteProtocolError but some cameras
# are flaky and sometimes do not respond to the Renew request so we
# retry on RequestError as well.
#
# For RemoteProtocolError:
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
# to close the connection at any time, we treat this as a normal and try again
# once since we do not want to declare the camera as not supporting webhooks
# if it just happened to close the connection at the wrong time.
await self._async_create_webhook_subscription()
await self._async_create_webhook_subscription()
except CREATE_ERRORS as err:
self._event_manager.async_webhook_failed()
LOGGER.debug(
@@ -700,6 +716,12 @@ class WebHookManager:
await self._async_unsubscribe_webhook()
return await self._async_start_webhook()
@retry_connection_error(SUBSCRIPTION_ATTEMPTS)
async def _async_call_webhook_subscription_renew(self) -> None:
"""Call PullPoint subscription Renew."""
assert self._webhook_subscription is not None
await self._webhook_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
async def _async_renew_webhook(self) -> bool:
"""Renew webhook subscription."""
if (
@@ -708,20 +730,7 @@ class WebHookManager:
):
return False
try:
try:
await self._webhook_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
except RequestError:
#
# We should only need to retry on RemoteProtocolError but some cameras
# are flaky and sometimes do not respond to the Renew request so we
# retry on RequestError as well.
#
# For RemoteProtocolError:
# http://datatracker.ietf.org/doc/html/rfc2616#section-8.1.4 allows the server
# to close the connection at any time, we treat this as a normal and try again
# once since we do not want to mark events as stale
# if it just happened to close the connection at the wrong time.
await self._webhook_subscription.Renew(SUBSCRIPTION_RELATIVE_TIME)
await self._async_call_webhook_subscription_renew()
LOGGER.debug("%s: Renewed Webhook subscription", self._name)
return True
except RENEW_ERRORS as err:
@@ -745,13 +754,12 @@ class WebHookManager:
# scheduled when the current one is done if needed.
return
async with self._renew_lock:
next_attempt = SUBSCRIPTION_RENEW_INTERVAL_ON_ERROR
next_attempt = SUBSCRIPTION_RESTART_INTERVAL_ON_ERROR
try:
if (
await self._async_renew_webhook()
or await self._async_restart_webhook()
):
if await self._async_renew_webhook():
next_attempt = SUBSCRIPTION_RENEW_INTERVAL
else:
await self._async_restart_webhook()
finally:
self._async_schedule_webhook_renew(next_attempt)
@@ -769,6 +777,7 @@ class WebHookManager:
return
webhook_id = self._webhook_unique_id
self._async_unregister_webhook()
webhook.async_register(
self._hass, DOMAIN, webhook_id, webhook_id, self._async_handle_webhook
)
+1 -1
View File
@@ -8,5 +8,5 @@
"documentation": "https://www.home-assistant.io/integrations/onvif",
"iot_class": "local_push",
"loggers": ["onvif", "wsdiscovery", "zeep"],
"requirements": ["onvif-zeep-async==1.3.0", "WSDiscovery==2.0.0"]
"requirements": ["onvif-zeep-async==2.1.1", "WSDiscovery==2.0.0"]
}
+47 -9
View File
@@ -15,6 +15,19 @@ PARSERS: Registry[
str, Callable[[str, Any], Coroutine[Any, Any, Event | None]]
] = Registry()
VIDEO_SOURCE_MAPPING = {
"vsconf": "VideoSourceToken",
}
def _normalize_video_source(source: str) -> str:
"""Normalize video source.
Some cameras do not set the VideoSourceToken correctly so we get duplicate
sensors, so we need to normalize it to the correct value.
"""
return VIDEO_SOURCE_MAPPING.get(source, source)
def local_datetime_or_none(value: str) -> datetime.datetime | None:
"""Convert strings to datetimes, if invalid, return None."""
@@ -188,7 +201,7 @@ async def async_parse_field_detector(uid: str, msg) -> Event | None:
rule = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "VideoSourceConfigurationToken":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
if source.Name == "VideoAnalyticsConfigurationToken":
video_analytics = source.Value
if source.Name == "Rule":
@@ -220,7 +233,7 @@ async def async_parse_cell_motion_detector(uid: str, msg) -> Event | None:
rule = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "VideoSourceConfigurationToken":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
if source.Name == "VideoAnalyticsConfigurationToken":
video_analytics = source.Value
if source.Name == "Rule":
@@ -251,7 +264,7 @@ async def async_parse_motion_region_detector(uid: str, msg) -> Event | None:
rule = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "VideoSourceConfigurationToken":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
if source.Name == "VideoAnalyticsConfigurationToken":
video_analytics = source.Value
if source.Name == "Rule":
@@ -282,7 +295,7 @@ async def async_parse_tamper_detector(uid: str, msg) -> Event | None:
rule = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "VideoSourceConfigurationToken":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
if source.Name == "VideoAnalyticsConfigurationToken":
video_analytics = source.Value
if source.Name == "Rule":
@@ -312,7 +325,7 @@ async def async_parse_dog_cat_detector(uid: str, msg) -> Event | None:
video_source = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "Source":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
return Event(
f"{uid}_{msg.Topic._value_1}_{video_source}",
@@ -337,7 +350,7 @@ async def async_parse_vehicle_detector(uid: str, msg) -> Event | None:
video_source = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "Source":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
return Event(
f"{uid}_{msg.Topic._value_1}_{video_source}",
@@ -362,7 +375,7 @@ async def async_parse_person_detector(uid: str, msg) -> Event | None:
video_source = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "Source":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
return Event(
f"{uid}_{msg.Topic._value_1}_{video_source}",
@@ -387,7 +400,7 @@ async def async_parse_face_detector(uid: str, msg) -> Event | None:
video_source = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "Source":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
return Event(
f"{uid}_{msg.Topic._value_1}_{video_source}",
@@ -401,6 +414,31 @@ async def async_parse_face_detector(uid: str, msg) -> Event | None:
return None
@PARSERS.register("tns1:RuleEngine/MyRuleDetector/Visitor")
# pylint: disable=protected-access
async def async_parse_visitor_detector(uid: str, msg) -> Event | None:
"""Handle parsing event message.
Topic: tns1:RuleEngine/MyRuleDetector/Visitor
"""
try:
video_source = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "Source":
video_source = _normalize_video_source(source.Value)
return Event(
f"{uid}_{msg.Topic._value_1}_{video_source}",
"Visitor Detection",
"binary_sensor",
"occupancy",
None,
msg.Message._value_1.Data.SimpleItem[0].Value == "true",
)
except (AttributeError, KeyError):
return None
@PARSERS.register("tns1:Device/Trigger/DigitalInput")
# pylint: disable=protected-access
async def async_parse_digital_input(uid: str, msg) -> Event | None:
@@ -658,7 +696,7 @@ async def async_parse_count_aggregation_counter(uid: str, msg) -> Event | None:
rule = ""
for source in msg.Message._value_1.Source.SimpleItem:
if source.Name == "VideoSourceConfigurationToken":
video_source = source.Value
video_source = _normalize_video_source(source.Value)
if source.Name == "VideoAnalyticsConfigurationToken":
video_analytics = source.Value
if source.Name == "Rule":
@@ -11,6 +11,7 @@
"error": {
"onvif_error": "Error setting up ONVIF device: {error}. Check logs for more information.",
"auth_failed": "Could not authenticate: {error}",
"no_onvif_service": "No ONVIF service found. Check that the port number is correct.",
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
},
"step": {
@@ -46,6 +47,7 @@
},
"reauth_confirm": {
"title": "Reauthenticate the ONVIF device",
"description": "Some devices will reject authentication if the time is out of sync by more than 5 seconds. If authentication is unsuccessful, verify the time on the device is correct and try again.",
"data": {
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]"
+7 -2
View File
@@ -18,7 +18,12 @@ def stringify_onvif_error(error: Exception) -> str:
if isinstance(error, Fault):
message = error.message
if error.detail:
message += ": " + error.detail
# Detail may be a bytes object, so we need to convert it to string
if isinstance(error.detail, bytes):
detail = error.detail.decode("utf-8", "replace")
else:
detail = str(error.detail)
message += ": " + detail
if error.code:
message += f" (code:{error.code})"
if error.subcodes:
@@ -29,7 +34,7 @@ def stringify_onvif_error(error: Exception) -> str:
message += f" (actor:{error.actor})"
else:
message = str(error)
return message or "Device sent empty error"
return message or f"Device sent empty error with type {type(error)}"
def is_auth_error(error: Exception) -> bool:
+2 -1
View File
@@ -38,7 +38,8 @@ DEFAULT_ALTITUDE = 0
EVENT_OPENSKY_ENTRY = f"{DOMAIN}_entry"
EVENT_OPENSKY_EXIT = f"{DOMAIN}_exit"
SCAN_INTERVAL = timedelta(seconds=12) # opensky public limit is 10 seconds
# OpenSky free user has 400 credits, with 4 credits per API call. 100/24 = ~4 requests per hour
SCAN_INTERVAL = timedelta(minutes=15)
OPENSKY_API_URL = "https://opensky-network.org/api/states/all"
OPENSKY_API_FIELDS = [
@@ -13,7 +13,7 @@
"integration_type": "hub",
"iot_class": "cloud_polling",
"loggers": ["boto3", "botocore", "pyhumps", "pyoverkiz", "s3transfer"],
"requirements": ["pyoverkiz==1.7.7"],
"requirements": ["pyoverkiz==1.7.8"],
"zeroconf": [
{
"type": "_kizbox._tcp.local.",
+4 -23
View File
@@ -3,7 +3,7 @@ from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any, cast
from typing import Any
from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
from pyoverkiz.enums.ui import UIClass, UIWidget
@@ -15,12 +15,12 @@ from homeassistant.components.switch import (
SwitchEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.const import EntityCategory, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HomeAssistantOverkizData
from .const import DOMAIN, IGNORED_OVERKIZ_DEVICES
from .const import DOMAIN
from .entity import OverkizDescriptiveEntity
@@ -107,19 +107,6 @@ SWITCH_DESCRIPTIONS: list[OverkizSwitchDescription] = [
),
entity_category=EntityCategory.CONFIG,
),
OverkizSwitchDescription(
key=UIWidget.DYNAMIC_SHUTTER,
name="Silent mode",
turn_on=OverkizCommand.ACTIVATE_OPTION,
turn_on_args=OverkizCommandParam.SILENCE,
turn_off=OverkizCommand.DEACTIVATE_OPTION,
turn_off_args=OverkizCommandParam.SILENCE,
is_on=lambda select_state: (
OverkizCommandParam.SILENCE
in cast(list, select_state(OverkizState.CORE_ACTIVATED_OPTIONS))
),
icon="mdi:feather",
),
]
SUPPORTED_DEVICES = {
@@ -136,13 +123,7 @@ async def async_setup_entry(
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
entities: list[OverkizSwitch] = []
for device in data.coordinator.data.values():
if (
device.widget in IGNORED_OVERKIZ_DEVICES
or device.ui_class in IGNORED_OVERKIZ_DEVICES
):
continue
for device in data.platforms[Platform.SWITCH]:
if description := SUPPORTED_DEVICES.get(device.widget) or SUPPORTED_DEVICES.get(
device.ui_class
):
@@ -7,6 +7,6 @@
"integration_type": "hub",
"iot_class": "local_polling",
"loggers": ["crcmod", "plugwise"],
"requirements": ["plugwise==0.31.0"],
"requirements": ["plugwise==0.31.1"],
"zeroconf": ["_plugwise._tcp.local."]
}
+1 -1
View File
@@ -7,5 +7,5 @@
"integration_type": "service",
"iot_class": "cloud_polling",
"quality_scale": "platinum",
"requirements": ["vehicle==1.0.0"]
"requirements": ["vehicle==1.0.1"]
}
@@ -8,6 +8,7 @@ from ..schema import (
correct_db_schema_precision,
correct_db_schema_utf8,
validate_db_schema_precision,
validate_table_schema_has_correct_collation,
validate_table_schema_supports_utf8,
)
@@ -17,9 +18,12 @@ if TYPE_CHECKING:
def validate_db_schema(instance: Recorder) -> set[str]:
"""Do some basic checks for common schema errors caused by manual migration."""
return validate_table_schema_supports_utf8(
schema_errors = validate_table_schema_supports_utf8(
instance, EventData, (EventData.shared_data,)
) | validate_db_schema_precision(instance, Events)
for table in (Events, EventData):
schema_errors |= validate_table_schema_has_correct_collation(instance, table)
return schema_errors
def correct_db_schema(
@@ -27,5 +31,6 @@ def correct_db_schema(
schema_errors: set[str],
) -> None:
"""Correct issues detected by validate_db_schema."""
correct_db_schema_utf8(instance, EventData, schema_errors)
for table in (Events, EventData):
correct_db_schema_utf8(instance, table, schema_errors)
correct_db_schema_precision(instance, Events, schema_errors)
@@ -5,6 +5,7 @@ from collections.abc import Iterable, Mapping
import logging
from typing import TYPE_CHECKING
from sqlalchemy import MetaData
from sqlalchemy.exc import OperationalError
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm.attributes import InstrumentedAttribute
@@ -60,6 +61,60 @@ def validate_table_schema_supports_utf8(
return schema_errors
def validate_table_schema_has_correct_collation(
instance: Recorder,
table_object: type[DeclarativeBase],
) -> set[str]:
"""Verify the table has the correct collation."""
schema_errors: set[str] = set()
# Lack of full utf8 support is only an issue for MySQL / MariaDB
if instance.dialect_name != SupportedDialect.MYSQL:
return schema_errors
try:
schema_errors = _validate_table_schema_has_correct_collation(
instance, table_object
)
except Exception as exc: # pylint: disable=broad-except
_LOGGER.exception("Error when validating DB schema: %s", exc)
_log_schema_errors(table_object, schema_errors)
return schema_errors
def _validate_table_schema_has_correct_collation(
instance: Recorder,
table_object: type[DeclarativeBase],
) -> set[str]:
"""Ensure the table has the correct collation to avoid union errors with mixed collations."""
schema_errors: set[str] = set()
# Mark the session as read_only to ensure that the test data is not committed
# to the database and we always rollback when the scope is exited
with session_scope(session=instance.get_session(), read_only=True) as session:
table = table_object.__tablename__
metadata_obj = MetaData()
connection = session.connection()
metadata_obj.reflect(bind=connection)
dialect_kwargs = metadata_obj.tables[table].dialect_kwargs
# Check if the table has a collation set, if its not set than its
# using the server default collation for the database
collate = (
dialect_kwargs.get("mysql_collate")
or dialect_kwargs.get(
"mariadb_collate"
) # pylint: disable-next=protected-access
or connection.dialect._fetch_setting(connection, "collation_server") # type: ignore[attr-defined]
)
if collate and collate != "utf8mb4_unicode_ci":
_LOGGER.debug(
"Database %s collation is not utf8mb4_unicode_ci",
table,
)
schema_errors.add(f"{table}.utf8mb4_unicode_ci")
return schema_errors
def _validate_table_schema_supports_utf8(
instance: Recorder,
table_object: type[DeclarativeBase],
@@ -184,7 +239,10 @@ def correct_db_schema_utf8(
) -> None:
"""Correct utf8 issues detected by validate_db_schema."""
table_name = table_object.__tablename__
if f"{table_name}.4-byte UTF-8" in schema_errors:
if (
f"{table_name}.4-byte UTF-8" in schema_errors
or f"{table_name}.utf8mb4_unicode_ci" in schema_errors
):
from ..migration import ( # pylint: disable=import-outside-toplevel
_correct_table_character_set_and_collation,
)
@@ -8,6 +8,7 @@ from ..schema import (
correct_db_schema_precision,
correct_db_schema_utf8,
validate_db_schema_precision,
validate_table_schema_has_correct_collation,
validate_table_schema_supports_utf8,
)
@@ -26,6 +27,8 @@ def validate_db_schema(instance: Recorder) -> set[str]:
for table, columns in TABLE_UTF8_COLUMNS.items():
schema_errors |= validate_table_schema_supports_utf8(instance, table, columns)
schema_errors |= validate_db_schema_precision(instance, States)
for table in (States, StateAttributes):
schema_errors |= validate_table_schema_has_correct_collation(instance, table)
return schema_errors

Some files were not shown because too many files have changed in this diff Show More