Commit Graph

1316 Commits (99e97782b6b742067ef8834e413c4d51124ba2ec)

Author SHA1 Message Date
Jan Bouwhuis fa4d9b2c08
Rework mqtt climate platform to simplify implementation water_heater platform (#93751)
* Rework to simplify water_heater platform

* Remove unused type hints

* Split shared and specific subscriptions

* Convert to abstract class
2023-05-31 11:12:58 +02:00
Jan Bouwhuis 661aedde90
Remove MQTT platform schema warnings (#93785) 2023-05-31 09:02:48 +02:00
Jan Bouwhuis 3a7f9ab57d
Remove mqtt sensor support for `last_reset_topic` (#93792)
* Remove mqtt sensor support for `last_reset_topic`

* Add cases for empty last reset messages
2023-05-30 21:07:07 -04:00
Brandon Rothweiler c513934f25
Fix broken URL in MQTT discovery log message (#93778) 2023-05-30 11:39:55 +02:00
J. Nick Koston 3db59908ca
Switch mqtt to use async_track_device_registry_updated_event (#93603) 2023-05-29 09:43:01 -05:00
Jan Bouwhuis c44a7fe358
Do not trigger reload when unloading or reloading MQTT entry (#93588)
* Do not trigger reload when unloading MQTT entry

* More cleanup

* cleanup async_reload_manual_mqtt_items

* Add test

* Improve test

* Remove unuse mocks from test

* Add discovery item in test
2023-05-29 15:44:09 +02:00
Jan Bouwhuis a81fe517c1
Make mqtt device_tracker state_topic optional when json_attribute_topic is used (#93322)
* Make device_tracker state_topic optional

* No state_topic needed
2023-05-22 15:49:18 +02:00
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
Jan Bouwhuis 73e3b30906
Add `suggested_display_precision` config option for MQTT sensor (#87129)
* Add precision for MQTT sensor

* Correct tests

* Use _attr_suggested_display_precision

* Rename option and add abbreviation

* Make abbr more compact
2023-02-07 08:55:35 +01:00
Marc Mueller 4fbb14ecc7
Update mypy to 1.0.0 (#87586) 2023-02-07 02:31:14 +01:00
Franck Nijhof 939eef3b28
Remove translations from Core (#87543)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-02-06 15:06:43 +01:00
Jan Bouwhuis 212e172be2
Cleanup not used schema validator for MQTT vacuum (#87462)
* Cleanup not used schema validator for MTT vacuum

* Only leave warning
2023-02-06 13:34:36 +01:00
Franck Nijhof 28b6306ad6
Remove use of Number DEVICE_CLASSES_SCHEMA from MQTT (#87345) 2023-02-04 00:08:15 +01:00
Franck Nijhof fcb612cd6f
Collection of code styling tweaks (#87344) 2023-02-03 23:51:27 +01:00
Franck Nijhof ca1a12898c
Enable Ruff D212 (#87347) 2023-02-03 23:08:48 +01:00
epenet 810367b757
Fix `can not` typo (#87254) 2023-02-03 11:37:16 +01:00
Franck Nijhof 5e81d28116
Update black to 23.1.0 (#87188) 2023-02-02 18:35:24 +01:00
GitHub Action 0f80932709 [ci skip] Translation update 2023-02-02 00:25:01 +00:00
Jan Bouwhuis 33ede351f0
Cleanup code for parsing yaml MQTT config (#86944)
* Cleanup code for parsing yaml configs

* Add abstractmethod decorator to async_update

* Replace get() with default-list ensured by schema
2023-01-31 08:24:33 +01:00
Jan Bouwhuis e57dad79fc
Fix MQTT discovery failing after bad config update (#86935)
* Fix MQTT discovery failing after bad config update

* Update last discovery payload after update success

* Improve test, correct update assignment

* send_discovery_done to finally-catch vol.Error

* Just use try..finally

* Remove extra line

* use elif to avoid log confusion
2023-01-30 19:15:11 +01:00
Jan Bouwhuis 6a94a58325
Correct stale doc string for MQTT tag platform (#86862) 2023-01-29 00:23:22 +02:00
Franck Nijhof e738924780
Enable Ruff SIM105 (#86759)
* Enable Ruff SIM105

* Adjust existing cases
2023-01-26 21:06:22 -05:00
Franck Nijhof b7de185924
Fix CI, missing import in MQTT (#86517) 2023-01-24 11:40:40 +01:00
Jan Bouwhuis 42ca46d7b2
Remove redundant label for MQTT CA verification selector (#86236)
Remove redundant label for MQTT CA verification
2023-01-24 09:38:00 +01:00
GitHub Action 613aa6f43a [ci skip] Translation update 2023-01-24 00:24:57 +00:00
Jan Bouwhuis 8672be3829
Always add `code` to template vars MQTT lock command template (#86460)
Always add `code` to template vars lock cmd tpl
2023-01-23 16:08:25 +01:00
Marc Mueller 6f94e47270
Update Union typing (6) [Py310] (#86454) 2023-01-23 15:01:07 +01:00
Jan Bouwhuis f719ecf086
Add command template and code_format support for MQTT lock (#85830)
* Add command template for MQTT lock

* Fix tests
2023-01-23 14:48:07 +01:00
Marc Mueller 077ca97ef8
Fix `local_partial_types` errors (#86410)
Fix local_partial_types errors
2023-01-23 10:29:11 +01:00
Marc Mueller 8abce25948
Update Union typing (4) [Py310] (#86427) 2023-01-23 09:04:40 +01:00
Marc Mueller d7dda6bee5
Update python version used for pylint [Py310] (#86414)
* Update python version used for pylint linting [Py310]

* Import Callable from collections.abc [Py310]

* Use builtin anext [Py310]
2023-01-23 07:56:15 +01:00
GitHub Action 4d215e573c [ci skip] Translation update 2023-01-23 00:23:13 +00:00
Jan Bouwhuis 66c3115b26
Improve MQTT transport select label (#86216) 2023-01-22 22:12:06 +01:00
GitHub Action 771e07c68b [ci skip] Translation update 2023-01-22 00:25:52 +00:00
GitHub Action e1483ff746 [ci skip] Translation update 2023-01-21 00:24:12 +00:00
Franck Nijhof 79b52a2b41
Stricter pylint message control (#86154) 2023-01-20 13:47:55 +01:00
Jan Bouwhuis 92742ae423
Add jammed state support for MQTT lock (#86010)
* Add jammed state support for MQTT lock

* Correct payload jammed key

* Add tests - rename solved to ok

* Rename jammed state and template topics to motor

* Use state topic for handling motor state

* Follow up comments

* Change default behaviour `state_unjammed`

* Skip `state_unjammed`
2023-01-20 12:19:26 +01:00
GitHub Action 59ad232ce5 [ci skip] Translation update 2023-01-20 00:25:31 +00:00
GitHub Action d1ecc418bb [ci skip] Translation update 2023-01-19 00:25:04 +00:00
GitHub Action 87b2a73460 [ci skip] Translation update 2023-01-18 00:24:40 +00:00
Jan Bouwhuis 25392655e7
Allow translating select selector options (#85531)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2023-01-17 16:22:19 +01:00
Patrick ZAJDA 0b02abf708
Add locking and unlocking to MQTT lock (#85779)
* Implement locking, unlocking and jammed on MQTT lock

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Add tests

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Refactor condition

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Parametrize tests

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Manage only locking and unlocking

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

* Remove jammed from abbreviations

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

* set valid states in self._valid_states

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>

Signed-off-by: Patrick ZAJDA <patrick@zajda.fr>
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
2023-01-16 08:42:43 +01:00
GitHub Action 77f9548e51 [ci skip] Translation update 2023-01-15 00:25:52 +00:00
Shay Levy 6938f791f9
Downgrade MQTT logging (#85867) 2023-01-14 13:28:41 +01:00
GitHub Action dffc913f9e [ci skip] Translation update 2023-01-14 00:22:57 +00:00
Jan Bouwhuis 64e235285d
Deprecate power_command_topic for MQTT climate (#85229)
* Deprecate mode_command_topic for MQTT climate

* Correct deprecation and remove support release inf

* Do not use future tense for comment

* Extend deprecation period to 6 months
2023-01-12 09:49:14 +01:00
Franck Nijhof 800b8abe39
Code styling tweaks to the MQTT integration (#85463) 2023-01-08 22:07:10 +01:00
Jan Bouwhuis ee21bc5d7f
Allow MQTT device_class or state_class to be set as `None` (#85106)
* Allow MQTT device_class to be set as `None`

* Add test

* Also allow sensor state_class to be `None`
2023-01-04 15:21:07 +01:00
Jan Bouwhuis 9f24897814
Do not reset current selection on reconfig or MQTT select (#85099)
* Do not reset current selection on reconfig

* Add a test
2023-01-04 10:29:53 +01:00
Jan Bouwhuis b29c96639b
Correct initial config of MQTT climate (#85097)
* Do not reset MQTT climate state on re-config

* More corrections

* Correct startup behavior in optimistic mode
2023-01-04 10:29:02 +01:00
GitHub Action 5169721916 [ci skip] Translation update 2023-01-04 00:22:58 +00:00