Improve coverage MQTT device_trigger (#87408)

* Improve coverage MQTT device_trigger

* Use assert
This commit is contained in:
Jan Bouwhuis 2023-02-09 17:42:32 +01:00 committed by GitHub
parent a13535b0c7
commit 1a38b9f665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -21,7 +21,6 @@ from homeassistant.const import (
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -35,7 +34,7 @@ from .const import (
CONF_TOPIC,
DOMAIN,
)
from .discovery import MQTT_DISCOVERY_DONE, MQTTDiscoveryPayload
from .discovery import MQTTDiscoveryPayload
from .mixins import (
MQTT_ENTITY_DEVICE_INFO_SCHEMA,
MqttDiscoveryDeviceUpdate,
@ -268,12 +267,9 @@ async def async_setup_trigger(
) -> None:
"""Set up the MQTT device trigger."""
config = TRIGGER_DISCOVERY_SCHEMA(config)
discovery_hash: tuple[str, str] = discovery_data[ATTR_DISCOVERY_HASH]
if (device_id := update_device(hass, config_entry, config)) is None:
async_dispatcher_send(hass, MQTT_DISCOVERY_DONE.format(discovery_hash), None)
return
device_id = update_device(hass, config_entry, config)
assert isinstance(device_id, str)
mqtt_device_trigger = MqttDeviceTrigger(
hass, config, device_id, discovery_data, config_entry
)

View File

@ -11,6 +11,7 @@ from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.mqtt import _LOGGER, DOMAIN, debug_info
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.trigger import async_initialize_triggers
from homeassistant.setup import async_setup_component
@ -964,6 +965,10 @@ async def test_attach_remove_late2(
await hass.async_block_till_done()
assert len(calls) == 0
# Try to remove the trigger twice
with pytest.raises(HomeAssistantError):
remove()
async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator