Commit Graph

133 Commits (58f7dd5dcc92437f16b57fd57d26030cf4e1fdd5)

Author SHA1 Message Date
Jan Bouwhuis b93aa760c5
Refactor the MQTT option and reconfigure flow (#133342)
* Move entry options to entry.options en remove broker setup from mqtt option flow

* UPdate diagnostics to export both entry data and options

* Parameterize entry options directly not depending on migration

* Update tests to use v2 entry and add separate migration test

* use start_reconfigure_flow helper

* Update quality scale comment

* Do minor entry upgrade, and do not force to upgrade entry

* Ensure options are read from older entries

* Add comment

* Follow up on code review

* Assert config entry version checking the broker connection

* Update comment
2025-01-13 19:00:18 +01:00
epenet 02956f9a83
Improve formatting in component test files (#135267)
Improve formatting in test files
2025-01-10 10:53:45 +01:00
Jan Bouwhuis a6cb6fd239
Create MQTT device referenced by via device (#131588) 2024-11-27 18:12:46 +01:00
Jan Bouwhuis 1773f2aadc
Allow MQTT device based auto discovery (#118757)
* Allow MQTT device based auto discovery

* Fix merge error

* Remove unused import

* Fix discovery device based topics

* Fix cannot delete twice

* Improve cleanup test

* Follow up comment

* Typo

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Explain more

* Use tuple

* Default a device payload to have priority over a platform based payload

* Add unique_id to sensor test data

* Set migration flag to mark a discovery topic for migration

* Correct type hint

* Make unique_id required for components in device based discovery payload

* Remove CONF_MIGRATE_DISCOVERY from platform schema

* Unload discovered MQTT item to allow migration

* Follow up comments from code review

* ruff

* Subscribe to platform discovery wildcards first

* Use normal dict

* Use dict to persist wildcard subscription order

* Remove missed unused parameter

* Add a comment to explain we use a dict  to preserve the subscription order

* Add wildcard subscription order test

* Remove discovery flag from test

* Improve discovery migration origin logging

* Assert initial  wildcard discovery topics subscription order and after reconnect

* Improve log messages

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-10-30 17:10:15 +01:00
Jan Bouwhuis d237180a98
Allow re-discovery of mqtt integration config payloads (#127362) 2024-10-26 07:21:52 +02:00
Jan Bouwhuis f99b7d8b78
Start mqtt integration discovery config flow only once if config has not changed (#126966)
* Start mqtt integration config flow only once

* Remember last config message

* Filter out instead of unsubscribing the intehration discovery topic

* Follow up comments from code review
2024-09-30 12:44:40 +02:00
Jan Bouwhuis 7fde2e2fe0
Do not unsubscribe mqtt integration discovery if entry is already configured (#126907)
* Do not unsubscribe mqtt integration discovery if entry is already configured

* Test cases without unsubscribe
2024-09-27 17:28:51 +02:00
Jan Bouwhuis b74aced6f3
Subscribe per component for MQTT discovery (#119974)
* Subscribe per component for MQTT discovery

* Use single assignment

* Handle wildcard subscriptions first

* Split subsRecription handling, update helper

* Fix help_all_subscribe_calls

* Fix import

* Fix test

* Update import order

* Undo move self._last_subscribe

* Recover removed test

* Revert not needed changes to binary_sensor platform tests

* Revert line removal

* Rework interation of discovery topics

* Reduce

* Add comment

* Move comment

* Chain subscriptions
2024-08-20 17:02:48 +02:00
J. Nick Koston 7002042119
Fix blocking I/O in mqtt tests (#121140) 2024-07-04 05:13:13 +01:00
Erik Montnemery 9bbeb5d608
Add primary_config_entry attribute to device registry entries (#119959)
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Robert Resch <robert@resch.dev>
2024-06-26 12:26:24 +02:00
Jan Bouwhuis e567f8f3d5
Fix issue where an MQTT device is removed linked to two config entries (#120430)
* Fix issue where an MQTT device is removed linked to two config entries

* Update homeassistant/components/mqtt/discovery.py

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

* Update homeassistant/components/mqtt/debug_info.py

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

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-06-26 09:14:33 +02:00
Jan Bouwhuis fab901f9b6
Cleanup mqtt platform tests part 2 (#120490) 2024-06-26 08:53:28 +02:00
Jan Bouwhuis a7200a70b2
Set up mqtt tests from client fixture of mqtt entry setup fixture, not both (#120274)
* Fix entry setup and cleanup issues in mqtt tests

* Reduce changes by using mqtt_client_mock alias

* Reduce sleep time where possibe
2024-06-24 19:42:32 +02:00
Jan Bouwhuis 85720f9e02
Fix setup and tear down issues for mqtt discovery and config flow tests (#120333)
* Fix setup and tear down issues for mqtt discovery and config flow tests

* Use async callback
2024-06-24 16:20:44 +02:00
Paulus Schoutsen eb89ce47ea
Inline primary integration (#119860) 2024-06-18 08:08:08 +02:00
Jan Bouwhuis e799270578
Recover mqtt abbrevations optimizations (#118762)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-06-04 06:20:18 +02:00
Jan Bouwhuis 39f5f30ca9
Revert "Allow MQTT device based auto discovery" (#118746)
Revert "Allow MQTT device based auto discovery (#109030)"

This reverts commit 585892f067.
2024-06-03 22:30:37 +02:00
Jan Bouwhuis 585892f067
Allow MQTT device based auto discovery (#109030)
* Add MQTT device based auto discovery

* Respect override of component options over shared ones

* Add state_topic, command_topic, qos and encoding as shared options

* Add shared option test

* Rename device.py to schemas.py

* Remove unused legacy `platform` attribute to avoid confusion

* Split validation device and origin info

* Require `origin` info on device based discovery

* Log origin info for only once for device discovery

* Fix tests and linters

* ruff

* speed up _replace_all_abbreviations

* Fix imports and merging errors - add slots attr

* Fix unrelated const changes

* More unrelated changes

* join string

* fix merge

* Undo move

* Adjust logger statement

* fix task storm to load platforms

* Revert "fix task storm to load platforms"

This reverts commit 8f12a5f251.

* bail if logging is disabled

* Correct mixup object_id and node_id

* Auto migrate entities to device discovery

* Add device discovery test for device_trigger

* Add migration support for non entity platforms

* Use helper to remove discovery payload

* Fix tests after update branch

* Add discovery migration test

* Refactor

* Repair after rebase

* Fix discovery is broken after migration

* Improve comments

* More comment improvements

* Split long lines

* Add comment to indicate payload dict can be empty

* typo

* Add walrus and update comment

* Add tag to migration test

* Join try blocks

* Refactor

* Cleanup not used attribute

* Refactor

* Move _replace_all_abbreviations out of try block

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-29 11:12:05 +02:00
Jan Bouwhuis bfc3194661
Fix mqtt not publishing null payload payload to remove discovery (#118261) 2024-05-27 12:53:22 -10:00
J. Nick Koston c15f7f304f
Remove unneeded dispatcher in mqtt discovery (#118205) 2024-05-26 17:07:24 -10:00
Jan Bouwhuis 821c7d813d
Correct formatting mqtt MQTT_DISCOVERY_DONE and MQTT_DISCOVERY_UPDATED message (#116947) 2024-05-06 22:32:46 +02:00
Jan Bouwhuis bedd5c1cef
Cleanup removed MQTT broker settings (#116633) 2024-05-02 20:37:21 +02:00
epenet ad84ff18eb
Use remove_device helper in tests (1/2) (#116240)
* Use remove_device helper in tests

* Update test_tag.py

* Update test_tag.py
2024-04-30 12:52:33 +02:00
J. Nick Koston 0ed56694b0
Migrate MQTT EnsureJobAfterCooldown to use eager start (#115977) 2024-04-22 20:09:45 +02:00
Joost Lekkerkerker 6bb4e7d62c
Bump ruff to 0.3.4 (#112690)
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
Jan Bouwhuis 18174ad47d
Improve test coverage mqtt discovery test (#114188) 2024-03-25 22:41:11 +01:00
Joost Lekkerkerker 595d07f1c6
Improve lists in integrations [L-M] (#113227)
* Improve lists in integrations [L-M]

* Update homeassistant/components/mailbox/__init__.py

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>

* Fix

---------

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
2024-03-13 21:28:21 +01:00
Jan Bouwhuis caaa03536b
Cleanup mqtt PLATFORMS constant and CI-test platform filters (#112847) 2024-03-09 23:48:54 +01:00
Jan Bouwhuis 6534943837
Revert "Cleanup mqtt discovery code" (#112818)
Revert "Cleanup mqtt discovery code (#112749)"

This reverts commit 87318c9111.
2024-03-09 12:54:10 +01:00
Jan Bouwhuis 87318c9111
Cleanup mqtt discovery code (#112749)
* Cleanup mqtt discovery code

* Cleanup mqtt discovery code
2024-03-09 11:54:27 +01:00
Marc Mueller 32f3f46542
Add empty line after module docstring (2) [tests.components] (#112737) 2024-03-08 19:16:21 +01:00
Jan Bouwhuis f4fd3633b4
Improve timing mqtt integration discovery test (#110960)
* Improve timing mqtt integration discovery test

* Remove condition
2024-02-19 20:16:06 +01:00
J. Nick Koston b35d7a348b
Fix mqtt discovery subscribe unsubscribe test with one less task (#110914)
This test currently relies on event loop overhead and since #110899
will remove another task in the config entry init flow, it needs
another async_block_till_done. In the future it should be refactored
to have better synchronization without having to rely on iterations
of the event loop.
2024-02-19 07:36:32 +01:00
Jan Bouwhuis 9ad3c8dbc9
Remove MQTT legacy vacuum support (#107274) 2024-01-08 09:22:43 +01:00
Martin Hjelmare b3211fa5ee
Clean mqtt patch.dict config entries (#104449) 2023-11-24 10:56:17 +01:00
Erik Montnemery 4536fb3541
Remove mock_entity_platform test helper (#104073) 2023-11-16 16:55:08 +01:00
Jan Bouwhuis d6a0f9b5a0
Give mqtt test more time to process subscriptions (#103006) 2023-10-30 06:02:03 +01:00
Jan Bouwhuis c377cf1ce0
Do not fail mqtt entry on single platform config schema error (#101373)
* Do not fail mqtt entry on platform config

* Raise on reload with invalid config

* Do not store issues

* Follow up
2023-10-19 12:06:33 +02:00
Jan Bouwhuis 55bf309d2f
Add mqtt discovery schema error tests for all platforms (#101583)
Add mqtt discovery schema error tests
2023-10-07 21:00:33 +02:00
Jan Bouwhuis a3fe120457
Raise vol.Invalid for invalid mqtt device_tracker config (#101399)
Raise vol.Invalid for invalid mqtt device_tracker
2023-10-04 19:36:34 +02:00
Jan Bouwhuis 8b232047c4
Add origin info support for MQTT discovered items (#98782)
* Add integration info support for MQTT discovery.

* Moving logs to discovery

* Revert adding class property

* Rename to origin

* Follow up comments
2023-08-24 09:50:39 +02:00
Franck Nijhof 86708b5590
Update ruff to v0.0.280 (#97102) 2023-07-23 22:00:26 +02:00
Jan Bouwhuis 447fbf58c9
Change naming of MQTT entities to correspond with HA guidelines (#95159)
* Set has_entity_name if device_name is set

* revert unneeded formatting change

* Add image platform

* Follow up comment

* Don't set `has_entity_name` without device name

* Only set has_entity_name if a valid name is set

* Follow device_class name and add tests

* Follow up comments add extra tests

* Move to helper - Log a warning

* fix test

* Allow to assign None as name explictly

* Refactor

* Log info messages when device name is not set

* Revert scene schema change - no device link

* Always set has_entity_name with device mapping

* Always set `_attr_has_entity_name`

* Cleanup
2023-07-21 12:52:10 +02:00
Erik Montnemery 7539cf25be
Don't require passing identifiers to DeviceRegistry.async_get_device (#96479)
* Require keyword arguments to DeviceRegistry.async_get_device

* Update tests

* Update tests

* Don't enforce keyword arguments
2023-07-13 13:39:25 -04:00
Jan Bouwhuis beff19f93c
Improve mqtt tag schema logging and avoid tests that use xfail (#95711)
Improve schema logging and tests
2023-07-11 10:12:31 +02:00
Jan Bouwhuis 82b9a31ea7
Improve logging of mqtt discovery message errors (#94491)
* Improve logging on mqtt discovery message errors

* Create shared helper

* Apply suggestion

* Catch base class vol.Invalid
2023-06-12 21:28:28 +02:00
Jan Bouwhuis 25549eed85
Debounce and group mqtt unsubscribes (#92201)
* Debounce MQTT unsubscribes and merge to one call

* Make _async_unsubscribe a callback

* Make sure unsubscribes are processed

* Move debug log out of lock

* Reduce calls and raise outside lock

* Cancel any unsubscribe when queing

* Copy pending unsubscribes

* Only convert topics to list once

* No copy needed

* Typo in comment
2023-05-09 16:36:19 +02:00
Jan Bouwhuis 689c6fbef7
Merge pending MQTT subscribes to a single call to the paho client (#92172)
* Merge mqtt subscribes in one call

* Cleanup

* cleanup, log outside of lock

* Remove function wrapper

* Add test that we bundle subscriptions
2023-05-08 15:37:25 +02:00
Jan Bouwhuis bb15923968
Rename MQTT entry mock and cleanup (#91223)
Rename to mqtt_mock_entry and cleanup
2023-04-12 09:43:03 +02:00
Jan Bouwhuis c81a38effb
Mqtt prepare test base part1 (#89796)
* Refactor test_reloadable

* Refactor test_disabling_and_enabling_entry

* optimize test_unload_config_entry

* Cleanup help_test_unload_config_entry

* cleanup test_unload_entry

* Update test tls_version

* More tests to entry only

* Add validate and hassconfig patch

* Revert fixture changes patch_hass_config

* Follow up comments
2023-03-16 15:57:01 +01:00