diff --git a/tests/components/media_player/test_device_condition.py b/tests/components/media_player/test_device_condition.py index 63cdb1c55a7..60e1ae7d19b 100644 --- a/tests/components/media_player/test_device_condition.py +++ b/tests/components/media_player/test_device_condition.py @@ -2,6 +2,7 @@ import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.media_player import DOMAIN from homeassistant.const import ( STATE_IDLE, @@ -88,7 +89,9 @@ async def test_get_conditions(hass, device_reg, entity_reg): "entity_id": f"{DOMAIN}.test_5678", }, ] - conditions = await async_get_device_automations(hass, "condition", device_entry.id) + conditions = await async_get_device_automations( + hass, DeviceAutomationType.CONDITION, device_entry.id + ) assert_lists_same(conditions, expected_conditions) diff --git a/tests/components/media_player/test_device_trigger.py b/tests/components/media_player/test_device_trigger.py index 2e3641242f9..6440430e2d2 100644 --- a/tests/components/media_player/test_device_trigger.py +++ b/tests/components/media_player/test_device_trigger.py @@ -4,6 +4,7 @@ from datetime import timedelta import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.media_player import DOMAIN from homeassistant.const import ( STATE_IDLE, @@ -68,7 +69,9 @@ async def test_get_triggers(hass, device_reg, entity_reg): } for trigger in trigger_types ] - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert_lists_same(triggers, expected_triggers) @@ -82,7 +85,9 @@ async def test_get_trigger_capabilities(hass, device_reg, entity_reg): ) entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id) - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 5 for trigger in triggers: capabilities = await async_get_device_automation_capabilities( diff --git a/tests/components/mobile_app/test_device_action.py b/tests/components/mobile_app/test_device_action.py index f7846ecc377..dd4d2a55d82 100644 --- a/tests/components/mobile_app/test_device_action.py +++ b/tests/components/mobile_app/test_device_action.py @@ -11,9 +11,9 @@ async def test_get_actions(hass, push_registration): webhook_id = push_registration["webhook_id"] device_id = hass.data[DOMAIN][DATA_DEVICES][webhook_id].id - assert await async_get_device_automations(hass, "action", device_id) == [ - {"domain": DOMAIN, "device_id": device_id, "type": "notify"} - ] + assert await async_get_device_automations( + hass, device_automation.DeviceAutomationType.ACTION, device_id + ) == [{"domain": DOMAIN, "device_id": device_id, "type": "notify"}] capabilitites = await device_automation._async_get_device_automation_capabilities( hass, diff --git a/tests/components/mqtt/test_device_trigger.py b/tests/components/mqtt/test_device_trigger.py index c3b16e3de43..a5359563d92 100644 --- a/tests/components/mqtt/test_device_trigger.py +++ b/tests/components/mqtt/test_device_trigger.py @@ -4,6 +4,7 @@ import json import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.mqtt import _LOGGER, DOMAIN, debug_info from homeassistant.helpers import device_registry as dr from homeassistant.helpers.trigger import async_initialize_triggers @@ -62,7 +63,9 @@ async def test_get_triggers(hass, device_reg, entity_reg, mqtt_mock): "subtype": "button_1", }, ] - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert_lists_same(triggers, expected_triggers) @@ -102,7 +105,9 @@ async def test_get_unknown_triggers(hass, device_reg, entity_reg, mqtt_mock): }, ) - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert_lists_same(triggers, []) @@ -118,7 +123,9 @@ async def test_get_non_existing_triggers(hass, device_reg, entity_reg, mqtt_mock await hass.async_block_till_done() device_entry = device_reg.async_get_device({("mqtt", "0AFFD2")}) - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert_lists_same(triggers, []) @@ -161,7 +168,9 @@ async def test_discover_bad_triggers(hass, device_reg, entity_reg, mqtt_mock): "subtype": "button_1", }, ] - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert_lists_same(triggers, expected_triggers) @@ -206,14 +215,18 @@ async def test_update_remove_triggers(hass, device_reg, entity_reg, mqtt_mock): expected_triggers2 = [dict(expected_triggers1[0])] expected_triggers2[0]["subtype"] = "button_2" - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert_lists_same(triggers, expected_triggers1) # Update trigger async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", data2) await hass.async_block_till_done() - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert_lists_same(triggers, expected_triggers2) # Remove trigger @@ -972,7 +985,9 @@ async def test_cleanup_trigger(hass, device_reg, entity_reg, mqtt_mock): device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert triggers[0]["type"] == "foo" device_reg.async_remove_device(device_entry.id) @@ -1007,7 +1022,9 @@ async def test_cleanup_device(hass, device_reg, entity_reg, mqtt_mock): device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert triggers[0]["type"] == "foo" async_fire_mqtt_message(hass, "homeassistant/device_automation/bla/config", "") @@ -1047,7 +1064,9 @@ async def test_cleanup_device_several_triggers(hass, device_reg, entity_reg, mqt device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 2 assert triggers[0]["type"] == "foo" assert triggers[1]["type"] == "foo2" @@ -1059,7 +1078,9 @@ async def test_cleanup_device_several_triggers(hass, device_reg, entity_reg, mqt device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 1 assert triggers[0]["type"] == "foo2" @@ -1102,7 +1123,9 @@ async def test_cleanup_device_with_entity1(hass, device_reg, entity_reg, mqtt_mo device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 3 # 2 binary_sensor triggers + device trigger async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", "") @@ -1112,7 +1135,9 @@ async def test_cleanup_device_with_entity1(hass, device_reg, entity_reg, mqtt_mo device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 2 # 2 binary_sensor triggers async_fire_mqtt_message(hass, "homeassistant/binary_sensor/bla2/config", "") @@ -1154,7 +1179,9 @@ async def test_cleanup_device_with_entity2(hass, device_reg, entity_reg, mqtt_mo device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 3 # 2 binary_sensor triggers + device trigger async_fire_mqtt_message(hass, "homeassistant/binary_sensor/bla2/config", "") @@ -1164,7 +1191,9 @@ async def test_cleanup_device_with_entity2(hass, device_reg, entity_reg, mqtt_mo device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 1 # device trigger async_fire_mqtt_message(hass, "homeassistant/device_automation/bla1/config", "") diff --git a/tests/components/mqtt/test_tag.py b/tests/components/mqtt/test_tag.py index dfc0bddeec4..e1f3de83a0d 100644 --- a/tests/components/mqtt/test_tag.py +++ b/tests/components/mqtt/test_tag.py @@ -5,6 +5,7 @@ from unittest.mock import ANY, patch import pytest +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.helpers import device_registry as dr from tests.common import ( @@ -609,7 +610,9 @@ async def test_cleanup_device_with_entity_and_trigger_1( device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 3 # 2 binary_sensor triggers + device trigger async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", "") @@ -669,7 +672,9 @@ async def test_cleanup_device_with_entity2(hass, device_reg, entity_reg, mqtt_mo device_entry = device_reg.async_get_device({("mqtt", "helloworld")}) assert device_entry is not None - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert len(triggers) == 3 # 2 binary_sensor triggers + device trigger async_fire_mqtt_message(hass, "homeassistant/device_automation/bla2/config", "") diff --git a/tests/components/nest/test_device_trigger.py b/tests/components/nest/test_device_trigger.py index c9dc9992410..69475fe1437 100644 --- a/tests/components/nest/test_device_trigger.py +++ b/tests/components/nest/test_device_trigger.py @@ -4,6 +4,7 @@ from google_nest_sdm.event import EventMessage import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.device_automation.exceptions import ( InvalidDeviceAutomationConfig, ) @@ -119,7 +120,9 @@ async def test_get_triggers(hass): "device_id": device_entry.id, }, ] - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert_lists_same(triggers, expected_triggers) @@ -147,7 +150,9 @@ async def test_multiple_devices(hass): entry2 = registry.async_get("camera.camera_2") assert entry2.unique_id == "device-id-2-camera" - triggers = await async_get_device_automations(hass, "trigger", entry1.device_id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, entry1.device_id + ) assert len(triggers) == 1 assert triggers[0] == { "platform": "device", @@ -156,7 +161,9 @@ async def test_multiple_devices(hass): "device_id": entry1.device_id, } - triggers = await async_get_device_automations(hass, "trigger", entry2.device_id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, entry2.device_id + ) assert len(triggers) == 1 assert triggers[0] == { "platform": "device", @@ -191,7 +198,9 @@ async def test_triggers_for_invalid_device_id(hass): assert device_entry_2 is not None with pytest.raises(InvalidDeviceAutomationConfig): - await async_get_device_automations(hass, "trigger", device_entry_2.id) + await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry_2.id + ) async def test_no_triggers(hass): @@ -203,7 +212,9 @@ async def test_no_triggers(hass): entry = registry.async_get("camera.my_camera") assert entry.unique_id == "some-device-id-camera" - triggers = await async_get_device_automations(hass, "trigger", entry.device_id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, entry.device_id + ) assert triggers == [] diff --git a/tests/components/netatmo/test_device_trigger.py b/tests/components/netatmo/test_device_trigger.py index 7e014d2648f..bbd4dd1e5ec 100644 --- a/tests/components/netatmo/test_device_trigger.py +++ b/tests/components/netatmo/test_device_trigger.py @@ -2,6 +2,7 @@ import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.netatmo import DOMAIN as NETATMO_DOMAIN from homeassistant.components.netatmo.const import ( CLIMATE_TRIGGERS, @@ -98,7 +99,7 @@ async def test_get_triggers( triggers = [ trigger for trigger in await async_get_device_automations( - hass, "trigger", device_entry.id + hass, DeviceAutomationType.TRIGGER, device_entry.id ) if trigger["domain"] == NETATMO_DOMAIN ] diff --git a/tests/components/number/test_device_action.py b/tests/components/number/test_device_action.py index a981a331e7e..806bd8771b2 100644 --- a/tests/components/number/test_device_action.py +++ b/tests/components/number/test_device_action.py @@ -3,6 +3,7 @@ import pytest import voluptuous_serialize import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.number import DOMAIN, device_action from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.setup import async_setup_component @@ -48,7 +49,9 @@ async def test_get_actions(hass, device_reg, entity_reg): "entity_id": "number.test_5678", }, ] - actions = await async_get_device_automations(hass, "action", device_entry.id) + actions = await async_get_device_automations( + hass, DeviceAutomationType.ACTION, device_entry.id + ) assert_lists_same(actions, expected_actions) @@ -69,7 +72,9 @@ async def test_get_action_no_state(hass, device_reg, entity_reg): "entity_id": "number.test_5678", }, ] - actions = await async_get_device_automations(hass, "action", device_entry.id) + actions = await async_get_device_automations( + hass, DeviceAutomationType.ACTION, device_entry.id + ) assert_lists_same(actions, expected_actions) diff --git a/tests/components/philips_js/test_device_trigger.py b/tests/components/philips_js/test_device_trigger.py index 936dd65f115..9980bf5627d 100644 --- a/tests/components/philips_js/test_device_trigger.py +++ b/tests/components/philips_js/test_device_trigger.py @@ -2,6 +2,7 @@ import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.philips_js.const import DOMAIN from homeassistant.setup import async_setup_component @@ -29,7 +30,9 @@ async def test_get_triggers(hass, mock_device): "device_id": mock_device.id, }, ] - triggers = await async_get_device_automations(hass, "trigger", mock_device.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, mock_device.id + ) assert_lists_same(triggers, expected_triggers) diff --git a/tests/components/remote/test_device_action.py b/tests/components/remote/test_device_action.py index 48e741a12a4..9c113c26578 100644 --- a/tests/components/remote/test_device_action.py +++ b/tests/components/remote/test_device_action.py @@ -2,6 +2,7 @@ import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.remote import DOMAIN from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.helpers import device_registry @@ -64,7 +65,9 @@ async def test_get_actions(hass, device_reg, entity_reg): "entity_id": f"{DOMAIN}.test_5678", }, ] - actions = await async_get_device_automations(hass, "action", device_entry.id) + actions = await async_get_device_automations( + hass, DeviceAutomationType.ACTION, device_entry.id + ) assert actions == expected_actions diff --git a/tests/components/remote/test_device_condition.py b/tests/components/remote/test_device_condition.py index 6f3c0e1c0a2..e3ed3059d8b 100644 --- a/tests/components/remote/test_device_condition.py +++ b/tests/components/remote/test_device_condition.py @@ -5,6 +5,7 @@ from unittest.mock import patch import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.remote import DOMAIN from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.helpers import device_registry @@ -65,7 +66,9 @@ async def test_get_conditions(hass, device_reg, entity_reg): "entity_id": f"{DOMAIN}.test_5678", }, ] - conditions = await async_get_device_automations(hass, "condition", device_entry.id) + conditions = await async_get_device_automations( + hass, DeviceAutomationType.CONDITION, device_entry.id + ) assert conditions == expected_conditions @@ -83,10 +86,12 @@ async def test_get_condition_capabilities(hass, device_reg, entity_reg): {"name": "for", "optional": True, "type": "positive_time_period_dict"} ] } - conditions = await async_get_device_automations(hass, "condition", device_entry.id) + conditions = await async_get_device_automations( + hass, DeviceAutomationType.CONDITION, device_entry.id + ) for condition in conditions: capabilities = await async_get_device_automation_capabilities( - hass, "condition", condition + hass, DeviceAutomationType.CONDITION, condition ) assert capabilities == expected_capabilities diff --git a/tests/components/remote/test_device_trigger.py b/tests/components/remote/test_device_trigger.py index 3afa731cf59..00c444b232e 100644 --- a/tests/components/remote/test_device_trigger.py +++ b/tests/components/remote/test_device_trigger.py @@ -4,6 +4,7 @@ from datetime import timedelta import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.remote import DOMAIN from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON from homeassistant.helpers import device_registry @@ -65,7 +66,9 @@ async def test_get_triggers(hass, device_reg, entity_reg): "entity_id": f"{DOMAIN}.test_5678", }, ] - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) assert triggers == expected_triggers @@ -83,10 +86,12 @@ async def test_get_trigger_capabilities(hass, device_reg, entity_reg): {"name": "for", "optional": True, "type": "positive_time_period_dict"} ] } - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) for trigger in triggers: capabilities = await async_get_device_automation_capabilities( - hass, "trigger", trigger + hass, DeviceAutomationType.TRIGGER, trigger ) assert capabilities == expected_capabilities diff --git a/tests/components/rfxtrx/test_device_action.py b/tests/components/rfxtrx/test_device_action.py index 6714bfdaea9..54f6430fc1d 100644 --- a/tests/components/rfxtrx/test_device_action.py +++ b/tests/components/rfxtrx/test_device_action.py @@ -7,6 +7,7 @@ import RFXtrx import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.rfxtrx import DOMAIN from homeassistant.helpers.device_registry import DeviceRegistry from homeassistant.setup import async_setup_component @@ -98,7 +99,9 @@ async def test_get_actions(hass, device_reg: DeviceRegistry, device, expected): device_entry = device_reg.async_get_device(device.device_identifiers, set()) assert device_entry - actions = await async_get_device_automations(hass, "action", device_entry.id) + actions = await async_get_device_automations( + hass, DeviceAutomationType.ACTION, device_entry.id + ) actions = [action for action in actions if action["domain"] == DOMAIN] expected_actions = [ diff --git a/tests/components/rfxtrx/test_device_trigger.py b/tests/components/rfxtrx/test_device_trigger.py index 90be97bd56f..eee437d495c 100644 --- a/tests/components/rfxtrx/test_device_trigger.py +++ b/tests/components/rfxtrx/test_device_trigger.py @@ -6,6 +6,7 @@ from typing import Any, NamedTuple import pytest import homeassistant.components.automation as automation +from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.rfxtrx import DOMAIN from homeassistant.helpers.device_registry import DeviceRegistry from homeassistant.setup import async_setup_component @@ -93,7 +94,9 @@ async def test_get_triggers(hass, device_reg, event: EventTestData, expected): for expect in expected ] - triggers = await async_get_device_automations(hass, "trigger", device_entry.id) + triggers = await async_get_device_automations( + hass, DeviceAutomationType.TRIGGER, device_entry.id + ) triggers = [value for value in triggers if value["domain"] == "rfxtrx"] assert_lists_same(triggers, expected_triggers)