Commit Graph

63 Commits (6f7cb158d84c9de476911531e186d53d9217384b)

Author SHA1 Message Date
Jan Bouwhuis 81514b0d1c
Move MQTT debug_info to dataclass (#78788)
* Add MQTT debug_info to dataclass

* Remove total attr, assign factory

* Rename typed dict to MqttDebugInfo and use helper

* Split entity and trigger debug info

* Refactor

* More rework
2022-09-23 20:55:29 +02:00
epenet e58531f118
Add MqttData helper to mqtt (#78825)
* Add MqttData helper to mqtt

* Adjust client for circular dependencies

* Move MqttData to models.py

* Move get_mqtt_data to util.py
2022-09-20 19:40:06 +02:00
Jan Bouwhuis 354411feed
Link manually added MQTT entities the the MQTT config entry (#78547)
Co-authored-by: Erik <erik@montnemery.com>
2022-09-18 12:55:31 -04:00
Jan Bouwhuis 1f410e884a
Make hass.data["mqtt"] an instance of a DataClass (#77972)
* Use dataclass to reference hass.data globals

* Add discovery_registry_hooks to dataclass

* Move discovery registry hooks to dataclass

* Add device triggers to dataclass

* Cleanup DEVICE_TRIGGERS const

* Add last_discovery to data_class

* Simplify typing for class `Subscription`

* Follow up on comment

* Redo suggested typing change to sasisfy mypy

* Restore typing

* Add mypy version to CI check logging

* revert changes to ci.yaml

* Add docstr for protocol

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>

* Mypy update after merging #78399

* Remove mypy ignore

* Correct return type

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2022-09-17 21:43:42 +02:00
Jan Bouwhuis fb67123d77
Clear MQTT discovery topic when a disabled entity is removed (#77757)
* Cleanup discovery on entity removal

* Add test

* Cleanup and test

* Test with clearing payload not unique id

* Address comments

* Tests cover and typing

* Just pass hass

* reuse code

* Follow up comments revert changes to cover tests

* Add test unique_id has priority over disabled

* Update homeassistant/components/mqtt/__init__.py

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

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-09-09 15:24:26 +02:00
Jan Bouwhuis 2e34814d7a
Fix reload of MQTT config entries (#76089)
* Wait for unsubscribes

* Spelling comment

* Remove notify_all() during _register_mid()

* Update homeassistant/components/mqtt/client.py

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

* Correct handling reload manual set up MQTT items

* Save and restore device trigger subscriptions

* Clarify we are storing all remaining subscriptions

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-09-02 18:54:20 +02:00
epenet dff9baf880
Use _attr_should_poll in components [j-n] (#77357) 2022-08-26 21:19:37 +02:00
Jan Bouwhuis 5d9e462118
Add repair for deprecated MQTT yaml config (#77174)
* Add repair for deprecated MQTT yaml config

* Update homeassistant/components/mqtt/strings.json

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

* Update homeassistant/components/mqtt/strings.json

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Add restart instruction

* Update homeassistant/components/mqtt/strings.json

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update English translation

* update issue_registry imports

* Update homeassistant/components/mqtt/manifest.json

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-08-25 13:30:05 +02:00
Maciej Bieniek ad6beac535
Add `hw_version` to MQTT device info (#77210)
* Add hw_version

* Add abbreviation for hw_version

* Update tests

* Update discovery tests
2022-08-25 11:55:33 +02:00
Marc Mueller cf7c716bda
Fix implicit Optional [core] (#76719) 2022-08-13 18:46:08 +02:00
Erik Montnemery f0eea62c1e
Address some MQTT review comments (#75482) 2022-07-22 11:12:00 +02:00
Jan Bouwhuis 5930f056a8
Mqtt support config_entry unload (#70149)
* squashed commits for rebase

* Flake

* Fix reloading issue manual legacy items

* Improve ACS sync for unsubscribe at disconnect

* Processed review comments

* Update homeassistant/components/mqtt/client.py

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

* No need to await entry setup

* Remove complication is_connected

* Update homeassistant/components/mqtt/__init__.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-07-12 11:07:18 +02:00
epenet 64bfa20f6a
Improve type hints in mqtt (#74295) 2022-07-02 20:15:54 +03:00
Erik Montnemery f05b4a0ca0
Fire event_mqtt_reloaded only after reload is completed (#74226) 2022-06-30 10:15:25 -07:00
J. Nick Koston 2742bf86e3
Switch mqtt to use json helper (#73871)
* Switch mqtt to use json helper

* whitespace
2022-06-23 14:29:09 +02:00
Jan Bouwhuis 57daeaa174
Fix MQTT config schema to ensure correct validation (#73619)
* Ensure config schema validation

* Use correct schema for device_tracker

* Remove schema validation from the platform setup

* Remove loop to build schema
2022-06-20 08:51:12 +02:00
Erik Montnemery de2fade8c6
Improve MQTT reload performance (#73313)
* Improve MQTT reload performance

* Update homeassistant/components/mqtt/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/mqtt/mixins.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/mqtt/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-06-10 14:23:08 +02:00
Erik Montnemery b97d346df7
Fix reload of MQTT yaml config (#72901) 2022-06-02 11:32:31 -07:00
Erik Montnemery 635d7085cf
Move MQTT config schemas and client to separate modules (#71995)
* Move MQTT config schemas and client to separate modules

* Update integrations depending on MQTT
2022-05-31 09:32:44 +02:00
Jan Bouwhuis ed1c2ea2b8
Move manual configuration of MQTT fan and light to the integration key (#71676)
* Processing yaml config through entry setup

* Setup all platforms

* Update homeassistant/components/mqtt/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* adjust mock_mqtt - reference config from cache

* Fix test config entry override

* Add tests yaml setup

* additional tests

* Introduce PLATFORM_SCHEMA_MODERN

* recover temporary MQTT_BASE_PLATFORM_SCHEMA

* Allow extra key in light base schema, restore test

* Fix test for exception on platform key

* One deprecation message per platform

* Remove deprecation checks from modern schema

* Update homeassistant/components/mqtt/fan.py

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

* Update homeassistant/components/mqtt/fan.py

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

* Update homeassistant/components/mqtt/light/__init__.py

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

* Update homeassistant/components/mqtt/light/__init__.py

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

* Update homeassistant/components/mqtt/light/schema_json.py

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

* Update homeassistant/components/mqtt/light/schema_template.py

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

* Update homeassistant/components/mqtt/mixins.py

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

* rename validate_modern_schema

* Do not fail platform if a single config is broken

* Update homeassistant/components/mqtt/__init__.py

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

* Fix tests on asserting log

* Update log. Make helper transparant, remove patch

* Perform parallel processing

* Update tests/components/mqtt/test_init.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/mqtt/mixins.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* black

* Fix tests and add #new_format anchor

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-05-19 15:04:53 +02:00
Jan Bouwhuis 3b2aae5045
Refactor MQTT discovery (#67966)
* Proof of concept

* remove notify platform

* remove loose test

* Add rework from #67912 (#1)

* Move notify serviceupdater to Mixins

* Move tag discovery handler to Mixins

* fix tests

* Add typing for async_load_platform_helper

* Add add entry unload support for notify platform

* Simplify discovery updates

* Remove not needed extra logic

* Cleanup inrelevant or duplicate code

* reuse update_device and move to mixins

* Remove notify platform

* revert changes to notify platform

* Rename update class

* unify tag entry setup

* Use shared code for device_trigger `update_device`

* PoC shared dispatcher for device_trigger

* Fix bugs

* Improve typing - remove async_update

* Unload config_entry and tests

* Release dispatcher after setup and deduplicate

* closures to methods, revert `in` to `=`, updates

* Re-add update support for tag platform

* Re-add update support for device-trigger platform

* Cleanup rediscovery code revert related changes

* Undo discovery code shift

* Update homeassistant/components/mqtt/mixins.py

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

* Update homeassistant/components/mqtt/device_trigger.py

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

* Update homeassistant/components/mqtt/mixins.py

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

* revert doc string changes

* move conditions

* typing and check config_entry_id

* Update homeassistant/components/mqtt/mixins.py

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

* cleanup not used attribute

* Remove entry_unload code and tests

* update  comment

* add second comment

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-04-15 12:35:08 +02:00
epenet 4c7e1fe060
Cleanup ENTITY_CATEGORIES_SCHEMA (#66549)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-04-01 09:40:43 -07:00
Paulus Schoutsen 130ca2213f
Enforce EntityCategory enum (#69015)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-03-31 15:04:33 -07:00
Erik Montnemery 7e8d52e5a3
Fix race when handling rapid succession of MQTT discovery messages (#68785)
Co-authored-by: jbouwh <jan@jbsoft.nl>
2022-03-29 20:26:11 -07:00
epenet 5830481a53
Use new CONF_MODEL in mqtt (#68832)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2022-03-29 12:49:00 +02:00
Jan Bouwhuis 5afe8fd2db
Revert "Add MQTT notify platform (#64728)" (#68505)
This reverts commit e574a3ef1d.
2022-03-22 12:51:24 +01:00
Jan Bouwhuis e574a3ef1d
Add MQTT notify platform (#64728)
* Mqtt Notify service draft

* fix updates

* Remove TARGET config parameter

* do not use protected attributes

* complete tests

* device support for auto discovery

* Add targets attribute and support for data param

* Add tests and resolve naming issues

* CONF_COMMAND_TEMPLATE from .const

* Use mqtt as default service name

* make sure service  has a unique name

* pylint error

* fix type error

* Conditional device removal and test

* Improve tests

* update description has_notify_services()

* Use TypedDict for service config

* casting- fix discovery - hass.data

* cleanup

* move MqttNotificationConfig after the schemas

* fix has_notify_services

* do not test log for reg update

* Improve casting types

* Simplify obtaining the device_id

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

* await not needed

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

* Improve casting types and naming

* cleanup_device_registry signature change and black

* remove not needed condition

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-03-08 16:27:18 +01:00
Marc Mueller 45d8d04c40
Use assignment expressions [other] (#66882) 2022-02-19 17:22:51 +01:00
Erik Montnemery fcf774ecfc
Small cleanup of MQTT mixins (#66812) 2022-02-18 16:51:14 +01:00
Erik Montnemery ba6d1976df
Improve MQTT device removal (#66766)
* Improve MQTT device removal

* Update homeassistant/components/mqtt/mixins.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Adjust tests

* Improve test coverage

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-02-18 13:45:25 +01:00
Erik Montnemery 750b48dcaf
Use pylint disable-next in MQTT (#66758) 2022-02-17 11:12:12 -08:00
Erik Montnemery fe38e6ba87
Drop MQTT import flow (#66160)
* Drop MQTT import flow

* Reload manually configured MQTT entities when config entry is setup

* Address review comments

* Actually remove the import flow
2022-02-10 21:09:57 +01:00
Erik Montnemery 911e488d48
Fix ENTITY_CATEGORIES_SCHEMA (#66108)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2022-02-08 14:00:53 -08:00
Erik Montnemery 55d8314093
Fix cleanup of MQTT debug info (#66104) 2022-02-08 12:49:25 -08:00
Erik Montnemery 8245ff7473
Log transmitted MQTT messages (#65550) 2022-02-04 17:35:32 +01:00
Erik Montnemery f3a89de71f
Fix race when handling updated MQTT discovery data (#65415) 2022-02-02 17:12:22 -08:00
Jan Bouwhuis 2c07330794
Fix MQTT expire_after effects after reloading (#65359)
* Cleanup sensor expire triggers after reload

* fix test binary_sensor

* Also trigger cleanup parent classes

* Restore an expiring state after a reload

* correct discovery_update

* restore expiring state with remaining time

* Update homeassistant/components/mqtt/binary_sensor.py

description

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

* Log remaining time

* Move check

* check and tests reload

* remove self.async_write_ha_state()

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-02-02 16:14:52 +01:00
Erik Montnemery 627be81531
Import registries in MQTT mixins (#65411) 2022-02-02 10:32:11 +01:00
Jan Bouwhuis dd0193052c
Add MQTT encoding parameter for all subscribed topics (#62263)
* Add encoding parameter for all subscribable topics

* test setup encoding incoming payload

* remove support for device_tracker and tag+tests
2022-01-03 16:08:07 +01:00
Jan Bouwhuis 3ca18922e6
Mqtt rework on value templates (#62105)
* add MqttValueTemplate class

* support variables at initiation

* pass MqttEntity instead of hass

* Use MqttValueTemplace class for value templates

* make hass en enitity parameters conditional

* remove unused property and remove None assignment

* rename self._attr_value_template
2022-01-03 16:07:40 +01:00
Dave T 8fd60dbd51
Refactor entity_category str types (#62790) 2021-12-27 18:23:08 +01:00
Jan Bouwhuis 3307e54363
Add MQTT availability template and encoding (#60470)
* Add MQTT availability template and encoding

* use generic encoding field

* pylint and cleanup

* remove additional topic check
2021-12-02 10:21:31 +01:00
Damien Duboeuf 67c2747027
Add MQTT object_id option (#58728)
* Add MQTT object_id option

* Add MQTT object_id option

* Add MQTT object_id option

* Add MQTT object_id option - Fix light and vacuum

* Add MQTT object_id option - Fix light and vacuum

* Add MQTT object_id option - Fix lock

* Add MQTT object_id option - Fix device

* Add MQTT object_id option - Fix device

* Update tests/components/mqtt/test_discovery.py

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

* Change deprecated method

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-08 14:02:18 +01:00
epenet a8a8b532d0
Use DeviceInfo in mqtt (#58389)
* Use DeviceInfo in mqtt

* Updates for mypy

Co-authored-by: epenet <epenet@users.noreply.github.com>
2021-10-25 13:46:09 +02:00
Erik Montnemery 1eebe45154
Add support for entity categories to MQTT entities (#57656)
* Add support for entity categories to MQTT entities

* Improve test

* Apply suggestions from code review

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

* Update homeassistant/components/mqtt/mixins.py

Co-authored-by: Paul Monigatti <paulmonigatti@users.noreply.github.com>

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Paul Monigatti <paulmonigatti@users.noreply.github.com>
2021-10-15 14:28:30 +02:00
Franck Nijhof eed9f67402
Add service configuration URL to MQTT (#57731) 2021-10-14 18:27:40 -07:00
Jan Bouwhuis a36a765352
Allow MQTT discovery availability shortcut (#57479)
* replace base in availability topic

* add tests for availability shortcuts - fix import

* group constants

* simplified loop

* Moving constants to .const

* rename value to topic

* move CONF_TOPIC to .const

* move CONF_AVAILABILITY to .const

* remove check for string

* Silently ignore if no config topic is found.

* CONF_TOPIC should be required
2021-10-11 23:37:31 +02:00
Marc Mueller 364767ff22
Import Callable from collections.abc (4) (#56778) 2021-09-29 16:15:36 +02:00
Erik Montnemery 3432efddaa
Remember state of MQTT availability topics when reconfiguring (#55199) 2021-08-25 12:23:42 +02:00
Erik Montnemery 4d32e1ed01
Minor improvements of MQTT typing (#52578)
* Minor improvements of MQTT typing

* Tweak
2021-07-06 14:38:48 +02:00