Commit Graph

277 Commits (94677090684661c1984464cb9b8009278e5e6839)

Author SHA1 Message Date
Jan Bouwhuis d3d00357aa
Allow to omit the payload attribute to MQTT publish action to allow an empty payload to be sent by default (#137595)
Allow to omit the payload attribute to MQTT publish actionto allow an empty payload to be sent by default
2025-02-06 22:11:39 +02:00
epenet d0a188b86d
Standardize homeassistant imports in component tests (m-z) (#136807) 2025-01-29 08:57:57 +01:00
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
Jan Bouwhuis 8098122dfe
Ensure an entity platform is added in mqtt tests (#134331) 2024-12-31 23:01:55 +01:00
Jan Bouwhuis 7b2a5d0684
Remove mqtt publish templates after 6 months of deprecation (#134056) 2024-12-26 23:25:44 +01:00
Jan Bouwhuis 3474642afe
Set up MQTT websocket_api and dump, publish actions from `async_setup` (#131170)
* Set up MQTT websocket_api and dump, publish actions from `async_setup`

* Follow up comments
2024-11-21 17:29:59 +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 ac6d893758
Correct type hints on MQTT tests (#128299) 2024-10-16 13:49:18 +02:00
Jan Bouwhuis 21affac571
Rename mqtt mixins module to `entity.py` (#126279) 2024-09-19 20:50:33 +02:00
Jan Bouwhuis 1cb9690001
Cleanup unused `hass_storage` mocks in mqtt tests (#124846) 2024-08-29 10:52:57 +02:00
Jan Bouwhuis e13f8996f2
Fix Import ReceivePayloadType (#124431)
* Fix Import ReceivePayloadType

* Do not assert export `ReceivePayloadType` on mqtt integration level as helper should be used.
2024-08-22 20:13:30 +02:00
Jan Bouwhuis 183c191d63
Allow raw mqtt payload to be in mqtt publish action (#123900)
* Publish raw rendered mqtt payload as raw for mqtt publish action

* Move check out of try block

* Only try to eval `bytes` is payload starts with supported string

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

* Improve docst

* Add `evaluate_bytes` option to publish action

* Rename to `evaluate_payload`

* Update homeassistant/components/mqtt/strings.json

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

* Extend test to assert literal_eval is called or not

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-08-16 13:34:14 +02:00
Jan Bouwhuis 21987a67e7
Cleanup unneeded assignment of hass property on MQTT Template objects (#123706)
* Cleanup unneeded assignment of hass property on MQTT Template objects

* Commented out code and unneeded checks

* Consistent assign hass to Template in mqtt tests

* Remove unused hass attribute

* Missed line
2024-08-12 19:20:21 +02:00
Jan Bouwhuis 5b4dd07189
Deprecate `topic_template` and `payload_template` for mqtt publish action (#122098)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2024-07-19 10:10:38 +02:00
Jan Bouwhuis 843fae825f
Revert "Remove stale `template_topic` code for mqtt publish service" (#121758)
Revert "Remove stale `template_topic` code for mqtt publish service (#121604)"

This reverts commit 5b25c24539.
2024-07-17 17:56:34 +02:00
Jan Bouwhuis acb4a92628
Revert "Add mqtt automation publish test with template rendering" (#121757) 2024-07-11 09:36:14 +02:00
Jan Bouwhuis 71e5ffb2bd
Add mqtt automation publish test with template rendering (#121695) 2024-07-10 21:17:27 +02:00
Jan Bouwhuis 5b25c24539
Remove stale `template_topic` code for mqtt publish service (#121604) 2024-07-09 18:22:08 +02:00
Jan Bouwhuis f3c76cd698
Split mqtt client tests (#120636) 2024-06-27 19:37:43 +02:00
Jan Bouwhuis 32e64f7911
Cleanup mqtt platform tests part 4 (init) (#120574) 2024-06-26 16:57:41 -05:00
Jan Bouwhuis aa05f73210
Add fixture to synchronize with debouncer in MQTT tests (#120373)
* Add fixture to synchronze with debouncer in MQTT tests

* Migrate more tests to use the debouncer

* Migrate more tests

* Migrate util tests

* Improve mqtt on_callback test using new fixture

* Improve test_subscribe_error

* Migrate other tests

* Import EnsureJobAfterCooldown from `util.py` but patch `client.py`
2024-06-25 14:26:20 +02:00
Jan Bouwhuis 1d16cbec96
Move mqtt debouncer to mqtt utils (#120392) 2024-06-25 10:33:58 +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 f1fd52bc30
Fix issue in mqtt fixture calling disconnect handler (#120246) 2024-06-23 10:37:08 -05:00
Jan Bouwhuis 60ba80a28d
Only (re)subscribe MQTT topics using the debouncer (#119995)
* Only (re)subscribe using the debouncer

* Update test

* Fix test

* Reset mock
2024-06-19 23:57:18 +02:00
Jan Bouwhuis 6eb9d1e01d
Gracefully disconnect MQTT entry if entry is reloaded (#119753) 2024-06-18 09:29:22 +02:00
epenet 2c7022950c
Fix import-outside-toplevel pylint warnings in tests (#119389) 2024-06-11 14:57:50 +02:00
Marc Mueller 7195a21126
Fix Generator annotations in tests (2) (#119019) 2024-06-07 08:34:38 +02:00
J. Nick Koston 67b3be8432
Remove useless threading locks in mqtt (#118737) 2024-06-04 14:21:03 -05:00
epenet 089874f818
Move mock_hass_config fixture to decorator (#118807) 2024-06-04 16:05:56 +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
epenet 0f8588a857
Rename calls fixture in mqtt tests (#118354)
Rename calls fixture in mqtt
2024-05-29 09:25:34 +02:00
J. Nick Koston 69353d2719
Speed up mqtt debug info on message callback (#118303) 2024-05-28 11:10:07 -10: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 6b8223e339
Try to read multiple packets in MQTT (#118222) 2024-05-27 11:07:24 +02:00
J. Nick Koston 9be829ba1f
Make mqtt internal subscription a normal function (#118092)
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
2024-05-25 11:34:24 -10:00
Jan Bouwhuis 521ed0a220
Fix mqtt callback exception logging (#118138)
* Fix mqtt callback exception logging

* Improve code

* Add test
2024-05-25 22:46:33 +02:00
Jan Bouwhuis c9a79f6293
Fix lingering mqtt test (#118072) 2024-05-24 14:34:18 -10:00
Jan Bouwhuis fa1ef8b0cf
Split mqtt subscribe and unsubscribe calls to smaller chunks (#118035) 2024-05-24 13:33:28 -10:00
Jan Bouwhuis f12aee28a8
Improve error logging on invalid MQTT entity state (#118006)
* Improve error logging on invalid MQTT entity state

* Explain not hanlding TpeError and ValueError

* Move length check closer to source

* use _LOGGER.exception
2024-05-24 13:11:52 +02:00
Marc Mueller dc47792ff2
Update codespell to 2.3.0 (#118001) 2024-05-24 08:22:29 +02:00
Jan Bouwhuis 050fc73056
Refactor shared mqtt schema's to new module (#117944)
* Refactor mqtt schema's to new module

* Remove unrelated change
2024-05-23 01:12:25 +02:00
J. Nick Koston f429bfa903
Fix mqtt timer churn (#117885)
Borrows the same design from homeassistant.helpers.storage to avoid
rescheduling the timer every time async_schedule is called if a timer
is already running.

Instead of the timer fires too early it gets rescheduled for the time
we wanted it. This avoids 1000s of timer add/cancel during startup
2024-05-21 21:05:33 -04:00
J. Nick Koston ac3321cef1
Fix setting MQTT socket buffer size with WebsocketWrapper (#117672) 2024-05-19 14:09:21 -10:00
Jan Bouwhuis 92254772ca
Increase MQTT broker socket buffer size (#117267)
* Increase MQTT broker socket buffer size

* Revert unrelated change

* Try to increase buffer size

* Set INITIAL_SUBSCRIBE_COOLDOWN back to 0.5 sec

* Sinplify and add test

* comments

* comments

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-12 13:13:41 +02:00
J. Nick Koston 481de8cdc9
Ensure config entry operations are always holding the lock (#117214)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-05-12 08:20:08 +09:00
Jan Bouwhuis 589104f63d
Export MQTT subscription helpers at integration level (#116150) 2024-05-08 23:46:50 +02:00
J. Nick Koston 649dd55da9
Simplify MQTT subscribe debouncer execution (#117006) 2024-05-07 14:41:31 -05:00
Jan Bouwhuis a3248ccff9
Log an exception mqtt client call back throws (#117028)
* Log an exception mqtt client call back throws

* Supress exceptions and add test
2024-05-07 21:19:46 +02:00