Commit Graph

1259 Commits (4d44d60e734069d0e9c1c282bc308adbd4ed9a4b)

Author SHA1 Message Date
Jan Bouwhuis a05c20a498
Filter replaying unrelated retained MQTT messages when subscribing to share topics (#88826)
* Do not replay already processed retained subscr.

* Add tests

* Always replay wildcards

* Update tests for debouncer

* Rework for retained topics

* Fix test

* Correct comment

* Add cleanup and test

* Fix key error

* Correct helper

* Rename mock

* Add comment on function _retained_init

* Always replay initial retained payload

* Apply suggestion moving msg.retain to outer check

* Improve test on edge case

* Improve comment formatting

* Follow up comment - improve comments on test

* Update homeassistant/components/mqtt/client.py

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

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-05-12 15:23:05 +02:00
Jan Bouwhuis 9e9073d5da
Move raise on MQTT publish outside lock (#92860)
* Move raise outside lock

* Move log too
2023-05-09 20:55:29 +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 9468aed689
Fix MQTT certificate files setup (#92266) 2023-04-30 00:01:44 +02:00
Jan Bouwhuis cff7829a8d
Fix mqtt subscribe debouncer initial delay too long when birth message is disabled (#92188)
Fix mqtt subscribe deboucer initial delay
2023-04-28 18:56:22 +02:00
Jan Bouwhuis aab7dffdb9
Only expose MQTT advanced settings in advanced mode (#91996) 2023-04-25 22:23:17 +02:00
Jan Bouwhuis 88f0e4000b
Cleanup unreachable code where device_entry will never be None on an update event (#91855) 2023-04-24 16:09:36 +02:00
rubenbe 2f1a5942ab
Add MQTT fan direction support (#91700)
* Add MQTT fan direction support

* Add MQTT fan direction abbreviations

* Add MQTT fan direction tests

* Shorten MQTT fan test payloads
2023-04-24 11:48:00 +02:00
Jan Bouwhuis 8910afa474
Substate will never be None when subscribing mqtt topics (#91856) 2023-04-22 17:54:39 +02:00
Jan Bouwhuis ad355b3396
Remove unreachable code in mqtt integration discovery (#91796) 2023-04-22 12:31:32 +02:00
Jan Bouwhuis 0bcda9fe9c
Make sure MQTT client is available when starting depending platforms (#91164)
* Make sure MQTT is available starting mqtt_json

* Wait for mqtt client

* Sync client connect

* Simplify

* Addiitional tests async_wait_for_mqtt_client

* Improve comment waiting for mqtt

* Improve docstr

* Do not wait unless the MQTT client is in setup

* Handle entry errors during setup

* More comments - do not clear event

* Add snips and mqtt_room

* Add manual_mqtt

* Update homeassistant/components/mqtt/__init__.py

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

* Use a fixture, improve tests

* Simplify

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-20 08:07:35 +02:00
Jan Bouwhuis 4132f08146
Remove check on remove deprecated call back for mqtt subscribe (#91464)
Remove check on deprecated callback wrapper
2023-04-18 16:02:24 +02:00
Jan Bouwhuis 599cc4a5c6
Cleanup MQTT platform set up and discovery start (#91007)
Cleanup platform set up and discovery start
2023-04-18 14:33:58 +02:00
Jan Bouwhuis fc8c5f1bbd
Do not allow mqtt lights to set brightness to zero (#91296)
* Do not allow mqtt lights to set brightness to zero

* Loglevel to debug

* Typo
2023-04-14 09:01:29 +02:00
Jan Bouwhuis e36fd5f222
Allow None device_class and UOM for mqtt entities (#91240)
* Allow None device_class and UOM for mqtt entities

* Rever not needed changes

* Revert another unwanted change
2023-04-12 19:14:16 +02:00
Jan Bouwhuis aa68d1d617
Cleanup mqtt CONFIG_SCHEMA_ENTRY (#90791) 2023-04-11 17:41:38 +02:00
J. Nick Koston 66b105fb21
Reduce creation of MQTT related discovery tasks (#90801)
* Reduce creation of MQTT related discovery tasks

Most of the branching can avoid creating a task as it
did not need to await for the majority of cases. We
fallback to creating a task for the cases were we do
need to await.

* comment

* revert
2023-04-08 23:14:22 -04:00
Jan Bouwhuis 4a0d3e881a
Rework MQTT config merging and adding defaults (#90529)
* Cleanup config merging and adding defaults

* Optimize and update tests

* Do not mix entry and yaml config

* Make sure hass.data is initilized

* remove check on get_mqtt_data

* Tweaks to MQTT client

* Remove None assigment mqtt client and fix mock
2023-04-04 18:12:18 +02:00
Jan Bouwhuis 9965d9d81d
Fix mqtt device_tracker is not reloading yaml (#90639) 2023-04-01 15:17:53 -04:00
Jan Bouwhuis 14ffda9758
Remove dependency on async_setup from mqtt integration (#87987)
* Remove async_setup from mqtt integration

* Final update common tests

* Related tests init

* Related tests diagnostics

* Related tests config_flow

* Cleanup and correct test

* Keep websockets_api commands in async_setup
2023-03-28 09:37:07 +02:00
Jan Bouwhuis e937693d97
Fix blocking MQTT entry unload (#89922)
* Remove unneeded async_block_till_done

* use await asyncio.sleep(0) instead
2023-03-18 14:57:40 -10:00
Franck Nijhof b1a3bfb298
Drop flake8 in favor of Ruff (#89863) 2023-03-17 13:30:06 +01:00
Jan Bouwhuis ec1b8b616f
Debounce and group MQTT subscriptions (#88862)
* Debounce and group mqtt subscriptions

* Cleanup

* Do not cooldown on resubscribe

* Remove lock from task

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

* ruff

* Longer initial cool down. Manages unsubscribes

* Own lock for access to self._pending_subscriptions

* adjust

* Subscribe to highest QoS when sharing subscription

* do not block _pending_subscriptions_lock with io

* Test the highest qos is subscribed at

* Cleanup max qos

* Follow up comments part 1

* Make docstr more generic

* Make max qos update thread safe

* Add lock on clearing _max_qos when resubscribing

* Wait for linger task

* User copy

* Check for key before cleaning up

* Fix lingering task

* Do not use a lock

* do not await _async_queue_subscriptions

* Replace copy with assignment

* Update max qos before returning

* Do not iterate if max_qos == 0

* Do not ieterate subs if max qos == 0

* Set initial cooldown correctly

* Ensure discovery cooldown ends after subscribing

* plan last subscribe with debouncer timeout

* cooldown if self._pending_subscriptions is set

* Revert format changes

* Remove stale assingnment self._last_subscribe

* Remove not used property

* Also check while for pending subscriptions

* revert first added sleep()

* Optimize

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-03-14 11:13:55 +01:00
anotherthomas 179cc4d7f7
Improve warnings in mqtt light messages (#89552)
* improved warnings in mqtt light messages.

* fixed tests.
2023-03-13 14:46:16 +01:00
Jan Bouwhuis 1a4b14c217
Fix MQTT rgb light brightness scaling (#89264)
* Normalize received RGB colors to 100% brightness

* Assert on rgb_color attribute

* Use max for RGB to get brightness

* Avoid division and add clamp

* remove clamp

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

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-03-09 08:02:59 +01:00
Jan Bouwhuis 366baef7f6
Allow enum as MQTT sensor device_class (#89391) 2023-03-08 22:35:06 +01:00
Jan Bouwhuis 5ee383456f
Catch exceptions and add logging when writing states on MQTT entities (#89091)
* Catch exceptions when writing states

* Do not use wrapper for logging and adjust tests

* Catch logging directly on async_write_ha_state()

* Update homeassistant/components/mqtt/models.py

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

* Fix test

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-03-06 15:34:47 +01:00
Jan Bouwhuis a9becd8e0e
Raise ValueError on date parsing of MQTT sensor with invalid date format (#89036)
* Suppress ValueError on date parsing of MQTT sensor

* Simplify, but not update state on invalid payload

* Still raise an an invalid date

* Make datetime state unknown on invalid format

* remove unrelated added new line
2023-03-05 17:06:48 +01:00
epenet 4a3c0cd0a8
Adjust docstrings for ruff D404 (#89077) 2023-03-03 11:26:13 +01:00
Jan Bouwhuis ae04c5d773
Clean up unused and deprecated TLS version setting on MQTT client (#88674)
* Cleanup CONF_TLS_VERSION remains

* Fix diagnostics tests
2023-03-01 18:42:34 +01:00
Jan Bouwhuis 3f79155df6
Remove deprecated callback support for MQTT subscribe (#88543)
* Remove deprecated callback support and fix tests

* Add note with removal instruction
2023-02-21 22:21:00 +01:00
Jan Bouwhuis 57738fbb8c
Replace deprecated SSLContext constant PROTOCOL_TLS in mqtt (#88214)
Replace deprecated SSLContext constants
2023-02-16 13:01:28 -05:00
J. Nick Koston d2277fa6db
Fix restore of MQTT subscriptions from reload (#88220) 2023-02-16 11:14:26 -06:00
epenet ba23816a0c
Inverse json import logic (#88099)
* Fix helpers and util

* Adjust components

* Move back errors

* Add report

* mypy

* mypy

* Assert deprecation messages

* Move test_json_loads_object

* Adjust tests

* Fix rebase

* Adjust pylint plugin

* Fix plugin

* Adjust references

* Adjust backup tests
2023-02-16 11:37:57 +01:00
Jan Bouwhuis 03e9dff327
Allow resetting MQTT climate attributes and ignore empty values (#87936)
Allow reseting MQTT climate attributes
2023-02-15 16:31:49 +01:00
Jan Bouwhuis 09b509da94
Add note on always subscribing to the MQTT broker when topics are shared (#88159)
Add note on always subscribing
2023-02-15 10:46:57 +01:00
Jan Bouwhuis aaf8196997
Fix race on check MQTT subscriptions (#88117)
* Check MQTT subscriptions under paho client lock

* Check simple subscriptions first

* Apply suggestion
2023-02-14 15:39:33 -05:00
Jan Bouwhuis 666aace8a2
Complete partly implemented type hints for `dict` on MQTT platforms (#87839) 2023-02-12 21:47:38 +01:00
Jan Bouwhuis 71b67e20e4
Improve MQTT `Callable` type hints (#87838) 2023-02-12 21:24:59 +01:00
J. Nick Koston 1a35c2d805
Avoid creating a task when waiting for the MQTT mid (#87887) 2023-02-12 14:24:55 -06:00
J. Nick Koston f2fb6a9a60
Optimize mqtt matchers (#87853) 2023-02-12 14:24:35 -06:00
J. Nick Koston 753c7abaf4
Make mqtt websocket subscribe use callback functions (#87885)
Nothing was being awaited so this was needlessly generating tasks when the callbacks fired
2023-02-12 21:05:37 +01:00
J. Nick Koston 1d4d688af3
Make mqtt discovery use callback functions (#87883) 2023-02-12 20:41:03 +01:00
Jan Bouwhuis 1a38b9f665
Improve coverage MQTT device_trigger (#87408)
* Improve coverage MQTT device_trigger

* Use assert
2023-02-09 17:42:32 +01:00
Erik Montnemery 1d64ba9d34
Sort manifests 6 (#87027) 2023-02-08 20:38:43 +01:00
epenet a202588fd2
Add return type to json_loads (#85672)
* Add JSON type definitions

* Sample use

* Keep mutable for a follo-up PR (avoid dead code)

* Use list/dict

* Remove JsonObjectType

* Remove reference to Union

* Cleanup

* Improve rest

* Rename json_dict => json_data

* Add docstring

* Add type hint to json_loads

* Add cast

* Move type alias to json helpers

* Cleanup

* Create and use json_loads_object

* Make error more explicit and add tests

* Use JsonObjectType in conversation

* Remove quotes
2023-02-07 17:21:55 +01:00
Jan Bouwhuis 4aa61b0d64
Cleanup remains of legacy validation MQTT light (#87467) 2023-02-07 14:52:40 +01:00
Jan Bouwhuis be564e0162
Cleanup `value_template` config parameter from MQTT basic light (#87466)
* Remove not supported case from code for MQTT light

* Remove from schema
2023-02-07 13:05:24 +01:00
Jan Bouwhuis c78cae4483
Fix handling `None` or empty value for numeric MQTT sensor (#87004)
* Allow `None` for numeric sensor, ignore empty val

* Add test case with omitting a value

* Use _numeric_state_expected property

* Only respect None if numeric state is expected
2023-02-07 11:23:23 +01:00