Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MQTT notify platform #64728

Merged
merged 29 commits into from
Mar 8, 2022
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8b94d41
Mqtt Notify service draft
jbouwh Jan 15, 2022
47beff3
fix updates
jbouwh Jan 21, 2022
a99481b
Remove TARGET config parameter
jbouwh Jan 22, 2022
9298aec
do not use protected attributes
jbouwh Jan 22, 2022
9c83c04
complete tests
jbouwh Jan 22, 2022
c589a7b
device support for auto discovery
jbouwh Jan 23, 2022
9fad9ba
Add targets attribute and support for data param
jbouwh Jan 23, 2022
60a468e
Add tests and resolve naming issues
jbouwh Jan 23, 2022
6f26585
CONF_COMMAND_TEMPLATE from .const
jbouwh Jan 23, 2022
197b5d8
Use mqtt as default service name
jbouwh Jan 24, 2022
7ddaff3
make sure service has a unique name
jbouwh Jan 24, 2022
98768bb
pylint error
jbouwh Jan 26, 2022
e2b0d1f
fix type error
jbouwh Jan 26, 2022
2282707
Conditional device removal and test
jbouwh Feb 5, 2022
70c566e
Improve tests
jbouwh Feb 6, 2022
e589d18
update description has_notify_services()
jbouwh Feb 6, 2022
2e9fc9a
Use TypedDict for service config
jbouwh Feb 16, 2022
d48f3d4
casting- fix discovery - hass.data
jbouwh Feb 16, 2022
a65d5e3
cleanup
jbouwh Feb 16, 2022
0a98578
move MqttNotificationConfig after the schemas
jbouwh Feb 16, 2022
2813e70
fix has_notify_services
jbouwh Feb 17, 2022
24bc032
do not test log for reg update
jbouwh Feb 17, 2022
f5c3f5d
Improve casting types
jbouwh Feb 17, 2022
1baf4a1
Simplify obtaining the device_id
jbouwh Feb 17, 2022
ac7cb2d
await not needed
jbouwh Feb 17, 2022
8fa8222
Improve casting types and naming
jbouwh Feb 17, 2022
b6e5e01
Merge branch 'dev' into mqtt-notify
jbouwh Feb 20, 2022
185e672
cleanup_device_registry signature change and black
jbouwh Feb 20, 2022
ed3b59f
remove not needed condition
jbouwh Mar 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/mqtt/__init__.py
Original file line number Diff line number Diff line change
@@ -154,6 +154,7 @@
Platform.HUMIDIFIER,
Platform.LIGHT,
Platform.LOCK,
Platform.NOTIFY,
Platform.NUMBER,
Platform.SELECT,
Platform.SCENE,
2 changes: 2 additions & 0 deletions homeassistant/components/mqtt/abbreviations.py
Original file line number Diff line number Diff line change
@@ -183,6 +183,8 @@
"set_fan_spd_t": "set_fan_speed_topic",
"set_pos_tpl": "set_position_template",
"set_pos_t": "set_position_topic",
"title": "title",
"trgts": "targets",
"pos_t": "position_topic",
"pos_tpl": "position_template",
"spd_cmd_t": "speed_command_topic",
12 changes: 7 additions & 5 deletions homeassistant/components/mqtt/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Constants used by multiple MQTT modules."""
from typing import Final

from homeassistant.const import CONF_PAYLOAD

ATTR_DISCOVERY_HASH = "discovery_hash"
@@ -12,11 +14,11 @@
CONF_AVAILABILITY = "availability"
CONF_BROKER = "broker"
CONF_BIRTH_MESSAGE = "birth_message"
CONF_COMMAND_TEMPLATE = "command_template"
CONF_COMMAND_TOPIC = "command_topic"
CONF_ENCODING = "encoding"
CONF_QOS = ATTR_QOS
CONF_RETAIN = ATTR_RETAIN
CONF_COMMAND_TEMPLATE: Final = "command_template"
CONF_COMMAND_TOPIC: Final = "command_topic"
CONF_ENCODING: Final = "encoding"
CONF_QOS: Final = "qos"
CONF_RETAIN: Final = "retain"
CONF_STATE_TOPIC = "state_topic"
CONF_STATE_VALUE_TEMPLATE = "state_value_template"
CONF_TOPIC = "topic"
12 changes: 11 additions & 1 deletion homeassistant/components/mqtt/discovery.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.loader import async_get_mqtt

from .. import mqtt
@@ -48,6 +49,7 @@
"humidifier",
"light",
"lock",
"notify",
"number",
"scene",
"siren",
@@ -232,7 +234,15 @@ async def discovery_done(_):
from . import device_automation

await device_automation.async_setup_entry(hass, config_entry)
elif component == "tag":
elif component in "notify":
# Local import to avoid circular dependencies
# pylint: disable=import-outside-toplevel
from . import notify

await notify.async_setup_entry(
hass, config_entry, AddEntitiesCallback
)
elif component in "tag":
# Local import to avoid circular dependencies
# pylint: disable-next=import-outside-toplevel
from . import tag
19 changes: 11 additions & 8 deletions homeassistant/components/mqtt/mixins.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
from collections.abc import Callable
import json
import logging
from typing import Any, Protocol
from typing import Any, Protocol, cast

import voluptuous as vol

@@ -237,10 +237,10 @@ async def __call__(


async def async_setup_entry_helper(hass, domain, async_setup, schema):
"""Set up entity, automation or tag creation dynamically through MQTT discovery."""
"""Set up entity, automation, notify service or tag creation dynamically through MQTT discovery."""

async def async_discover(discovery_payload):
"""Discover and add an MQTT entity, automation or tag."""
"""Discover and add an MQTT entity, automation, notify service or tag."""
discovery_data = discovery_payload.discovery_data
try:
config = schema(discovery_payload)
@@ -496,11 +496,13 @@ def available(self) -> bool:
return self._available_latest


async def cleanup_device_registry(hass, device_id, config_entry_id):
"""Remove device registry entry if there are no remaining entities or triggers."""
async def cleanup_device_registry(
hass: HomeAssistant, device_id: str | None, config_entry_id: str | None
) -> None:
"""Remove device registry entry if there are no remaining entities, triggers or notify services."""
# Local import to avoid circular dependencies
# pylint: disable-next=import-outside-toplevel
from . import device_trigger, tag
# pylint: disable=import-outside-toplevel
from . import device_trigger, notify, tag

device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
@@ -511,9 +513,10 @@ async def cleanup_device_registry(hass, device_id, config_entry_id):
)
and not await device_trigger.async_get_triggers(hass, device_id)
and not tag.async_has_tags(hass, device_id)
and not notify.device_has_notify_services(hass, device_id)
):
device_registry.async_update_device(
device_id, remove_config_entry_id=config_entry_id
device_id, remove_config_entry_id=cast(str, config_entry_id)
)


Loading