Commit Graph

122 Commits

Author SHA1 Message Date
Franck Nijhof b1a3bfb298
Drop flake8 in favor of Ruff (#89863) 2023-03-17 13:30:06 +01: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
J. Nick Koston 1d4d688af3
Make mqtt discovery use callback functions (#87883) 2023-02-12 20:41:03 +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
Franck Nijhof 5e81d28116
Update black to 23.1.0 (#87188) 2023-02-02 18:35:24 +01:00
Shay Levy 6938f791f9
Downgrade MQTT logging (#85867) 2023-01-14 13:28:41 +01:00
Franck Nijhof baef267f33
String formatting and max line length - Part 3 (#84394) 2022-12-22 13:35:47 +01:00
Jan Bouwhuis 2785b2b52f
Add mqtt text platform (#82884) 2022-11-29 20:31:05 +01:00
Jan Bouwhuis 8a8732f0bc
Strict type hints for MQTT integration (#82317)
* Strict type hints for MQTT integration

* Fix errors

* Additional corrections

* Use cv.template to avoid untyped calls

* Enable strict typing policy for MQTT integration

* Use ignore[no-untyped-call]

* Use # type: ignore[unreachable]

* Correct cast

* Refactor getting discovery_payload

* Remove unused type ignore comments
2022-11-24 08:25:44 +01:00
Jan Bouwhuis 2f11385627
Add typing hints for MQTT mixins (#80702)
* Add typing hints for MQTT mixins

* Follow up comments

* config_entry is always set

* typing discovery_data - substate None assignment

* Rename `config[CONF_DEVICE]` -> specifications
2022-10-24 15:00:37 +02:00
Maciej Bieniek 1f0cb73ad0
Add `update` platform to MQTT integration (#80659) 2022-10-24 11:47:45 +02:00
Bert Melis 6546bba233
Process abbreviated availability options in mqtt discovery payload (#79712)
Expand availability in mqtt discovery payload
2022-10-08 15:36:49 +02:00
Jan Bouwhuis 84b2c74746
Move MQTT discovery hass.data globals to dataclass (#78706)
* Add MQTT discovery hass.data globals to dataclass

* isort

* Additional rework

* Add hass.data["mqtt_tags"] to dataclass

* Follow-up comment

* Corrections
2022-09-28 14:13:44 +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 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 acaa20cabe
Improve MQTT warning message on illegal discovery topic (#76545) 2022-08-10 09:38:40 -04:00
J. Nick Koston 666f715e76
Avoid importing MQTT into core for ServiceInfo dataclass (#74418)
* Avoid importing MQTT into core for discovery dataclass

Likely fixes #73863

* relo

* adjust

* rename

* rename

* rename

* adjust missed imports

* drop compat

* fix conflict correctly

* Update homeassistant/helpers/config_entry_flow.py

* fix black from trying to fix the conflict in github
2022-07-14 11:09:09 -05: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
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 48e3d68b53
Clean up MQTT platform entry setup at discovery (#72371)
* Setup MQTT discovery with entry setup

* Wait for entry setup in test

* flake
2022-06-13 13:38:53 +02:00
epenet f91aa33c5f
Add FlowResultType enum to data entry flow (#72955) 2022-06-07 22:02:44 -07: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
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
Erik Montnemery 750b48dcaf
Use pylint disable-next in MQTT (#66758) 2022-02-17 11:12:12 -08:00
Jan Bouwhuis 6fdaec0847
Add MQTT siren platform (#64440)
* Add mqtt siren draft

* fix tests

* Intergrate notify platform

* tests and fixes siren platform

* Add tests notify platform

* config parameters and abbreviations

* remove duplicate key

* undo move topic abbreviation

* Move const CONF_MESSAGE_COMMAND_TEMPLATE

* Remove notify service integration

* Rework

* Update homeassistant/components/mqtt/siren.py

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

* Publish JSON by default

* Allow unknown state - rename value_template

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-01-31 10:31:57 +01:00
epenet b65b25c1bb
Move MqttServiceInfo to init.py (#60905)
Co-authored-by: epenet <epenet@users.noreply.github.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-12-03 19:34:48 +01:00
epenet f6bbdec6cb
Use BaseServiceInfo inheritance in MqttServiceInfo (#60207)
Co-authored-by: epenet <epenet@users.noreply.github.com>
2021-11-23 16:52:33 +01:00
epenet 3b0d984959
Use dataclass for MqttServiceInfo (#60191)
* Use dataclass for MqttServiceInfo

* Drop test exception

Co-authored-by: epenet <epenet@users.noreply.github.com>
2021-11-23 09:01:40 +01:00
epenet 4387bbfb94
Adjust async_step_mqtt signature for strict typing (#59761)
* Add MqttServiceInfo

* Adjust async_step_mqtt signature

* Adjust async_step_mqtt signature

* Adjust components

Co-authored-by: epenet <epenet@users.noreply.github.com>
2021-11-16 13:30:38 +01:00
Erik Montnemery b5ce84cd89
Add MQTT button (#59348) 2021-11-09 12:04:14 +01:00
Marc Mueller b1d49b3b66
Use assignment expressions 29 (#58713) 2021-10-30 16:31:43 +02:00
Erik Montnemery f3bd13d179
Fix regression in MQTT discovery (#58684)
* Fix regression in MQTT discovery

* Update test
2021-10-29 15:59:16 +02:00
Marc Mueller 487fa0a905
Use assignment expressions 20 (#57969) 2021-10-20 20:31:00 +02: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 0815eede4b
Replace lists with tuples (2) (#53685) 2021-07-30 01:20:03 +02:00
Jan Bouwhuis c9eab10134
Add MQTT humidifier platform integration (#52828)
* New mqtt humidifier platform

* Add humidifier platform

* Leave out humidity step

* Use humidity in constant for payload reset

* change TARGET_HUMIDITY_RESET payload name

* _attr_max_humidity not assigned correctly

* _target_humidity_range has a zero base

* align CONF_TARGET_HUMIDITY_MIN and MAX  with model

* shorter topics for humidity_range

* Converts float to int from template

* new humidifier abbreviations

* Add common module to support tests

* Add tests

* Addtional testing

* Always require target_humidity_command_topic

* Typo

* use available_modes to align entity model

* use avail_modes not modes to avoid conflict

* typo target_humidity_value_template

* Allign modes and templates with climate platform

* mode_state_template

* target_humidity_state_template

* Typo in platform name

* Remove humidity_range feature and common lib

* Update homeassistant/components/mqtt/humidifier.py

Use vol.In, not regex

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

* black

* Update homeassistant/components/mqtt/humidifier.py

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

* Use round to convert float to target humidity

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-07-15 11:12:23 +02:00
Erik Montnemery 5e472f2c06
Improve typing of Tasmota (1/3) (#52746) 2021-07-12 20:14:03 +02:00
Erik Montnemery 79ee112490
Enable basic type checking for mqtt (#52463)
* Enable basic type checking for mqtt

* Tweak
2021-07-05 10:33:12 +02:00
Erik Montnemery 4533a77597
Add MQTT select (#52120)
* Add MQTT select

* Fix value_template support

* Lint
2021-06-24 17:09:06 +02:00
Erik Montnemery 2351f2d95e
Warn when receiving message on illegal MQTT discovery topic (#52106)
* Warn when receiving message on illegal MQTT discovery topic

* Fix test
2021-06-23 15:53:17 +02:00
Ville Skyttä c2f5dcefa5
Use flow result type constants more (#51122) 2021-05-29 14:09:13 +02:00
J. Nick Koston 3fa8ffa731
Enable mccabe complexity checks in flake8 (#49616)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-04-25 12:38:40 +02:00
jan iversen 9410aefd0d
Integrations m*: Rename HomeAssistantType to HomeAssistant. (#49567) 2021-04-22 14:53:37 -07:00
Erik Montnemery f86beed7b0
Subscribe only to valid MQTT discovery topics (#45456) 2021-01-23 08:51:25 -05:00
Diogo Gomes f18880686c
Add MQTT Number (#44739)
* Initial Commit

* initial commit

* add discovery and tests

* increase coverage

* address review

* catchup with reality
2021-01-06 08:27:46 +01:00
Erik Montnemery 34bd70aee6
Fix race when handling MQTT discovery messages (#44730)
* Fix race when handling MQTT discovery messages

* Lint

* retrigger checks
2021-01-04 12:28:17 +01:00
Erik Montnemery 97edbaa85f
Small cleanup of MQTT (#44110)
* Use relative imports of mqtt component in mqtt platforms

* Correct parameters to _async_setup_entity

* Lint
2020-12-10 21:30:07 +01:00
PeteBa 727b1d37b6
Add discovery for MQTT device tracker (#42327) 2020-12-07 13:16:56 +01:00