Commit Graph

643 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 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 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
Erik Montnemery 63f3767a29
Include UUID in hassio discovery data (#91970) 2023-04-25 09:48:47 +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 9197316b57
Add tests mqtt light with single supported color_mode (#91811) 2023-04-22 13:55:43 +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 f37b1fc9f8
Improve tests subscribe connection for mqtt status (#91463)
Improve test_subscribe_connection_status
2023-04-15 15:29:31 -04: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 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 aa68d1d617
Cleanup mqtt CONFIG_SCHEMA_ENTRY (#90791) 2023-04-11 17:41:38 +02: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 7364e6ecb3
Remove incorrect parametrize decorator (#90219) 2023-03-24 09:38:43 +01:00
Jan Bouwhuis 1224b1aff6
Use helper on tests MQTT fan platform (#90196)
Use helper on tests fan
2023-03-24 08:42:23 +01:00
Jan Bouwhuis f2b4c95a04
Prepare MQTT platform tests part7 (#90130)
* Tests select

* Tests sensor

* Deduplicate test code
2023-03-24 08:42:00 +01:00
Jan Bouwhuis 0570405a3c
Prepare MQTT platform tests part6 (#90129)
* Tests lock

* Tests mixins

* Tests number

* Tests scene
2023-03-24 08:41:36 +01:00
Jan Bouwhuis a404d5f6d7
Prepare MQTT platform tests part5 (#90108)
* Tests light_json

* Tests light_template

* Tests light
2023-03-24 08:41:04 +01:00
Jan Bouwhuis 185d6d74d7
Prepare MQTT platform tests part9 (#90133)
* Tests switch

* Tests text

* Tests update
2023-03-23 19:17:27 +01:00
Jan Bouwhuis db63c8584e
Prepare MQTT platform tests part8 (#90132)
* Tests state_vacuum

* Tests siren
2023-03-23 19:16:54 +01:00
Jan Bouwhuis 2c1b59be0e
Prepare MQTT platform tests part4 (#90107)
* Tests humidifier

* Tests legacy_vacuum
2023-03-23 19:14:44 +01:00
Jan Bouwhuis 44add1dc11
Prepare MQTT platform tests part3 (#90106)
* Tests cover

* Tests fan
2023-03-23 19:14:08 +01:00
Jan Bouwhuis 8fd88d6703
Prepare MQTT platform tests part2 (#90105)
* Tests button

* Tests camera

* Tests climate
2023-03-23 19:13:36 +01:00
Jan Bouwhuis 214286acb9
Prepare MQTT platorm tests part1 (#90051)
* Add help_custom_config

* Tests alarm_control_panel

* Tests binary_sensor

* Only use help_custom_config with iterable options
2023-03-22 10:23:08 +01:00
Jan Bouwhuis d865440012
Prepare MQTT common tests part3 (#90022) 2023-03-21 09:19:20 +01:00
Jan Bouwhuis fe49861e26
Prepare MQTT common tests part4 (#90023)
* Upd test_setting_attribute_via_mqtt_json_message

* Update test_setting_attribute_with_template

* Update test_update_with_json_attrs_not_dict

* Update test_update_with_json_attrs_bad_json
2023-03-21 09:07:46 +01:00
Jan Bouwhuis 91dbda1ce7
Add mqtt common tests for availability (part2) (#89805)
* update test_availability_when_connection_lost

* Adjust test_availability_without_topic

* Update test_default_availability_payload + helper

* Update test_default_availability_list_payload

* Use helper for async_setup_component

* Update test_default_availability_list_*

* Update test_custom_availability_payload
2023-03-21 08:20:37 +01:00
epenet ff8b91aeea
Add freezer to known test fixtures in pylint (#89825)
Add freezer to known fixtures in pylint
2023-03-16 22:39:41 -04:00
Jan Bouwhuis 6e25abfdcc
Fix typo in docstr (#89804) 2023-03-16 16:54:26 +01: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
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
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
Franck Nijhof ed79265843
Enable Ruff PT006 (#88165)
* Enable Ruff PT006

* Adjust existing cases

* Fix tests

* Remove unneeded parentheses
2023-02-15 14:09:50 +01:00
Franck Nijhof 9030ca05b1
Enable Ruff SIM118 (#87772) 2023-02-15 12:39:12 +01:00
epenet 50cbabb2d8
Add type hints to integration tests (part 15) (#88006) 2023-02-15 10:00:49 +01:00