Rename MQTT entry mock and cleanup (#91223)
Rename to mqtt_mock_entry and cleanup
This commit is contained in:
parent
b7cc42d135
commit
bb15923968
35 changed files with 2275 additions and 2322 deletions
|
@ -135,8 +135,7 @@ _TEST_FIXTURES: dict[str, list[str] | str] = {
|
|||
"mock_zeroconf": "None",
|
||||
"mqtt_client_mock": "MqttMockPahoClient",
|
||||
"mqtt_mock": "MqttMockHAClient",
|
||||
"mqtt_mock_entry_no_yaml_config": "MqttMockHAClientGenerator",
|
||||
"mqtt_mock_entry_with_yaml_config": "MqttMockHAClientGenerator",
|
||||
"mqtt_mock_entry": "MqttMockHAClientGenerator",
|
||||
"recorder_db_url": "str",
|
||||
"recorder_mock": "Recorder",
|
||||
"requests_mock": "requests_mock.Mocker",
|
||||
|
|
|
@ -178,10 +178,10 @@ async def test_fail_setup_without_state_or_command_topic(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_update_state_via_state_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test updating with via state topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_id = "alarm_control_panel.test"
|
||||
|
@ -206,10 +206,10 @@ async def test_update_state_via_state_topic(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_ignore_update_state_if_unknown_via_state_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test ignoring updates via state topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
entity_id = "alarm_control_panel.test"
|
||||
|
||||
|
@ -233,12 +233,12 @@ async def test_ignore_update_state_if_unknown_via_state_topic(
|
|||
)
|
||||
async def test_publish_mqtt_no_code(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
service,
|
||||
payload,
|
||||
) -> None:
|
||||
"""Test publishing of MQTT messages when no code is configured."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await hass.services.async_call(
|
||||
alarm_control_panel.DOMAIN,
|
||||
|
@ -264,12 +264,12 @@ async def test_publish_mqtt_no_code(
|
|||
)
|
||||
async def test_publish_mqtt_with_code(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
service,
|
||||
payload,
|
||||
) -> None:
|
||||
"""Test publishing of MQTT messages when code is configured."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
call_count = mqtt_mock.async_publish.call_count
|
||||
|
||||
# No code provided, should not publish
|
||||
|
@ -318,12 +318,12 @@ async def test_publish_mqtt_with_code(
|
|||
)
|
||||
async def test_publish_mqtt_with_remote_code(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
service,
|
||||
payload,
|
||||
) -> None:
|
||||
"""Test publishing of MQTT messages when remode code is configured."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
call_count = mqtt_mock.async_publish.call_count
|
||||
|
||||
# No code provided, should not publish
|
||||
|
@ -363,12 +363,12 @@ async def test_publish_mqtt_with_remote_code(
|
|||
)
|
||||
async def test_publish_mqtt_with_remote_code_text(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
service: str,
|
||||
payload: str,
|
||||
) -> None:
|
||||
"""Test publishing of MQTT messages when remote text code is configured."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
call_count = mqtt_mock.async_publish.call_count
|
||||
|
||||
# No code provided, should not publish
|
||||
|
@ -460,7 +460,7 @@ async def test_publish_mqtt_with_remote_code_text(
|
|||
)
|
||||
async def test_publish_mqtt_with_code_required_false(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
service: str,
|
||||
payload: str,
|
||||
) -> None:
|
||||
|
@ -469,7 +469,7 @@ async def test_publish_mqtt_with_code_required_false(
|
|||
code_arm_required = False / code_disarm_required = False /
|
||||
code_trigger_required = False
|
||||
"""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
# No code provided, should publish
|
||||
await hass.services.async_call(
|
||||
|
@ -518,13 +518,13 @@ async def test_publish_mqtt_with_code_required_false(
|
|||
],
|
||||
)
|
||||
async def test_disarm_publishes_mqtt_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test publishing of MQTT messages while disarmed.
|
||||
|
||||
When command_template set to output json
|
||||
"""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await common.async_alarm_disarm(hass, "0123")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
|
@ -553,10 +553,10 @@ async def test_disarm_publishes_mqtt_with_template(
|
|||
],
|
||||
)
|
||||
async def test_update_state_via_state_topic_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test updating with template_value via state topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("alarm_control_panel.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -576,10 +576,10 @@ async def test_update_state_via_state_topic_template(
|
|||
],
|
||||
)
|
||||
async def test_attributes_code_number(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test attributes which are not supported by the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("alarm_control_panel.test")
|
||||
assert (
|
||||
|
@ -599,10 +599,10 @@ async def test_attributes_code_number(
|
|||
],
|
||||
)
|
||||
async def test_attributes_remote_code_number(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test attributes which are not supported by the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("alarm_control_panel.test")
|
||||
assert (
|
||||
|
@ -620,10 +620,10 @@ async def test_attributes_remote_code_number(
|
|||
],
|
||||
)
|
||||
async def test_attributes_code_text(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test attributes which are not supported by the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("alarm_control_panel.test")
|
||||
assert (
|
||||
|
@ -634,70 +634,70 @@ async def test_attributes_code_text(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_CODE])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN
|
||||
hass, mqtt_mock_entry, alarm_control_panel.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_CODE])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG_CODE,
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG_CODE,
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_ALARM_ATTRIBUTES_BLOCKED,
|
||||
|
@ -705,12 +705,12 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
@ -718,13 +718,13 @@ async def test_setting_attribute_with_template(
|
|||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -733,13 +733,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -748,13 +748,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -785,29 +785,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one alarm per unique_id."""
|
||||
await help_test_unique_id(
|
||||
hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN
|
||||
)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, alarm_control_panel.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_alarm(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered alarm_control_panel."""
|
||||
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN])
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, alarm_control_panel.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, alarm_control_panel.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_alarm_topic_and_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered alarm_control_panel."""
|
||||
|
@ -832,7 +830,7 @@ async def test_discovery_update_alarm_topic_and_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
alarm_control_panel.DOMAIN,
|
||||
config1,
|
||||
|
@ -844,7 +842,7 @@ async def test_discovery_update_alarm_topic_and_template(
|
|||
|
||||
async def test_discovery_update_alarm_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered alarm_control_panel."""
|
||||
|
@ -867,7 +865,7 @@ async def test_discovery_update_alarm_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
alarm_control_panel.DOMAIN,
|
||||
config1,
|
||||
|
@ -879,7 +877,7 @@ async def test_discovery_update_alarm_template(
|
|||
|
||||
async def test_discovery_update_unchanged_alarm(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered alarm_control_panel."""
|
||||
|
@ -892,7 +890,7 @@ async def test_discovery_update_unchanged_alarm(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
alarm_control_panel.DOMAIN,
|
||||
data1,
|
||||
|
@ -903,7 +901,7 @@ async def test_discovery_update_unchanged_alarm(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -915,7 +913,7 @@ async def test_discovery_broken(
|
|||
)
|
||||
await help_test_discovery_broken(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
alarm_control_panel.DOMAIN,
|
||||
data1,
|
||||
|
@ -932,14 +930,14 @@ async def test_discovery_broken(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
) -> None:
|
||||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN],
|
||||
topic,
|
||||
|
@ -948,81 +946,81 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT alarm control panel device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT alarm control panel device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, alarm_control_panel.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
alarm_control_panel.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
alarm_control_panel.SERVICE_ALARM_DISARM,
|
||||
|
@ -1055,7 +1053,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -1071,7 +1069,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -1097,21 +1095,21 @@ async def test_reloadable(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = alarm_control_panel.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = alarm_control_panel.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -93,11 +93,11 @@ def binary_sensor_platform_only():
|
|||
)
|
||||
async def test_setting_sensor_value_expires_availability_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the expiration of the value."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
@ -128,11 +128,11 @@ async def test_setting_sensor_value_expires_availability_topic(
|
|||
)
|
||||
async def test_setting_sensor_value_expires(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the expiration of the value."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# State should be unavailable since expire_after is defined and > 0
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
|
@ -194,11 +194,11 @@ async def expires_helper(hass: HomeAssistant) -> None:
|
|||
|
||||
async def test_expiration_on_discovery_and_discovery_update_of_binary_sensor(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that binary_sensor with expire_after set behaves correctly on discovery and discovery update."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = {
|
||||
"name": "Test",
|
||||
"state_topic": "test-topic",
|
||||
|
@ -291,10 +291,10 @@ async def test_expiration_on_discovery_and_discovery_update_of_binary_sensor(
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_value_via_mqtt_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
|
||||
|
@ -330,11 +330,11 @@ async def test_setting_sensor_value_via_mqtt_message(
|
|||
)
|
||||
async def test_invalid_sensor_value_via_mqtt_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
|
||||
|
@ -375,10 +375,10 @@ async def test_invalid_sensor_value_via_mqtt_message(
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_value_via_mqtt_message_and_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -410,11 +410,11 @@ async def test_setting_sensor_value_via_mqtt_message_and_template(
|
|||
)
|
||||
async def test_setting_sensor_value_via_mqtt_message_and_template2(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -452,11 +452,11 @@ async def test_setting_sensor_value_via_mqtt_message_and_template2(
|
|||
)
|
||||
async def test_setting_sensor_value_via_mqtt_message_and_template_and_raw_state_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test processing a raw value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -487,10 +487,10 @@ async def test_setting_sensor_value_via_mqtt_message_and_template_and_raw_state_
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_value_via_mqtt_message_empty_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -519,10 +519,10 @@ async def test_setting_sensor_value_via_mqtt_message_empty_template(
|
|||
],
|
||||
)
|
||||
async def test_valid_device_class(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of a valid sensor class."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("binary_sensor.test")
|
||||
assert state.attributes.get("device_class") == "motion"
|
||||
|
@ -545,49 +545,49 @@ async def test_valid_device_class(
|
|||
async def test_invalid_device_class(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test the setting of an invalid sensor class."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert "Invalid config for [mqtt]: expected BinarySensorDeviceClass" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -607,10 +607,10 @@ async def test_custom_availability_payload(
|
|||
],
|
||||
)
|
||||
async def test_force_update_disabled(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test force update option."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
events = []
|
||||
|
||||
|
@ -647,10 +647,10 @@ async def test_force_update_disabled(
|
|||
],
|
||||
)
|
||||
async def test_force_update_enabled(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test force update option."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
events = []
|
||||
|
||||
|
@ -688,10 +688,10 @@ async def test_force_update_enabled(
|
|||
],
|
||||
)
|
||||
async def test_off_delay(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test off_delay option."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
events = []
|
||||
|
||||
|
@ -722,21 +722,21 @@ async def test_off_delay(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
@ -744,13 +744,13 @@ async def test_setting_attribute_with_template(
|
|||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -759,13 +759,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -774,13 +774,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -809,29 +809,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one sensor per unique_id."""
|
||||
await help_test_unique_id(
|
||||
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN
|
||||
)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, binary_sensor.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_binary_sensor(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered binary_sensor."""
|
||||
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN])
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, binary_sensor.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, binary_sensor.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_binary_sensor_topic_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered binary_sensor."""
|
||||
|
@ -858,7 +856,7 @@ async def test_discovery_update_binary_sensor_topic_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
binary_sensor.DOMAIN,
|
||||
config1,
|
||||
|
@ -870,7 +868,7 @@ async def test_discovery_update_binary_sensor_topic_template(
|
|||
|
||||
async def test_discovery_update_binary_sensor_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered binary_sensor."""
|
||||
|
@ -895,7 +893,7 @@ async def test_discovery_update_binary_sensor_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
binary_sensor.DOMAIN,
|
||||
config1,
|
||||
|
@ -920,7 +918,7 @@ async def test_discovery_update_binary_sensor_template(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -929,7 +927,7 @@ async def test_encoding_subscribable_topics(
|
|||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN],
|
||||
topic,
|
||||
|
@ -941,7 +939,7 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
async def test_discovery_update_unchanged_binary_sensor(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered binary_sensor."""
|
||||
|
@ -954,7 +952,7 @@ async def test_discovery_update_unchanged_binary_sensor(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
binary_sensor.DOMAIN,
|
||||
data1,
|
||||
|
@ -965,7 +963,7 @@ async def test_discovery_update_unchanged_binary_sensor(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -973,7 +971,7 @@ async def test_discovery_broken(
|
|||
data2 = '{ "name": "Milk",' ' "state_topic": "test_topic" }'
|
||||
await help_test_discovery_broken(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
binary_sensor.DOMAIN,
|
||||
data1,
|
||||
|
@ -982,81 +980,81 @@ async def test_discovery_broken(
|
|||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT binary sensor device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT binary sensor device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, binary_sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
binary_sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
None,
|
||||
|
@ -1108,7 +1106,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_cleanup_triggers_and_restoring_state(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
tmp_path: Path,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
|
@ -1121,7 +1119,7 @@ async def test_cleanup_triggers_and_restoring_state(
|
|||
"""Test cleanup old triggers at reloading and restoring the state."""
|
||||
freezer.move_to("2022-02-02 12:01:00+01:00")
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic1", payload1)
|
||||
state = hass.states.get("binary_sensor.test1")
|
||||
|
@ -1164,7 +1162,7 @@ async def test_cleanup_triggers_and_restoring_state(
|
|||
)
|
||||
async def test_skip_restoring_state_with_over_due_expire_trigger(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test restoring a state with over due expire timer."""
|
||||
|
@ -1183,28 +1181,28 @@ async def test_skip_restoring_state_with_over_due_expire_trigger(
|
|||
)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
state = hass.states.get("binary_sensor.test3")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = binary_sensor.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = binary_sensor.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -73,10 +73,10 @@ def button_platform_only():
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("button.test_button")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -113,10 +113,10 @@ async def test_sending_mqtt_commands(
|
|||
],
|
||||
)
|
||||
async def test_command_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of MQTT commands through a command template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("button.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -137,26 +137,26 @@ async def test_command_template(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN
|
||||
hass, mqtt_mock_entry, button.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
config = {
|
||||
|
@ -170,7 +170,7 @@ async def test_default_availability_payload(
|
|||
}
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
button.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -180,7 +180,7 @@ async def test_default_availability_payload(
|
|||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
config = {
|
||||
|
@ -195,7 +195,7 @@ async def test_custom_availability_payload(
|
|||
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
button.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -205,41 +205,41 @@ async def test_custom_availability_payload(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG, None
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG, None
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
button.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -248,13 +248,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
button.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -263,13 +263,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
button.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -298,27 +298,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one button per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, button.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_button(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered button."""
|
||||
data = '{ "name": "test", "command_topic": "test_topic" }'
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, button.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, button.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_button(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered button."""
|
||||
|
@ -329,7 +329,7 @@ async def test_discovery_update_button(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
button.DOMAIN,
|
||||
config1,
|
||||
|
@ -339,7 +339,7 @@ async def test_discovery_update_button(
|
|||
|
||||
async def test_discovery_update_unchanged_button(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered button."""
|
||||
|
@ -353,7 +353,7 @@ async def test_discovery_update_unchanged_button(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
button.DOMAIN,
|
||||
data1,
|
||||
|
@ -364,69 +364,69 @@ async def test_discovery_update_unchanged_button(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
data2 = '{ "name": "Milk", "command_topic": "test_topic" }'
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, button.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, button.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT button device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT button device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, button.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
button.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
button.SERVICE_PRESS,
|
||||
|
@ -450,11 +450,11 @@ async def test_entity_debug_info_message(
|
|||
],
|
||||
)
|
||||
async def test_invalid_device_class(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device_class option with invalid value."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -483,10 +483,10 @@ async def test_invalid_device_class(
|
|||
],
|
||||
)
|
||||
async def test_valid_device_class(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device_class option with valid values."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("button.test_1")
|
||||
assert state.attributes["device_class"] == button.ButtonDeviceClass.UPDATE
|
||||
|
@ -504,7 +504,7 @@ async def test_valid_device_class(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -518,7 +518,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -542,21 +542,21 @@ async def test_reloadable(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = button.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = button.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -62,11 +62,11 @@ def camera_platform_only():
|
|||
async def test_run_camera_setup(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload."""
|
||||
topic = "test/camera"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
url = hass.states.get("camera.test_camera").attributes["entity_picture"]
|
||||
|
||||
|
@ -96,11 +96,11 @@ async def test_run_camera_setup(
|
|||
async def test_run_camera_b64_encoded(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test that it fetches the given encoded payload."""
|
||||
topic = "test/camera"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
url = hass.states.get("camera.test_camera").attributes["entity_picture"]
|
||||
|
||||
|
@ -132,12 +132,12 @@ async def test_run_camera_b64_encoded(
|
|||
async def test_camera_b64_encoded_with_availability(
|
||||
hass: HomeAssistant,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test availability works if b64 encoding is turned on."""
|
||||
topic = "test/camera"
|
||||
topic_availability = "test/camera_availability"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# Make sure we are available
|
||||
async_fire_mqtt_message(hass, topic_availability, "online")
|
||||
|
@ -155,58 +155,58 @@ async def test_camera_b64_encoded_with_availability(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN
|
||||
hass, mqtt_mock_entry, camera.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_CAMERA_ATTRIBUTES_BLOCKED,
|
||||
|
@ -214,23 +214,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -239,13 +239,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -254,13 +254,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -289,27 +289,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one camera per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, camera.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_camera(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered camera."""
|
||||
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][camera.DOMAIN])
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, camera.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_camera(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered camera."""
|
||||
|
@ -317,13 +317,13 @@ async def test_discovery_update_camera(
|
|||
config2 = {"name": "Milk", "topic": "test_topic"}
|
||||
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, camera.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_camera(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered camera."""
|
||||
|
@ -333,7 +333,7 @@ async def test_discovery_update_unchanged_camera(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
camera.DOMAIN,
|
||||
data1,
|
||||
|
@ -344,7 +344,7 @@ async def test_discovery_update_unchanged_camera(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -352,53 +352,53 @@ async def test_discovery_broken(
|
|||
data2 = '{ "name": "Milk", "topic": "test_topic"}'
|
||||
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, camera.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, camera.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT camera device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT camera device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
["test_topic"],
|
||||
|
@ -406,21 +406,21 @@ async def test_entity_id_update_subscriptions(
|
|||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, camera.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
camera.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
None,
|
||||
|
@ -441,21 +441,21 @@ async def test_reloadable(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = camera.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = camera.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -104,10 +104,10 @@ def climate_platform_only():
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_params(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the initial parameters."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("temperature") == 21
|
||||
|
@ -133,11 +133,11 @@ async def test_setup_params(
|
|||
async def test_preset_none_in_preset_modes(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test the preset mode payload reset configuration."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert "Invalid config for [mqtt]: not a valid value" in caplog.text
|
||||
|
||||
|
||||
|
@ -211,10 +211,10 @@ async def test_preset_modes_deprecation_guard(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_supported_features(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the supported_features."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
support = (
|
||||
|
@ -232,10 +232,10 @@ async def test_supported_features(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_get_hvac_modes(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that the operation list returns the correct modes."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
modes = state.attributes.get("hvac_modes")
|
||||
|
@ -252,14 +252,14 @@ async def test_get_hvac_modes(
|
|||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_operation_bad_attr_and_state(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test setting operation mode without required attribute.
|
||||
|
||||
Also check the state.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.state == "off"
|
||||
|
@ -275,10 +275,10 @@ async def test_set_operation_bad_attr_and_state(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_operation(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of new operation mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.state == "off"
|
||||
|
@ -298,11 +298,11 @@ async def test_set_operation(
|
|||
],
|
||||
)
|
||||
async def test_set_operation_pessimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting operation mode in pessimistic mode."""
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.state == "unknown"
|
||||
|
@ -331,10 +331,10 @@ async def test_set_operation_pessimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_operation_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting operation mode in optimistic mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.state == "off"
|
||||
|
@ -364,10 +364,10 @@ async def test_set_operation_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_operation_with_power_command(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of new operation mode with power command enabled."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.state == "off"
|
||||
|
@ -391,11 +391,11 @@ async def test_set_operation_with_power_command(
|
|||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_fan_mode_bad_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test setting fan mode without required attribute."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("fan_mode") == "low"
|
||||
|
@ -417,10 +417,10 @@ async def test_set_fan_mode_bad_attr(
|
|||
],
|
||||
)
|
||||
async def test_set_fan_mode_pessimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of new fan mode in pessimistic mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("fan_mode") is None
|
||||
|
@ -449,10 +449,10 @@ async def test_set_fan_mode_pessimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_fan_mode_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of new fan mode in optimistic mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("fan_mode") == "low"
|
||||
|
@ -472,10 +472,10 @@ async def test_set_fan_mode_optimistic(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_fan_mode(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of new fan mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("fan_mode") == "low"
|
||||
|
@ -488,11 +488,11 @@ async def test_set_fan_mode(
|
|||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_swing_mode_bad_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test setting swing mode without required attribute."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("swing_mode") == "off"
|
||||
|
@ -514,10 +514,10 @@ async def test_set_swing_mode_bad_attr(
|
|||
],
|
||||
)
|
||||
async def test_set_swing_pessimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting swing mode in pessimistic mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("swing_mode") is None
|
||||
|
@ -546,10 +546,10 @@ async def test_set_swing_pessimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_swing_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting swing mode in optimistic mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("swing_mode") == "off"
|
||||
|
@ -569,10 +569,10 @@ async def test_set_swing_optimistic(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_swing(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of new swing mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("swing_mode") == "off"
|
||||
|
@ -584,10 +584,10 @@ async def test_set_swing(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_target_temperature(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the target temperature."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("temperature") == 21
|
||||
|
@ -622,10 +622,10 @@ async def test_set_target_temperature(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_target_humidity(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the target humidity."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("humidity") is None
|
||||
|
@ -647,10 +647,10 @@ async def test_set_target_humidity(
|
|||
],
|
||||
)
|
||||
async def test_set_target_temperature_pessimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the target temperature."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("temperature") is None
|
||||
|
@ -679,10 +679,10 @@ async def test_set_target_temperature_pessimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_target_temperature_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the target temperature optimistic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("temperature") == 21
|
||||
|
@ -702,10 +702,10 @@ async def test_set_target_temperature_optimistic(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_target_temperature_low_high(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the low/high target temperature."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await common.async_set_temperature(
|
||||
hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE
|
||||
|
@ -733,10 +733,10 @@ async def test_set_target_temperature_low_high(
|
|||
],
|
||||
)
|
||||
async def test_set_target_temperature_low_highpessimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the low/high target temperature."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("target_temp_low") is None
|
||||
|
@ -784,10 +784,10 @@ async def test_set_target_temperature_low_highpessimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_target_temperature_low_high_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the low/high target temperature optimistic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("target_temp_low") == 21
|
||||
|
@ -829,10 +829,10 @@ async def test_set_target_temperature_low_high_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_target_humidity_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the target humidity optimistic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("humidity") is None
|
||||
|
@ -860,10 +860,10 @@ async def test_set_target_humidity_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_target_humidity_pessimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the target humidity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("humidity") is None
|
||||
|
@ -891,10 +891,10 @@ async def test_set_target_humidity_pessimistic(
|
|||
],
|
||||
)
|
||||
async def test_receive_mqtt_temperature(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test getting the current temperature via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "current_temperature", "47")
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
|
@ -912,10 +912,10 @@ async def test_receive_mqtt_temperature(
|
|||
],
|
||||
)
|
||||
async def test_receive_mqtt_humidity(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test getting the current humidity via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "current_humidity", "35")
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
|
@ -933,10 +933,10 @@ async def test_receive_mqtt_humidity(
|
|||
],
|
||||
)
|
||||
async def test_handle_target_humidity_received(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting the target humidity via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("humidity") is None
|
||||
|
@ -952,10 +952,10 @@ async def test_handle_target_humidity_received(
|
|||
[help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"action_topic": "action"},))],
|
||||
)
|
||||
async def test_handle_action_received(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test getting the action received via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# Cycle through valid modes and also check for wrong input such as "None" (str(None))
|
||||
async_fire_mqtt_message(hass, "action", "None")
|
||||
|
@ -975,11 +975,11 @@ async def test_handle_action_received(
|
|||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_preset_mode_optimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test setting of the preset mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("preset_mode") == "none"
|
||||
|
@ -1032,11 +1032,11 @@ async def test_set_preset_mode_optimistic(
|
|||
)
|
||||
async def test_set_preset_mode_explicit_optimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test setting of the preset mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("preset_mode") == "none"
|
||||
|
@ -1089,11 +1089,11 @@ async def test_set_preset_mode_explicit_optimistic(
|
|||
)
|
||||
async def test_set_preset_mode_pessimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test setting of the preset mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("preset_mode") == "none"
|
||||
|
@ -1141,10 +1141,10 @@ async def test_set_preset_mode_pessimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_aux_pessimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of the aux heating in pessimistic mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("aux_heat") == "off"
|
||||
|
@ -1168,10 +1168,10 @@ async def test_set_aux_pessimistic(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_set_aux(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting of the aux heating."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
assert state.attributes.get("aux_heat") == "off"
|
||||
|
@ -1189,39 +1189,39 @@ async def test_set_aux(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN
|
||||
hass, mqtt_mock_entry, climate.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -1244,11 +1244,11 @@ async def test_custom_availability_payload(
|
|||
)
|
||||
async def test_get_target_temperature_low_high_with_templates(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test getting temperature high/low with templates."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
|
||||
|
@ -1351,11 +1351,11 @@ async def test_get_target_temperature_low_high_with_templates(
|
|||
)
|
||||
async def test_get_with_templates(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test getting various attributes with templates."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# Operation Mode
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
|
@ -1507,11 +1507,11 @@ async def test_get_with_templates(
|
|||
)
|
||||
async def test_set_and_templates(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test setting various attributes with templates."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
# Fan Mode
|
||||
await common.async_set_fan_mode(hass, "high", ENTITY_CLIMATE)
|
||||
|
@ -1589,10 +1589,10 @@ async def test_set_and_templates(
|
|||
[help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"min_temp": 26},))],
|
||||
)
|
||||
async def test_min_temp_custom(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test a custom min temp."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
min_temp = state.attributes.get("min_temp")
|
||||
|
@ -1606,10 +1606,10 @@ async def test_min_temp_custom(
|
|||
[help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"max_temp": 60},))],
|
||||
)
|
||||
async def test_max_temp_custom(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test a custom max temp."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
max_temp = state.attributes.get("max_temp")
|
||||
|
@ -1623,10 +1623,10 @@ async def test_max_temp_custom(
|
|||
[help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"min_humidity": 42},))],
|
||||
)
|
||||
async def test_min_humidity_custom(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test a custom min humidity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
min_humidity = state.attributes.get("min_humidity")
|
||||
|
@ -1640,10 +1640,10 @@ async def test_min_humidity_custom(
|
|||
[help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"max_humidity": 58},))],
|
||||
)
|
||||
async def test_max_humidity_custom(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test a custom max humidity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
max_humidity = state.attributes.get("max_humidity")
|
||||
|
@ -1657,10 +1657,10 @@ async def test_max_humidity_custom(
|
|||
[help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"temp_step": 0.01},))],
|
||||
)
|
||||
async def test_temp_step_custom(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test a custom temp step."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(ENTITY_CLIMATE)
|
||||
temp_step = state.attributes.get("target_temp_step")
|
||||
|
@ -1685,10 +1685,10 @@ async def test_temp_step_custom(
|
|||
],
|
||||
)
|
||||
async def test_temperature_unit(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that setting temperature unit converts temperature values."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "current_temperature", "77")
|
||||
|
||||
|
@ -1697,21 +1697,21 @@ async def test_temperature_unit(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
climate.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_CLIMATE_ATTRIBUTES_BLOCKED,
|
||||
|
@ -1719,23 +1719,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
climate.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1744,13 +1744,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
climate.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1759,13 +1759,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
climate.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1796,10 +1796,10 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one climate per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, climate.DOMAIN)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -1822,7 +1822,7 @@ async def test_unique_id(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -1832,7 +1832,7 @@ async def test_encoding_subscribable_topics(
|
|||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
climate.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -1844,32 +1844,32 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
async def test_discovery_removal_climate(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered climate."""
|
||||
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN])
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, climate.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_climate(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered climate."""
|
||||
config1 = {"name": "Beer"}
|
||||
config2 = {"name": "Milk"}
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, climate.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_climate(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered climate."""
|
||||
|
@ -1879,7 +1879,7 @@ async def test_discovery_update_unchanged_climate(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
climate.DOMAIN,
|
||||
data1,
|
||||
|
@ -1890,55 +1890,55 @@ async def test_discovery_update_unchanged_climate(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer", "power_command_topic": "test_topic#" }'
|
||||
data2 = '{ "name": "Milk", "power_command_topic": "test_topic" }'
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, climate.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, climate.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT climate device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT climate device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = {
|
||||
|
@ -1952,7 +1952,7 @@ async def test_entity_id_update_subscriptions(
|
|||
}
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
climate.DOMAIN,
|
||||
config,
|
||||
["test-topic", "avty-topic"],
|
||||
|
@ -1960,16 +1960,16 @@ async def test_entity_id_update_subscriptions(
|
|||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, climate.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
config = {
|
||||
|
@ -1983,7 +1983,7 @@ async def test_entity_debug_info_message(
|
|||
}
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
climate.DOMAIN,
|
||||
config,
|
||||
climate.SERVICE_TURN_ON,
|
||||
|
@ -1995,10 +1995,10 @@ async def test_entity_debug_info_message(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_precision_default(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that setting precision to tenths works as intended."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await common.async_set_temperature(
|
||||
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
|
||||
|
@ -2013,10 +2013,10 @@ async def test_precision_default(
|
|||
[help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"precision": 0.5},))],
|
||||
)
|
||||
async def test_precision_halves(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that setting precision to halves works as intended."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await common.async_set_temperature(
|
||||
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
|
||||
|
@ -2031,10 +2031,10 @@ async def test_precision_halves(
|
|||
[help_custom_config(climate.DOMAIN, DEFAULT_CONFIG, ({"precision": 1.0},))],
|
||||
)
|
||||
async def test_precision_whole(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that setting precision to whole works as intended."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await common.async_set_temperature(
|
||||
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
|
||||
|
@ -2129,7 +2129,7 @@ async def test_precision_whole(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -2146,7 +2146,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -2224,15 +2224,15 @@ async def test_publishing_with_custom_encoding(
|
|||
)
|
||||
async def test_humidity_configuration_validity(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
valid: bool,
|
||||
) -> None:
|
||||
"""Test the validity of humidity configurations."""
|
||||
if valid:
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
return
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
|
||||
async def test_reloadable(
|
||||
|
@ -2247,21 +2247,21 @@ async def test_reloadable(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = climate.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = climate.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -145,11 +145,11 @@ def help_custom_config(
|
|||
|
||||
async def help_test_availability_when_connection_lost(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
|
@ -165,13 +165,13 @@ async def help_test_availability_when_connection_lost(
|
|||
|
||||
async def help_test_availability_without_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
assert "availability_topic" not in config[mqtt.DOMAIN][domain]
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
|
@ -226,7 +226,7 @@ async def help_test_default_availability_payload(
|
|||
|
||||
async def help_test_default_availability_list_payload(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
no_assumed_state: bool = False,
|
||||
|
@ -243,7 +243,7 @@ async def help_test_default_availability_list_payload(
|
|||
{"topic": "availability-topic1"},
|
||||
{"topic": "availability-topic2"},
|
||||
]
|
||||
await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config)
|
||||
await help_setup_component(hass, mqtt_mock_entry, domain, config)
|
||||
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
assert state and state.state == STATE_UNAVAILABLE
|
||||
|
@ -286,7 +286,7 @@ async def help_test_default_availability_list_payload(
|
|||
|
||||
async def help_test_default_availability_list_payload_all(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
no_assumed_state: bool = False,
|
||||
|
@ -304,7 +304,7 @@ async def help_test_default_availability_list_payload_all(
|
|||
{"topic": "availability-topic1"},
|
||||
{"topic": "availability-topic2"},
|
||||
]
|
||||
await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config)
|
||||
await help_setup_component(hass, mqtt_mock_entry, domain, config)
|
||||
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
assert state and state.state == STATE_UNAVAILABLE
|
||||
|
@ -348,7 +348,7 @@ async def help_test_default_availability_list_payload_all(
|
|||
|
||||
async def help_test_default_availability_list_payload_any(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
no_assumed_state: bool = False,
|
||||
|
@ -366,7 +366,7 @@ async def help_test_default_availability_list_payload_any(
|
|||
{"topic": "availability-topic1"},
|
||||
{"topic": "availability-topic2"},
|
||||
]
|
||||
await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config)
|
||||
await help_setup_component(hass, mqtt_mock_entry, domain, config)
|
||||
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
assert state and state.state == STATE_UNAVAILABLE
|
||||
|
@ -429,7 +429,7 @@ async def help_test_default_availability_list_single(
|
|||
|
||||
async def help_test_custom_availability_payload(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
no_assumed_state: bool = False,
|
||||
|
@ -445,7 +445,7 @@ async def help_test_custom_availability_payload(
|
|||
config[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic"
|
||||
config[mqtt.DOMAIN][domain]["payload_available"] = "good"
|
||||
config[mqtt.DOMAIN][domain]["payload_not_available"] = "nogood"
|
||||
await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config)
|
||||
await help_setup_component(hass, mqtt_mock_entry, domain, config)
|
||||
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
assert state and state.state == STATE_UNAVAILABLE
|
||||
|
@ -476,7 +476,7 @@ async def help_test_custom_availability_payload(
|
|||
|
||||
async def help_test_discovery_update_availability(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -484,7 +484,7 @@ async def help_test_discovery_update_availability(
|
|||
|
||||
This is a test helper for the MQTTAvailability mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add availability settings to config
|
||||
config1 = copy.deepcopy(config)
|
||||
config1[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic1"
|
||||
|
@ -554,7 +554,7 @@ async def help_test_discovery_update_availability(
|
|||
|
||||
async def help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -565,7 +565,7 @@ async def help_test_setting_attribute_via_mqtt_json_message(
|
|||
# Add JSON attributes settings to config
|
||||
config = copy.deepcopy(config)
|
||||
config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic"
|
||||
await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config)
|
||||
await help_setup_component(hass, mqtt_mock_entry, domain, config)
|
||||
|
||||
async_fire_mqtt_message(hass, "attr-topic", '{ "val": "100" }')
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
|
@ -575,7 +575,7 @@ async def help_test_setting_attribute_via_mqtt_json_message(
|
|||
|
||||
async def help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
extra_blocked_attributes: frozenset[str] | None,
|
||||
|
@ -584,7 +584,7 @@ async def help_test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
This is a test helper for the MqttAttributes mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
extra_blocked_attribute_list = list(extra_blocked_attributes or [])
|
||||
|
||||
# Add JSON attributes settings to config
|
||||
|
@ -608,7 +608,7 @@ async def help_test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
async def help_test_setting_attribute_with_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -622,7 +622,7 @@ async def help_test_setting_attribute_with_template(
|
|||
config[mqtt.DOMAIN][domain][
|
||||
"json_attributes_template"
|
||||
] = "{{ value_json['Timer1'] | tojson }}"
|
||||
await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config)
|
||||
await help_setup_component(hass, mqtt_mock_entry, domain, config)
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "attr-topic", json.dumps({"Timer1": {"Arm": 0, "Time": "22:18"}})
|
||||
|
@ -636,7 +636,7 @@ async def help_test_setting_attribute_with_template(
|
|||
|
||||
async def help_test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
|
@ -648,7 +648,7 @@ async def help_test_update_with_json_attrs_not_dict(
|
|||
# Add JSON attributes settings to config
|
||||
config = copy.deepcopy(config)
|
||||
config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic"
|
||||
await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config)
|
||||
await help_setup_component(hass, mqtt_mock_entry, domain, config)
|
||||
|
||||
async_fire_mqtt_message(hass, "attr-topic", '[ "list", "of", "things"]')
|
||||
state = hass.states.get(f"{domain}.test")
|
||||
|
@ -659,7 +659,7 @@ async def help_test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def help_test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
|
@ -671,7 +671,7 @@ async def help_test_update_with_json_attrs_bad_json(
|
|||
# Add JSON attributes settings to config
|
||||
config = copy.deepcopy(config)
|
||||
config[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic"
|
||||
await help_setup_component(hass, mqtt_mock_entry_no_yaml_config, domain, config)
|
||||
await help_setup_component(hass, mqtt_mock_entry, domain, config)
|
||||
|
||||
async_fire_mqtt_message(hass, "attr-topic", "This is not JSON")
|
||||
|
||||
|
@ -682,7 +682,7 @@ async def help_test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def help_test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
|
@ -691,7 +691,7 @@ async def help_test_discovery_update_attr(
|
|||
|
||||
This is a test helper for the MqttAttributes mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add JSON attributes settings to config
|
||||
config1 = copy.deepcopy(config)
|
||||
config1[mqtt.DOMAIN][domain]["json_attributes_topic"] = "attr-topic1"
|
||||
|
@ -723,18 +723,18 @@ async def help_test_discovery_update_attr(
|
|||
|
||||
async def help_test_unique_id(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
) -> None:
|
||||
"""Test unique id option only creates one entity per unique_id."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids(domain)) == 1
|
||||
|
||||
|
||||
async def help_test_discovery_removal(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
domain: str,
|
||||
data: str,
|
||||
|
@ -743,7 +743,7 @@ async def help_test_discovery_removal(
|
|||
|
||||
This is a test helper for the MqttDiscoveryUpdate mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -760,7 +760,7 @@ async def help_test_discovery_removal(
|
|||
|
||||
async def help_test_discovery_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog,
|
||||
domain,
|
||||
discovery_config1: DiscoveryInfoType,
|
||||
|
@ -772,7 +772,7 @@ async def help_test_discovery_update(
|
|||
|
||||
This is a test helper for the MqttDiscoveryUpdate mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add some future configuration to the configurations
|
||||
config1 = copy.deepcopy(discovery_config1)
|
||||
config1["some_future_option_1"] = "future_option_1"
|
||||
|
@ -825,7 +825,7 @@ async def help_test_discovery_update(
|
|||
|
||||
async def help_test_discovery_update_unchanged(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
domain: str,
|
||||
data1: str,
|
||||
|
@ -835,7 +835,7 @@ async def help_test_discovery_update_unchanged(
|
|||
|
||||
This is a test helper for the MqttDiscoveryUpdate mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -851,14 +851,14 @@ async def help_test_discovery_update_unchanged(
|
|||
|
||||
async def help_test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
domain: str,
|
||||
data1: str,
|
||||
data2: str,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -877,7 +877,7 @@ async def help_test_discovery_broken(
|
|||
|
||||
async def help_test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
topic: str,
|
||||
|
@ -951,7 +951,7 @@ async def help_test_encoding_subscribable_topics(
|
|||
init_payload_value_utf8 = init_payload[1].encode("utf-8")
|
||||
init_payload_value_utf16 = init_payload[1].encode("utf-16")
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass, f"homeassistant/{domain}/item1/config", json.dumps(config1)
|
||||
)
|
||||
|
@ -1012,7 +1012,7 @@ async def help_test_encoding_subscribable_topics(
|
|||
|
||||
async def help_test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -1020,7 +1020,7 @@ async def help_test_entity_device_info_with_identifier(
|
|||
|
||||
This is a test helper for the MqttDiscoveryUpdate mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1046,7 +1046,7 @@ async def help_test_entity_device_info_with_identifier(
|
|||
|
||||
async def help_test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -1054,7 +1054,7 @@ async def help_test_entity_device_info_with_connection(
|
|||
|
||||
This is a test helper for the MqttDiscoveryUpdate mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_MAC)
|
||||
|
@ -1082,12 +1082,12 @@ async def help_test_entity_device_info_with_connection(
|
|||
|
||||
async def help_test_entity_device_info_remove(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1114,7 +1114,7 @@ async def help_test_entity_device_info_remove(
|
|||
|
||||
async def help_test_entity_device_info_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -1122,7 +1122,7 @@ async def help_test_entity_device_info_update(
|
|||
|
||||
This is a test helper for the MqttDiscoveryUpdate mixin.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1150,7 +1150,7 @@ async def help_test_entity_device_info_update(
|
|||
|
||||
async def help_test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
topics: list[str] | None = None,
|
||||
|
@ -1169,7 +1169,7 @@ async def help_test_entity_id_update_subscriptions(
|
|||
entity_registry = er.async_get(hass)
|
||||
|
||||
mqtt_mock = await help_setup_component(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config, use_discovery=True
|
||||
hass, mqtt_mock_entry, domain, config, use_discovery=True
|
||||
)
|
||||
assert mqtt_mock is not None
|
||||
|
||||
|
@ -1196,14 +1196,14 @@ async def help_test_entity_id_update_subscriptions(
|
|||
|
||||
async def help_test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
topic: str | None = None,
|
||||
) -> None:
|
||||
"""Test MQTT discovery update after entity_id is updated."""
|
||||
# Add unique_id to config
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = copy.deepcopy(config)
|
||||
config[mqtt.DOMAIN][domain]["unique_id"] = "TOTALLY_UNIQUE"
|
||||
|
||||
|
@ -1243,7 +1243,7 @@ async def help_test_entity_id_update_discovery_update(
|
|||
|
||||
async def help_test_entity_debug_info(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -1251,7 +1251,7 @@ async def help_test_entity_debug_info(
|
|||
|
||||
This is a test helper for MQTT debug_info.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1284,7 +1284,7 @@ async def help_test_entity_debug_info(
|
|||
|
||||
async def help_test_entity_debug_info_max_messages(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -1292,7 +1292,7 @@ async def help_test_entity_debug_info_max_messages(
|
|||
|
||||
This is a test helper for MQTT debug_info.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1342,7 +1342,7 @@ async def help_test_entity_debug_info_max_messages(
|
|||
|
||||
async def help_test_entity_debug_info_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
service: str,
|
||||
|
@ -1357,7 +1357,7 @@ async def help_test_entity_debug_info_message(
|
|||
This is a test helper for MQTT debug_info.
|
||||
"""
|
||||
# Add device settings to config
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
config["unique_id"] = "veryunique"
|
||||
|
@ -1454,7 +1454,7 @@ async def help_test_entity_debug_info_message(
|
|||
|
||||
async def help_test_entity_debug_info_remove(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -1462,7 +1462,7 @@ async def help_test_entity_debug_info_remove(
|
|||
|
||||
This is a test helper for MQTT debug_info.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1504,7 +1504,7 @@ async def help_test_entity_debug_info_remove(
|
|||
|
||||
async def help_test_entity_debug_info_update_entity_id(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
|
@ -1512,7 +1512,7 @@ async def help_test_entity_debug_info_update_entity_id(
|
|||
|
||||
This is a test helper for MQTT debug_info.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1566,12 +1566,12 @@ async def help_test_entity_debug_info_update_entity_id(
|
|||
|
||||
async def help_test_entity_disabled_by_default(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1608,12 +1608,12 @@ async def help_test_entity_disabled_by_default(
|
|||
|
||||
async def help_test_entity_category(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Add device settings to config
|
||||
config = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
config["device"] = copy.deepcopy(DEFAULT_CONFIG_DEVICE_INFO_ID)
|
||||
|
@ -1655,7 +1655,7 @@ async def help_test_entity_category(
|
|||
|
||||
async def help_test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
domain: str,
|
||||
config: ConfigType,
|
||||
|
@ -1700,7 +1700,7 @@ async def help_test_publishing_with_custom_encoding(
|
|||
service_data[test_id].update(parameters)
|
||||
|
||||
# setup test entities using discovery
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
item: int = 0
|
||||
for component_config in setup_config:
|
||||
conf = json.dumps(component_config)
|
||||
|
@ -1868,7 +1868,7 @@ async def help_test_unload_config_entry(hass: HomeAssistant) -> None:
|
|||
|
||||
async def help_test_unload_config_entry_with_platform(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
domain: str,
|
||||
config: dict[str, dict[str, Any]],
|
||||
) -> None:
|
||||
|
@ -1879,7 +1879,7 @@ async def help_test_unload_config_entry_with_platform(
|
|||
config_name = config_setup
|
||||
|
||||
with patch("homeassistant.config.load_yaml_config_file", return_value=config_name):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# prepare setup through discovery
|
||||
discovery_setup = copy.deepcopy(config[mqtt.DOMAIN][domain])
|
||||
|
|
|
@ -443,14 +443,14 @@ async def test_hassio_cannot_connect(
|
|||
|
||||
async def test_option_flow(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection: MagicMock,
|
||||
) -> None:
|
||||
"""Test config flow options."""
|
||||
with patch(
|
||||
"homeassistant.config.async_hass_config_yaml", AsyncMock(return_value={})
|
||||
) as yaml_mock:
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
mock_try_connection.return_value = True
|
||||
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
config_entry.data = {
|
||||
|
@ -540,7 +540,7 @@ async def test_option_flow(
|
|||
)
|
||||
async def test_bad_certificate(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection_success: MqttMockPahoClient,
|
||||
mock_ssl_context: dict[str, MagicMock],
|
||||
mock_process_uploaded_file: MagicMock,
|
||||
|
@ -577,7 +577,7 @@ async def test_bad_certificate(
|
|||
# Client key file without client cert, client cert without key file
|
||||
test_input.pop(mqtt.CONF_CLIENT_KEY)
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
mock_try_connection.return_value = True
|
||||
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
# Add at least one advanced option to get the full form
|
||||
|
@ -636,7 +636,7 @@ async def test_bad_certificate(
|
|||
)
|
||||
async def test_keepalive_validation(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
input_value: str,
|
||||
|
@ -650,7 +650,7 @@ async def test_keepalive_validation(
|
|||
mqtt.CONF_KEEPALIVE: input_value,
|
||||
}
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
mock_try_connection.return_value = True
|
||||
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
# Add at least one advanced option to get the full form
|
||||
|
@ -682,12 +682,12 @@ async def test_keepalive_validation(
|
|||
|
||||
async def test_disable_birth_will(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
) -> None:
|
||||
"""Test disabling birth and will."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
mock_try_connection.return_value = True
|
||||
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
config_entry.data = {
|
||||
|
@ -753,12 +753,12 @@ async def test_disable_birth_will(
|
|||
|
||||
async def test_invalid_discovery_prefix(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
) -> None:
|
||||
"""Test setting an invalid discovery prefix."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
mock_try_connection.return_value = True
|
||||
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
config_entry.data = {
|
||||
|
@ -832,12 +832,12 @@ def get_suggested(schema: vol.Schema, key: str) -> Any:
|
|||
|
||||
async def test_option_flow_default_suggested_values(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection_success: MqttMockPahoClient,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
) -> None:
|
||||
"""Test config flow options has default/suggested values."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
config_entry.data = {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
|
@ -987,7 +987,7 @@ async def test_option_flow_default_suggested_values(
|
|||
)
|
||||
async def test_skipping_advanced_options(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mock_try_connection: MagicMock,
|
||||
mock_reload_after_entry_update: MagicMock,
|
||||
advanced_options: bool,
|
||||
|
@ -1001,7 +1001,7 @@ async def test_skipping_advanced_options(
|
|||
"advanced_options": advanced_options,
|
||||
}
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
mock_try_connection.return_value = True
|
||||
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
# Initiate with a basic setup
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -41,11 +41,11 @@ def device_tracker_platform_only():
|
|||
|
||||
async def test_discover_device_tracker(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test discovering an MQTT device tracker component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -63,11 +63,11 @@ async def test_discover_device_tracker(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -92,11 +92,11 @@ async def test_discovery_broken(
|
|||
|
||||
async def test_non_duplicate_device_tracker_discovery(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test for a non duplicate component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -120,11 +120,11 @@ async def test_non_duplicate_device_tracker_discovery(
|
|||
|
||||
async def test_device_tracker_removal(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of component through empty discovery message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -142,11 +142,11 @@ async def test_device_tracker_removal(
|
|||
|
||||
async def test_device_tracker_rediscover(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test rediscover of removed component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -173,11 +173,11 @@ async def test_device_tracker_rediscover(
|
|||
|
||||
async def test_duplicate_device_tracker_removal(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test for a non duplicate component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -198,11 +198,11 @@ async def test_duplicate_device_tracker_removal(
|
|||
|
||||
async def test_device_tracker_discovery_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test for a discovery update event."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -231,12 +231,12 @@ async def test_cleanup_device_tracker(
|
|||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test discovered device is cleaned up when removed from registry."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
async_fire_mqtt_message(
|
||||
|
@ -291,11 +291,11 @@ async def test_cleanup_device_tracker(
|
|||
|
||||
async def test_setting_device_tracker_value_via_mqtt_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -319,11 +319,11 @@ async def test_setting_device_tracker_value_via_mqtt_message(
|
|||
|
||||
async def test_setting_device_tracker_value_via_mqtt_message_and_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -346,11 +346,11 @@ async def test_setting_device_tracker_value_via_mqtt_message_and_template(
|
|||
|
||||
async def test_setting_device_tracker_value_via_mqtt_message_and_template2(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -376,11 +376,11 @@ async def test_setting_device_tracker_value_via_mqtt_message_and_template2(
|
|||
|
||||
async def test_setting_device_tracker_location_via_mqtt_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the location via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -400,11 +400,11 @@ async def test_setting_device_tracker_location_via_mqtt_message(
|
|||
|
||||
async def test_setting_device_tracker_location_via_lat_lon_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the latitude and longitude via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -461,11 +461,11 @@ async def test_setting_device_tracker_location_via_lat_lon_message(
|
|||
|
||||
async def test_setting_device_tracker_location_via_reset_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the automatic inference of zones via MQTT via reset."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -537,11 +537,11 @@ async def test_setting_device_tracker_location_via_reset_message(
|
|||
|
||||
async def test_setting_device_tracker_location_via_abbr_reset_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of reset via abbreviated names and custom payloads via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/device_tracker/bla/config",
|
||||
|
@ -580,12 +580,12 @@ async def test_setting_device_tracker_location_via_abbr_reset_message(
|
|||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
device_tracker.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
None,
|
||||
|
@ -603,10 +603,10 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
],
|
||||
)
|
||||
async def test_setup_with_modern_schema(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup using the modern schema."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
dev_id = "jan"
|
||||
entity_id = f"{device_tracker.DOMAIN}.{dev_id}"
|
||||
assert hass.states.get(entity_id) is not None
|
||||
|
|
|
@ -45,10 +45,10 @@ def binary_sensor_and_sensor_only():
|
|||
async def test_get_triggers(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a discovered mqtt device."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data1 = (
|
||||
'{ "automation_type":"trigger",'
|
||||
' "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -81,10 +81,10 @@ async def test_get_triggers(
|
|||
async def test_get_unknown_triggers(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test we don't get unknown triggers."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Discover a sensor (without device triggers)
|
||||
data1 = (
|
||||
'{ "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -128,10 +128,10 @@ async def test_get_unknown_triggers(
|
|||
async def test_get_non_existing_triggers(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test getting non existing triggers."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Discover a sensor (without device triggers)
|
||||
data1 = (
|
||||
'{ "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -152,10 +152,10 @@ async def test_get_non_existing_triggers(
|
|||
async def test_discover_bad_triggers(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test bad discovery message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# Test sending bad data
|
||||
data0 = (
|
||||
'{ "automation_type":"trigger",'
|
||||
|
@ -202,10 +202,10 @@ async def test_discover_bad_triggers(
|
|||
async def test_update_remove_triggers(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test triggers can be updated and removed."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = {
|
||||
"automation_type": "trigger",
|
||||
"device": {"identifiers": ["0AFFD2"]},
|
||||
|
@ -272,10 +272,10 @@ async def test_if_fires_on_mqtt_message(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test triggers firing."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data1 = (
|
||||
'{ "automation_type":"trigger",'
|
||||
' "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -351,10 +351,10 @@ async def test_if_fires_on_mqtt_message_template(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test triggers firing."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data1 = (
|
||||
'{ "automation_type":"trigger",'
|
||||
' "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -432,10 +432,10 @@ async def test_if_fires_on_mqtt_message_late_discover(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test triggers firing of MQTT device triggers discovered after setup."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data0 = (
|
||||
'{ "device":{"identifiers":["0AFFD2"]},'
|
||||
' "state_topic": "foobar/sensor",'
|
||||
|
@ -519,10 +519,10 @@ async def test_if_fires_on_mqtt_message_after_update(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test triggers firing after update."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data1 = (
|
||||
'{ "automation_type":"trigger",'
|
||||
' "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -598,10 +598,10 @@ async def test_if_fires_on_mqtt_message_after_update(
|
|||
async def test_no_resubscribe_same_topic(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test subscription to topics without change."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
data1 = (
|
||||
'{ "automation_type":"trigger",'
|
||||
' "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -646,10 +646,10 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test triggers not firing after removal."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data1 = (
|
||||
'{ "automation_type":"trigger",'
|
||||
' "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -712,13 +712,13 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
|||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test triggers not firing after removal."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
|
@ -783,10 +783,10 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
|||
async def test_attach_remove(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test attach and removal of trigger."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data1 = (
|
||||
'{ "automation_type":"trigger",'
|
||||
' "device":{"identifiers":["0AFFD2"]},'
|
||||
|
@ -841,10 +841,10 @@ async def test_attach_remove(
|
|||
async def test_attach_remove_late(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test attach and removal of trigger ."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data0 = (
|
||||
'{ "device":{"identifiers":["0AFFD2"]},'
|
||||
' "state_topic": "foobar/sensor",'
|
||||
|
@ -907,10 +907,10 @@ async def test_attach_remove_late(
|
|||
async def test_attach_remove_late2(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test attach and removal of trigger ."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data0 = (
|
||||
'{ "device":{"identifiers":["0AFFD2"]},'
|
||||
' "state_topic": "foobar/sensor",'
|
||||
|
@ -969,10 +969,10 @@ async def test_attach_remove_late2(
|
|||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT device registry integration."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
registry = dr.async_get(hass)
|
||||
|
||||
data = json.dumps(
|
||||
|
@ -1007,10 +1007,10 @@ async def test_entity_device_info_with_connection(
|
|||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT device registry integration."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
registry = dr.async_get(hass)
|
||||
|
||||
data = json.dumps(
|
||||
|
@ -1043,10 +1043,10 @@ async def test_entity_device_info_with_identifier(
|
|||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
registry = dr.async_get(hass)
|
||||
|
||||
config = {
|
||||
|
@ -1086,10 +1086,10 @@ async def test_cleanup_trigger(
|
|||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test trigger discovery topic is cleaned when device is removed from registry."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
|
@ -1142,10 +1142,10 @@ async def test_cleanup_trigger(
|
|||
async def test_cleanup_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test removal from device registry when trigger is removed."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = {
|
||||
"automation_type": "trigger",
|
||||
"topic": "test-topic",
|
||||
|
@ -1178,10 +1178,10 @@ async def test_cleanup_device(
|
|||
async def test_cleanup_device_several_triggers(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test removal from device registry when the last trigger is removed."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = {
|
||||
"automation_type": "trigger",
|
||||
"topic": "test-topic",
|
||||
|
@ -1240,13 +1240,13 @@ async def test_cleanup_device_several_triggers(
|
|||
async def test_cleanup_device_with_entity1(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test removal from device registry for device with entity.
|
||||
|
||||
Trigger removed first, then entity.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = {
|
||||
"automation_type": "trigger",
|
||||
"topic": "test-topic",
|
||||
|
@ -1301,13 +1301,13 @@ async def test_cleanup_device_with_entity1(
|
|||
async def test_cleanup_device_with_entity2(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test removal from device registry for device with entity.
|
||||
|
||||
Entity removed first, then trigger.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = {
|
||||
"automation_type": "trigger",
|
||||
"topic": "test-topic",
|
||||
|
@ -1360,13 +1360,13 @@ async def test_cleanup_device_with_entity2(
|
|||
|
||||
|
||||
async def test_trigger_debug_info(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test debug_info.
|
||||
|
||||
This is a test helper for MQTT debug_info.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
registry = dr.async_get(hass)
|
||||
|
||||
config1 = {
|
||||
|
|
|
@ -36,10 +36,10 @@ async def test_entry_diagnostics(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
mqtt_mock.connected = True
|
||||
|
||||
|
@ -160,10 +160,10 @@ async def test_redact_diagnostics(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test redacting diagnostics."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
expected_config = dict(default_config)
|
||||
expected_config["password"] = "**REDACTED**"
|
||||
expected_config["username"] = "**REDACTED**"
|
||||
|
|
|
@ -49,10 +49,10 @@ from tests.typing import (
|
|||
)
|
||||
async def test_subscribing_config_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test setting up discovery."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
|
||||
discovery_topic = "homeassistant"
|
||||
|
@ -77,13 +77,13 @@ async def test_subscribing_config_topic(
|
|||
)
|
||||
async def test_invalid_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
topic: str,
|
||||
log: bool,
|
||||
) -> None:
|
||||
"""Test sending to invalid topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.discovery.async_dispatcher_send"
|
||||
) as mock_dispatcher_send:
|
||||
|
@ -104,11 +104,11 @@ async def test_invalid_topic(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_invalid_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test sending in invalid JSON."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.discovery.async_dispatcher_send"
|
||||
) as mock_dispatcher_send:
|
||||
|
@ -124,11 +124,11 @@ async def test_invalid_json(
|
|||
|
||||
async def test_only_valid_components(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test for a valid component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.discovery.async_dispatcher_send"
|
||||
) as mock_dispatcher_send:
|
||||
|
@ -150,10 +150,10 @@ async def test_only_valid_components(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_correct_config_discovery(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test sending in correct JSON."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/binary_sensor/bla/config",
|
||||
|
@ -171,10 +171,10 @@ async def test_correct_config_discovery(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.FAN])
|
||||
async def test_discover_fan(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test discovering an MQTT fan."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/fan/bla/config",
|
||||
|
@ -192,11 +192,11 @@ async def test_discover_fan(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CLIMATE])
|
||||
async def test_discover_climate(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test discovering an MQTT climate component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data = (
|
||||
'{ "name": "ClimateTest",'
|
||||
' "current_temperature_topic": "climate/bla/current_temp",'
|
||||
|
@ -216,10 +216,10 @@ async def test_discover_climate(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
|
||||
async def test_discover_alarm_control_panel(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test discovering an MQTT alarm control panel component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data = (
|
||||
'{ "name": "AlarmControlPanelTest",'
|
||||
' "state_topic": "test_topic",'
|
||||
|
@ -385,7 +385,7 @@ async def test_discover_alarm_control_panel(
|
|||
)
|
||||
async def test_discovery_with_object_id(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
config: str,
|
||||
entity_id: str,
|
||||
|
@ -393,7 +393,7 @@ async def test_discovery_with_object_id(
|
|||
domain: str,
|
||||
) -> None:
|
||||
"""Test discovering an MQTT entity with object_id."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(hass, topic, config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -407,10 +407,10 @@ async def test_discovery_with_object_id(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_discovery_incl_nodeid(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test sending in correct JSON with optional node_id included."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/binary_sensor/my_node_id/bla/config",
|
||||
|
@ -430,11 +430,11 @@ async def test_discovery_incl_nodeid(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_non_duplicate_discovery(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test for a non duplicate component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/binary_sensor/bla/config",
|
||||
|
@ -459,10 +459,10 @@ async def test_non_duplicate_discovery(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_removal(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test removal of component through empty discovery message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/binary_sensor/bla/config",
|
||||
|
@ -481,10 +481,10 @@ async def test_removal(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_rediscover(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test rediscover of removed component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/binary_sensor/bla/config",
|
||||
|
@ -512,10 +512,10 @@ async def test_rediscover(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_rapid_rediscover(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test immediate rediscover of removed component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
events = async_capture_events(hass, EVENT_STATE_CHANGED)
|
||||
|
||||
async_fire_mqtt_message(
|
||||
|
@ -565,10 +565,10 @@ async def test_rapid_rediscover(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_rapid_rediscover_unique(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test immediate rediscover of removed component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
events = []
|
||||
|
||||
@callback
|
||||
|
@ -628,10 +628,10 @@ async def test_rapid_rediscover_unique(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_rapid_reconfigure(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test immediate reconfigure of added component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
events = []
|
||||
|
||||
@callback
|
||||
|
@ -684,11 +684,11 @@ async def test_rapid_reconfigure(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||
async def test_duplicate_removal(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test for a non duplicate component."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
"homeassistant/binary_sensor/bla/config",
|
||||
|
@ -710,10 +710,10 @@ async def test_cleanup_device(
|
|||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test discvered device is cleaned up when entry removed from device."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
|
@ -772,10 +772,10 @@ async def test_cleanup_device_mqtt(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test discvered device is cleaned up when removed through MQTT."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
data = (
|
||||
'{ "device":{"identifiers":["0AFFD2"]},'
|
||||
' "state_topic": "foobar/sensor",'
|
||||
|
@ -819,12 +819,12 @@ async def test_cleanup_device_multiple_config_entries(
|
|||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test discovered device is cleaned up when entry removed from device."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
config_entry = MockConfigEntry(domain="test", data={})
|
||||
|
@ -924,10 +924,10 @@ async def test_cleanup_device_multiple_config_entries_mqtt(
|
|||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test discovered device is cleaned up when removed through MQTT."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
config_entry = MockConfigEntry(domain="test", data={})
|
||||
config_entry.add_to_hass(hass)
|
||||
device_entry = device_registry.async_get_or_create(
|
||||
|
@ -1008,10 +1008,10 @@ async def test_cleanup_device_multiple_config_entries_mqtt(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||
async def test_discovery_expansion(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test expansion of abbreviated discovery payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data = (
|
||||
'{ "~": "some/base/topic",'
|
||||
' "name": "DiscoveryExpansionTest1",'
|
||||
|
@ -1071,10 +1071,10 @@ async def test_discovery_expansion(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||
async def test_discovery_expansion_2(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test expansion of abbreviated discovery payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data = (
|
||||
'{ "~": "some/base/topic",'
|
||||
' "name": "DiscoveryExpansionTest1",'
|
||||
|
@ -1117,11 +1117,11 @@ async def test_discovery_expansion_2(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_expansion_3(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test expansion of broken discovery payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data = (
|
||||
'{ "~": "some/base/topic",'
|
||||
' "name": "DiscoveryExpansionTest1",'
|
||||
|
@ -1153,10 +1153,10 @@ async def test_discovery_expansion_3(
|
|||
|
||||
async def test_discovery_expansion_without_encoding_and_value_template_1(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test expansion of raw availability payload with a template as list."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data = (
|
||||
'{ "~": "some/base/topic",'
|
||||
' "name": "DiscoveryExpansionTest1",'
|
||||
|
@ -1205,10 +1205,10 @@ async def test_discovery_expansion_without_encoding_and_value_template_1(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||
async def test_discovery_expansion_without_encoding_and_value_template_2(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test expansion of raw availability payload with a template directly."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data = (
|
||||
'{ "~": "some/base/topic",'
|
||||
' "name": "DiscoveryExpansionTest1",'
|
||||
|
@ -1290,10 +1290,10 @@ ABBREVIATIONS_WHITE_LIST = [
|
|||
|
||||
async def test_missing_discover_abbreviations(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Check MQTT platforms for missing abbreviations."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
missing = []
|
||||
regex = re.compile(r"(CONF_[a-zA-Z\d_]*) *= *[\'\"]([a-zA-Z\d_]*)[\'\"]")
|
||||
for fil in Path(mqtt.__file__).parent.rglob("*.py"):
|
||||
|
@ -1319,10 +1319,10 @@ async def test_missing_discover_abbreviations(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||
async def test_no_implicit_state_topic_switch(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test no implicit state topic for switch."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
data = '{ "name": "Test1", "command_topic": "cmnd" }'
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/switch/bla/config", data)
|
||||
|
@ -1352,10 +1352,10 @@ async def test_no_implicit_state_topic_switch(
|
|||
],
|
||||
)
|
||||
async def test_complex_discovery_topic_prefix(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Tests handling of discovery topic prefix with multiple slashes."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
|
@ -1379,10 +1379,10 @@ async def test_complex_discovery_topic_prefix(
|
|||
async def test_mqtt_integration_discovery_subscribe_unsubscribe(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Check MQTT integration discovery subscribe and unsubscribe."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
entry = hass.config_entries.async_entries("mqtt")[0]
|
||||
|
@ -1426,10 +1426,10 @@ async def test_mqtt_integration_discovery_subscribe_unsubscribe(
|
|||
async def test_mqtt_discovery_unsubscribe_once(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Check MQTT integration discovery unsubscribe once."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
mock_entity_platform(hass, "config_flow.comp", None)
|
||||
|
||||
entry = hass.config_entries.async_entries("mqtt")[0]
|
||||
|
@ -1464,12 +1464,12 @@ async def test_mqtt_discovery_unsubscribe_once(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
||||
async def test_clear_config_topic_disabled_entity(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the discovery topic is removed when a disabled entity is removed."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
# discover an entity that is not enabled by default
|
||||
config = {
|
||||
"name": "sbfspot_12345",
|
||||
|
@ -1540,12 +1540,12 @@ async def test_clear_config_topic_disabled_entity(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
||||
async def test_clean_up_registry_monitoring(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Test registry monitoring hook is removed after a reload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
hooks: dict = hass.data["mqtt"].discovery_registry_hooks
|
||||
# discover an entity that is not enabled by default
|
||||
config1 = {
|
||||
|
@ -1595,11 +1595,11 @@ async def test_clean_up_registry_monitoring(
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
||||
async def test_unique_id_collission_has_priority(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test the unique_id collision detection has priority over registry disabled items."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = {
|
||||
"name": "sbfspot_12345",
|
||||
"state_topic": "homeassistant_test/sensor/sbfspot_0/sbfspot_12345/",
|
||||
|
@ -1643,10 +1643,10 @@ async def test_unique_id_collission_has_priority(
|
|||
@pytest.mark.xfail(raises=MultipleInvalid)
|
||||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
||||
async def test_update_with_bad_config_not_breaks_discovery(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test a bad update does not break discovery."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# discover a sensor
|
||||
config1 = {
|
||||
"name": "sbfspot_12345",
|
||||
|
|
|
@ -89,11 +89,11 @@ def fan_platform_only():
|
|||
async def test_fail_setup_if_no_command_topic(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test if command fails with command topic."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['fan'][0]['command_topic']"
|
||||
in caplog.text
|
||||
|
@ -138,11 +138,11 @@ async def test_fail_setup_if_no_command_topic(
|
|||
)
|
||||
async def test_controlling_state_via_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -262,11 +262,11 @@ async def test_controlling_state_via_topic(
|
|||
)
|
||||
async def test_controlling_state_via_topic_with_different_speed_range(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic using an alternate speed range."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "percentage-state-topic1", "100")
|
||||
state = hass.states.get("fan.test1")
|
||||
|
@ -314,11 +314,11 @@ async def test_controlling_state_via_topic_with_different_speed_range(
|
|||
)
|
||||
async def test_controlling_state_via_topic_no_percentage_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic without percentage topics."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -384,11 +384,11 @@ async def test_controlling_state_via_topic_no_percentage_topics(
|
|||
)
|
||||
async def test_controlling_state_via_topic_and_json_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message (percentage mode)."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -491,11 +491,11 @@ async def test_controlling_state_via_topic_and_json_message(
|
|||
)
|
||||
async def test_controlling_state_via_topic_and_json_message_shared_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message using a shared topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -572,10 +572,10 @@ async def test_controlling_state_via_topic_and_json_message_shared_topic(
|
|||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test optimistic mode without state topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -711,10 +711,10 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_with_alternate_speed_range(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the controlling state via topic using an alternate speed range."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await common.async_set_percentage(hass, "fan.test1", 0)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
|
@ -803,11 +803,11 @@ async def test_sending_mqtt_commands_with_alternate_speed_range(
|
|||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic_no_legacy(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test optimistic mode without state topic without legacy speed command topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -942,10 +942,10 @@ async def test_sending_mqtt_commands_and_optimistic_no_legacy(
|
|||
)
|
||||
async def test_sending_mqtt_command_templates_(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test optimistic mode without state topic without legacy speed command topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1082,10 +1082,10 @@ async def test_sending_mqtt_command_templates_(
|
|||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test optimistic mode without state topic without percentage command topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1150,10 +1150,10 @@ async def test_sending_mqtt_commands_and_optimistic_no_percentage_topic(
|
|||
)
|
||||
async def test_sending_mqtt_commands_and_explicit_optimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test optimistic mode with state topic and turn on attributes."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1372,7 +1372,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -1386,7 +1386,7 @@ async def test_encoding_subscribable_topics(
|
|||
config[CONF_OSCILLATION_COMMAND_TOPIC] = "fan/some_oscillation_command_topic"
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
fan.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -1418,11 +1418,11 @@ async def test_encoding_subscribable_topics(
|
|||
)
|
||||
async def test_attributes(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("fan.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1698,49 +1698,47 @@ async def test_attributes(
|
|||
)
|
||||
async def test_supported_features(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
name: str,
|
||||
success: bool,
|
||||
features,
|
||||
) -> None:
|
||||
"""Test optimistic mode without state topic."""
|
||||
if success:
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(f"fan.{name}")
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == features
|
||||
return
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN
|
||||
)
|
||||
await help_test_availability_when_connection_lost(hass, mqtt_mock_entry, fan.DOMAIN)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
fan.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
True,
|
||||
|
@ -1750,12 +1748,12 @@ async def test_default_availability_payload(
|
|||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
fan.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
True,
|
||||
|
@ -1765,21 +1763,21 @@ async def test_custom_availability_payload(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
fan.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_FAN_ATTRIBUTES_BLOCKED,
|
||||
|
@ -1787,23 +1785,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
fan.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1812,13 +1810,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
fan.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1827,12 +1825,12 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, caplog, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -1860,40 +1858,38 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique_id option only creates one fan per id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, fan.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_fan(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered fan."""
|
||||
data = '{ "name": "test", "command_topic": "test_topic" }'
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, data
|
||||
)
|
||||
await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, fan.DOMAIN, data)
|
||||
|
||||
|
||||
async def test_discovery_update_fan(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered fan."""
|
||||
config1 = {"name": "Beer", "command_topic": "test_topic"}
|
||||
config2 = {"name": "Milk", "command_topic": "test_topic"}
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, fan.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_fan(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered fan."""
|
||||
|
@ -1903,7 +1899,7 @@ async def test_discovery_update_unchanged_fan(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
fan.DOMAIN,
|
||||
data1,
|
||||
|
@ -1914,7 +1910,7 @@ async def test_discovery_update_unchanged_fan(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -1922,71 +1918,71 @@ async def test_discovery_broken(
|
|||
data2 = '{ "name": "Milk", "command_topic": "test_topic" }'
|
||||
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, fan.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, fan.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT fan device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT fan device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, fan.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
fan.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
fan.SERVICE_TURN_ON,
|
||||
|
@ -2035,7 +2031,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -2051,7 +2047,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -2075,21 +2071,21 @@ async def test_reloadable(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = fan.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = fan.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -133,12 +133,12 @@ async def async_set_humidity(
|
|||
)
|
||||
async def test_fail_setup_if_no_command_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test if command fails with command topic."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['humidifier'][0]['command_topic']. Got None"
|
||||
in caplog.text
|
||||
|
@ -177,11 +177,11 @@ async def test_fail_setup_if_no_command_topic(
|
|||
)
|
||||
async def test_controlling_state_via_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("humidifier.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -280,12 +280,12 @@ async def test_controlling_state_via_topic(
|
|||
)
|
||||
async def test_controlling_state_via_topic_and_json_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message."""
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("humidifier.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -372,11 +372,11 @@ async def test_controlling_state_via_topic_and_json_message(
|
|||
)
|
||||
async def test_controlling_state_via_topic_and_json_message_shared_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message using a shared topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("humidifier.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -447,11 +447,11 @@ async def test_controlling_state_via_topic_and_json_message_shared_topic(
|
|||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test optimistic mode without state topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("humidifier.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -547,11 +547,11 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
)
|
||||
async def test_sending_mqtt_command_templates_(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Testing command templates with optimistic mode without state topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("humidifier.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -648,11 +648,11 @@ async def test_sending_mqtt_command_templates_(
|
|||
)
|
||||
async def test_sending_mqtt_commands_and_explicit_optimistic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test optimistic mode with state topic and turn on attributes."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("humidifier.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -753,7 +753,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -765,7 +765,7 @@ async def test_encoding_subscribable_topics(
|
|||
config[CONF_MODE_COMMAND_TOPIC] = "humidifier/some_mode_command_topic"
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
humidifier.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -796,11 +796,11 @@ async def test_encoding_subscribable_topics(
|
|||
)
|
||||
async def test_attributes(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("humidifier.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -939,15 +939,15 @@ async def test_attributes(
|
|||
)
|
||||
async def test_validity_configurations(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
valid: bool,
|
||||
) -> None:
|
||||
"""Test validity of configurations."""
|
||||
if valid:
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
return
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -1043,49 +1043,49 @@ async def test_validity_configurations(
|
|||
)
|
||||
async def test_supported_features(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
name: str,
|
||||
success: bool,
|
||||
features: humidifier.HumidifierEntityFeature | None,
|
||||
) -> None:
|
||||
"""Test supported features."""
|
||||
if success:
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get(f"humidifier.{name}")
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == features
|
||||
return
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
humidifier.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
True,
|
||||
|
@ -1095,12 +1095,12 @@ async def test_default_availability_payload(
|
|||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
humidifier.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
True,
|
||||
|
@ -1110,21 +1110,21 @@ async def test_custom_availability_payload(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
humidifier.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_HUMIDIFIER_ATTRIBUTES_BLOCKED,
|
||||
|
@ -1132,23 +1132,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
humidifier.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1157,13 +1157,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
humidifier.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1172,13 +1172,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
humidifier.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1211,27 +1211,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique_id option only creates one fan per id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, humidifier.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_humidifier(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered humidifier."""
|
||||
data = '{ "name": "test", "command_topic": "test_topic", "target_humidity_command_topic": "test-topic2" }'
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, humidifier.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, humidifier.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_humidifier(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered humidifier."""
|
||||
|
@ -1247,7 +1247,7 @@ async def test_discovery_update_humidifier(
|
|||
}
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
humidifier.DOMAIN,
|
||||
config1,
|
||||
|
@ -1257,7 +1257,7 @@ async def test_discovery_update_humidifier(
|
|||
|
||||
async def test_discovery_update_unchanged_humidifier(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered humidifier."""
|
||||
|
@ -1267,7 +1267,7 @@ async def test_discovery_update_unchanged_humidifier(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
humidifier.DOMAIN,
|
||||
data1,
|
||||
|
@ -1278,78 +1278,78 @@ async def test_discovery_update_unchanged_humidifier(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
data2 = '{ "name": "Milk", "command_topic": "test_topic", "target_humidity_command_topic": "test-topic2" }'
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, humidifier.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, humidifier.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT fan device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT fan device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
humidifier.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
humidifier.SERVICE_TURN_ON,
|
||||
|
@ -1391,7 +1391,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -1407,7 +1407,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -1431,21 +1431,21 @@ async def test_reloadable(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = humidifier.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = humidifier.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -125,10 +125,10 @@ def vacuum_platform_only():
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_default_supported_features(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that the correct supported features."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
entity = hass.states.get("vacuum.mqtttest")
|
||||
entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0)
|
||||
assert sorted(services_to_strings(entity_features, SERVICE_TO_STRING)) == sorted(
|
||||
|
@ -149,10 +149,10 @@ async def test_default_supported_features(
|
|||
[DEFAULT_CONFIG_ALL_SERVICES],
|
||||
)
|
||||
async def test_all_commands(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test simple commands to the vacuum."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await common.async_turn_on(hass, "vacuum.mqtttest")
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
|
@ -240,10 +240,10 @@ async def test_all_commands(
|
|||
],
|
||||
)
|
||||
async def test_commands_without_supported_features(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test commands which are not supported by the vacuum."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await common.async_turn_on(hass, "vacuum.mqtttest")
|
||||
mqtt_mock.async_publish.assert_not_called()
|
||||
|
@ -299,10 +299,10 @@ async def test_commands_without_supported_features(
|
|||
],
|
||||
)
|
||||
async def test_attributes_without_supported_features(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test attributes which are not supported by the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"battery_level": 54,
|
||||
|
@ -325,10 +325,10 @@ async def test_attributes_without_supported_features(
|
|||
[DEFAULT_CONFIG_ALL_SERVICES],
|
||||
)
|
||||
async def test_status(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"battery_level": 54,
|
||||
|
@ -365,10 +365,10 @@ async def test_status(
|
|||
[DEFAULT_CONFIG_ALL_SERVICES],
|
||||
)
|
||||
async def test_status_battery(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"battery_level": 54
|
||||
|
@ -383,11 +383,11 @@ async def test_status_battery(
|
|||
[DEFAULT_CONFIG_ALL_SERVICES],
|
||||
)
|
||||
async def test_status_cleaning(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"cleaning": true
|
||||
|
@ -402,10 +402,10 @@ async def test_status_cleaning(
|
|||
[DEFAULT_CONFIG_ALL_SERVICES],
|
||||
)
|
||||
async def test_status_docked(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"docked": true
|
||||
|
@ -420,10 +420,10 @@ async def test_status_docked(
|
|||
[DEFAULT_CONFIG_ALL_SERVICES],
|
||||
)
|
||||
async def test_status_charging(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"charging": true
|
||||
|
@ -435,10 +435,10 @@ async def test_status_charging(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES])
|
||||
async def test_status_fan_speed(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"fan_speed": "max"
|
||||
|
@ -450,10 +450,10 @@ async def test_status_fan_speed(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES])
|
||||
async def test_status_fan_speed_list(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("vacuum.mqtttest")
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == ["min", "medium", "high", "max"]
|
||||
|
@ -476,13 +476,13 @@ async def test_status_fan_speed_list(
|
|||
],
|
||||
)
|
||||
async def test_status_no_fan_speed_list(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum.
|
||||
|
||||
If the vacuum doesn't support fan speed, fan speed list should be None.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("vacuum.mqtttest")
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None
|
||||
|
@ -490,10 +490,10 @@ async def test_status_no_fan_speed_list(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES])
|
||||
async def test_status_error(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"error": "Error1"
|
||||
|
@ -526,10 +526,10 @@ async def test_status_error(
|
|||
],
|
||||
)
|
||||
async def test_battery_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that you can use non-default templates for battery_level."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "retroroomba/battery_level", "54")
|
||||
state = hass.states.get("vacuum.mqtttest")
|
||||
|
@ -539,10 +539,10 @@ async def test_battery_template(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_ALL_SERVICES])
|
||||
async def test_status_invalid_json(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test to make sure nothing breaks if the vacuum sends bad JSON."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}')
|
||||
state = hass.states.get("vacuum.mqtttest")
|
||||
|
@ -563,12 +563,12 @@ async def test_status_invalid_json(
|
|||
)
|
||||
async def test_missing_templates(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test to make sure missing template is not allowed."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: some but not all values in the same group of inclusion"
|
||||
in caplog.text
|
||||
|
@ -577,58 +577,58 @@ async def test_missing_templates(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
MQTT_LEGACY_VACUUM_ATTRIBUTES_BLOCKED,
|
||||
|
@ -636,23 +636,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
|
@ -661,13 +661,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
|
@ -676,13 +676,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
|
@ -711,40 +711,40 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one vacuum per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, vacuum.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_vacuum(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered vacuum."""
|
||||
data = json.dumps(DEFAULT_CONFIG_2[mqtt.DOMAIN][vacuum.DOMAIN])
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_vacuum(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered vacuum."""
|
||||
config1 = {"name": "Beer", "command_topic": "test_topic"}
|
||||
config2 = {"name": "Milk", "command_topic": "test_topic"}
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_vacuum(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered vacuum."""
|
||||
|
@ -754,7 +754,7 @@ async def test_discovery_update_unchanged_vacuum(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
vacuum.DOMAIN,
|
||||
data1,
|
||||
|
@ -765,55 +765,55 @@ async def test_discovery_update_unchanged_vacuum(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer",' ' "command_topic": "test_topic#" }'
|
||||
data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }'
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT vacuum device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT vacuum device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
config = {
|
||||
|
@ -829,7 +829,7 @@ async def test_entity_id_update_subscriptions(
|
|||
}
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
vacuum.DOMAIN,
|
||||
config,
|
||||
["test-topic", "avty-topic"],
|
||||
|
@ -837,16 +837,16 @@ async def test_entity_id_update_subscriptions(
|
|||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
config = {
|
||||
|
@ -862,7 +862,7 @@ async def test_entity_debug_info_message(
|
|||
}
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
vacuum.DOMAIN,
|
||||
config,
|
||||
vacuum.SERVICE_TURN_ON,
|
||||
|
@ -911,7 +911,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -932,7 +932,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -977,7 +977,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -1002,7 +1002,7 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
vacuum.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -1015,9 +1015,9 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = vacuum.DOMAIN
|
||||
assert hass.states.get(f"{platform}.mqtttest")
|
||||
|
|
|
@ -247,12 +247,12 @@ def light_platform_only():
|
|||
)
|
||||
async def test_fail_setup_if_no_command_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test if command fails with command topic."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']. Got None."
|
||||
in caplog.text
|
||||
|
@ -274,10 +274,10 @@ async def test_fail_setup_if_no_command_topic(
|
|||
],
|
||||
)
|
||||
async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test if there is no color and brightness if no topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -352,12 +352,12 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
|
|||
],
|
||||
)
|
||||
async def test_controlling_state_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the controlling of the state via topic."""
|
||||
color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"]
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -480,11 +480,11 @@ async def test_controlling_state_via_topic(
|
|||
)
|
||||
async def test_invalid_state_via_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of empty data via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -597,10 +597,10 @@ async def test_invalid_state_via_topic(
|
|||
],
|
||||
)
|
||||
async def test_brightness_controlling_scale(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the brightness controlling scale."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -646,10 +646,10 @@ async def test_brightness_controlling_scale(
|
|||
],
|
||||
)
|
||||
async def test_brightness_from_rgb_controlling_scale(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the brightness controlling scale."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
|
@ -728,12 +728,12 @@ async def test_brightness_from_rgb_controlling_scale(
|
|||
],
|
||||
)
|
||||
async def test_controlling_state_via_topic_with_templates(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the state with a template."""
|
||||
color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"]
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -821,7 +821,7 @@ async def test_controlling_state_via_topic_with_templates(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of command in optimistic mode."""
|
||||
color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"]
|
||||
|
@ -838,7 +838,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
|
@ -1009,10 +1009,10 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_rgb_command_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of RGB command with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1052,10 +1052,10 @@ async def test_sending_mqtt_rgb_command_with_template(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_rgbw_command_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of RGBW command with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1095,10 +1095,10 @@ async def test_sending_mqtt_rgbw_command_with_template(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_rgbww_command_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of RGBWW command with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1137,10 +1137,10 @@ async def test_sending_mqtt_rgbww_command_with_template(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_color_temp_command_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of Color Temp command with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1176,10 +1176,10 @@ async def test_sending_mqtt_color_temp_command_with_template(
|
|||
],
|
||||
)
|
||||
async def test_on_command_first(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command being sent before brightness."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1217,10 +1217,10 @@ async def test_on_command_first(
|
|||
],
|
||||
)
|
||||
async def test_on_command_last(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command being sent after brightness."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1260,10 +1260,10 @@ async def test_on_command_last(
|
|||
],
|
||||
)
|
||||
async def test_on_command_brightness(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command being sent as only brightness."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1322,10 +1322,10 @@ async def test_on_command_brightness(
|
|||
],
|
||||
)
|
||||
async def test_on_command_brightness_scaled(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test brightness scale."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1395,10 +1395,10 @@ async def test_on_command_brightness_scaled(
|
|||
],
|
||||
)
|
||||
async def test_on_command_rgb(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command in RGB brightness mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1491,10 +1491,10 @@ async def test_on_command_rgb(
|
|||
],
|
||||
)
|
||||
async def test_on_command_rgbw(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command in RGBW brightness mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1587,10 +1587,10 @@ async def test_on_command_rgbw(
|
|||
],
|
||||
)
|
||||
async def test_on_command_rgbww(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command in RGBWW brightness mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1684,10 +1684,10 @@ async def test_on_command_rgbww(
|
|||
],
|
||||
)
|
||||
async def test_on_command_rgb_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command in RGB brightness mode with RGB template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1727,10 +1727,10 @@ async def test_on_command_rgb_template(
|
|||
],
|
||||
)
|
||||
async def test_on_command_rgbw_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command in RGBW brightness mode with RGBW template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1770,10 +1770,10 @@ async def test_on_command_rgbw_template(
|
|||
],
|
||||
)
|
||||
async def test_on_command_rgbww_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test on command in RGBWW brightness mode with RGBWW template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1824,12 +1824,12 @@ async def test_on_command_rgbww_template(
|
|||
],
|
||||
)
|
||||
async def test_on_command_white(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test sending commands for RGB + white light."""
|
||||
color_modes = ["rgb", "white"]
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1916,12 +1916,12 @@ async def test_on_command_white(
|
|||
],
|
||||
)
|
||||
async def test_explicit_color_mode(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test explicit color mode over mqtt."""
|
||||
color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "xy"]
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -2062,12 +2062,12 @@ async def test_explicit_color_mode(
|
|||
],
|
||||
)
|
||||
async def test_explicit_color_mode_templated(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test templated explicit color mode over mqtt."""
|
||||
color_modes = ["color_temp", "hs"]
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -2157,12 +2157,12 @@ async def test_explicit_color_mode_templated(
|
|||
],
|
||||
)
|
||||
async def test_white_state_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test state updates for RGB + white light."""
|
||||
color_modes = ["rgb", "white"]
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -2213,10 +2213,10 @@ async def test_white_state_update(
|
|||
],
|
||||
)
|
||||
async def test_effect(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test effect."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -2242,58 +2242,58 @@ async def test_effect(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN
|
||||
hass, mqtt_mock_entry, light.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
||||
|
@ -2301,23 +2301,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -2326,13 +2326,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -2341,13 +2341,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -2378,15 +2378,15 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one light per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, light.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered light."""
|
||||
|
@ -2395,18 +2395,16 @@ async def test_discovery_removal_light(
|
|||
' "state_topic": "test_topic",'
|
||||
' "command_topic": "test_topic" }'
|
||||
)
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data
|
||||
)
|
||||
await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, light.DOMAIN, data)
|
||||
|
||||
|
||||
async def test_discovery_ignores_extra_keys(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test discovery ignores extra keys that are not blocked."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
# inserted `platform` key should be ignored
|
||||
data = (
|
||||
'{ "name": "Beer",' ' "platform": "mqtt",' ' "command_topic": "test_topic"}'
|
||||
|
@ -2420,7 +2418,7 @@ async def test_discovery_ignores_extra_keys(
|
|||
|
||||
async def test_discovery_update_light_topic_and_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
|
@ -2665,7 +2663,7 @@ async def test_discovery_update_light_topic_and_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
config1,
|
||||
|
@ -2677,7 +2675,7 @@ async def test_discovery_update_light_topic_and_template(
|
|||
|
||||
async def test_discovery_update_light_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
|
@ -2880,7 +2878,7 @@ async def test_discovery_update_light_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
config1,
|
||||
|
@ -2892,7 +2890,7 @@ async def test_discovery_update_light_template(
|
|||
|
||||
async def test_discovery_update_unchanged_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
|
@ -2906,7 +2904,7 @@ async def test_discovery_update_unchanged_light(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
data1,
|
||||
|
@ -2917,7 +2915,7 @@ async def test_discovery_update_unchanged_light(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -2928,71 +2926,71 @@ async def test_discovery_broken(
|
|||
' "command_topic": "test_topic" }'
|
||||
)
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, light.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT light device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT light device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
light.SERVICE_TURN_ON,
|
||||
|
@ -3015,10 +3013,10 @@ async def test_entity_debug_info_message(
|
|||
],
|
||||
)
|
||||
async def test_max_mireds(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting min_mireds and max_mireds."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get("min_mireds") == 153
|
||||
|
@ -3113,7 +3111,7 @@ async def test_max_mireds(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -3133,7 +3131,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -3189,7 +3187,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -3211,7 +3209,7 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -3230,7 +3228,7 @@ async def test_encoding_subscribable_topics(
|
|||
)
|
||||
async def test_encoding_subscribable_topics_brightness(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
topic: str,
|
||||
value: str,
|
||||
|
@ -3244,7 +3242,7 @@ async def test_encoding_subscribable_topics_brightness(
|
|||
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -3274,10 +3272,10 @@ async def test_encoding_subscribable_topics_brightness(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_brightness_command_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of Brightness command with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -3318,10 +3316,10 @@ async def test_sending_mqtt_brightness_command_with_template(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_effect_command_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of Effect command with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -3362,10 +3360,10 @@ async def test_sending_mqtt_effect_command_with_template(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_hs_command_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of HS Color command with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -3405,10 +3403,10 @@ async def test_sending_mqtt_hs_command_with_template(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_xy_command_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of XY Color command with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -3430,21 +3428,21 @@ async def test_sending_mqtt_xy_command_with_template(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = light.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = light.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -192,12 +192,12 @@ class JsonValidator:
|
|||
)
|
||||
async def test_fail_setup_if_no_command_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test if setup fails with no command topic."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']. Got None."
|
||||
in caplog.text
|
||||
|
@ -215,12 +215,12 @@ async def test_fail_setup_if_no_command_topic(
|
|||
)
|
||||
async def test_fail_setup_if_color_mode_deprecated(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test if setup fails if color mode is combined with deprecated config keys."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: color_mode must not be combined with any of"
|
||||
in caplog.text
|
||||
|
@ -258,13 +258,13 @@ async def test_fail_setup_if_color_mode_deprecated(
|
|||
)
|
||||
async def test_fail_setup_if_color_modes_invalid(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
error: str,
|
||||
) -> None:
|
||||
"""Test if setup fails if supported color modes is invalid."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert error in caplog.text
|
||||
|
||||
|
||||
|
@ -284,10 +284,10 @@ async def test_fail_setup_if_color_modes_invalid(
|
|||
],
|
||||
)
|
||||
async def test_legacy_rgb_light(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test legacy RGB light flags expected features and color modes."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
color_modes = [light.ColorMode.HS]
|
||||
|
@ -312,10 +312,10 @@ async def test_legacy_rgb_light(
|
|||
],
|
||||
)
|
||||
async def test_no_color_brightness_color_temp_if_no_topics(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test for no RGB, brightness, color temp, effector XY."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -373,10 +373,10 @@ async def test_no_color_brightness_color_temp_if_no_topics(
|
|||
],
|
||||
)
|
||||
async def test_controlling_state_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the controlling of the state via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -504,12 +504,12 @@ async def test_controlling_state_via_topic(
|
|||
)
|
||||
async def test_controlling_state_via_topic2(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling of the state via topic for a light supporting color mode."""
|
||||
supported_color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "white", "xy"]
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -681,7 +681,7 @@ async def test_controlling_state_via_topic2(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of command in optimistic mode."""
|
||||
fake_state = State(
|
||||
|
@ -696,7 +696,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
|
@ -834,7 +834,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic2(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of command in optimistic mode for a light supporting color mode."""
|
||||
supported_color_modes = ["color_temp", "hs", "rgb", "rgbw", "rgbww", "white", "xy"]
|
||||
|
@ -851,7 +851,7 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
|||
)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
|
@ -1063,10 +1063,10 @@ async def test_sending_mqtt_commands_and_optimistic2(
|
|||
],
|
||||
)
|
||||
async def test_sending_hs_color(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test light.turn_on with hs color sends hs color parameters."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1125,11 +1125,11 @@ async def test_sending_hs_color(
|
|||
],
|
||||
)
|
||||
async def test_sending_rgb_color_no_brightness(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test light.turn_on with hs color sends rgb color parameters."""
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1184,10 +1184,10 @@ async def test_sending_rgb_color_no_brightness(
|
|||
],
|
||||
)
|
||||
async def test_sending_rgb_color_no_brightness2(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test light.turn_on with hs color sends rgb color parameters."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1264,10 +1264,10 @@ async def test_sending_rgb_color_no_brightness2(
|
|||
],
|
||||
)
|
||||
async def test_sending_rgb_color_with_brightness(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test light.turn_on with hs color sends rgb color parameters."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1333,11 +1333,11 @@ async def test_sending_rgb_color_with_brightness(
|
|||
],
|
||||
)
|
||||
async def test_sending_rgb_color_with_scaled_brightness(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test light.turn_on with hs color sends rgb color parameters."""
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1405,10 +1405,10 @@ async def test_sending_rgb_color_with_scaled_brightness(
|
|||
],
|
||||
)
|
||||
async def test_sending_scaled_white(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test light.turn_on with scaled white."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1449,10 +1449,10 @@ async def test_sending_scaled_white(
|
|||
],
|
||||
)
|
||||
async def test_sending_xy_color(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test light.turn_on with hs color sends xy color parameters."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1511,10 +1511,10 @@ async def test_sending_xy_color(
|
|||
],
|
||||
)
|
||||
async def test_effect(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test for effect being sent when included."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1578,10 +1578,10 @@ async def test_effect(
|
|||
],
|
||||
)
|
||||
async def test_flash_short_and_long(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test for flash length being sent when included."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1641,10 +1641,10 @@ async def test_flash_short_and_long(
|
|||
],
|
||||
)
|
||||
async def test_transition(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test for transition time being sent when included."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1693,10 +1693,10 @@ async def test_transition(
|
|||
],
|
||||
)
|
||||
async def test_brightness_scale(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test for brightness scaling."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1741,10 +1741,10 @@ async def test_brightness_scale(
|
|||
],
|
||||
)
|
||||
async def test_white_scale(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test for white scaling."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1801,10 +1801,10 @@ async def test_white_scale(
|
|||
],
|
||||
)
|
||||
async def test_invalid_values(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that invalid color/brightness/etc. values are ignored."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -1912,58 +1912,58 @@ async def test_invalid_values(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN
|
||||
hass, mqtt_mock_entry, light.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
||||
|
@ -1971,23 +1971,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1996,13 +1996,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -2011,13 +2011,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -2050,22 +2050,22 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one light per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, light.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered mqtt_json lights."""
|
||||
data = '{ "name": "test", "schema": "json", "command_topic": "test_topic" }'
|
||||
await help_test_discovery_removal(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
data,
|
||||
|
@ -2074,7 +2074,7 @@ async def test_discovery_removal(
|
|||
|
||||
async def test_discovery_update_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
|
@ -2092,7 +2092,7 @@ async def test_discovery_update_light(
|
|||
}
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
config1,
|
||||
|
@ -2102,7 +2102,7 @@ async def test_discovery_update_light(
|
|||
|
||||
async def test_discovery_update_unchanged_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
|
@ -2117,7 +2117,7 @@ async def test_discovery_update_unchanged_light(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
data1,
|
||||
|
@ -2128,7 +2128,7 @@ async def test_discovery_update_unchanged_light(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -2141,7 +2141,7 @@ async def test_discovery_broken(
|
|||
)
|
||||
await help_test_discovery_broken(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
data1,
|
||||
|
@ -2150,78 +2150,78 @@ async def test_discovery_broken(
|
|||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT light device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT light device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
light.SERVICE_TURN_ON,
|
||||
|
@ -2247,10 +2247,10 @@ async def test_entity_debug_info_message(
|
|||
],
|
||||
)
|
||||
async def test_max_mireds(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting min_mireds and max_mireds."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get("min_mireds") == 153
|
||||
|
@ -2282,7 +2282,7 @@ async def test_max_mireds(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -2300,7 +2300,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -2338,7 +2338,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -2358,7 +2358,7 @@ async def test_encoding_subscribable_topics(
|
|||
]
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -2372,9 +2372,9 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = light.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
|
|
@ -141,12 +141,12 @@ def light_platform_only():
|
|||
)
|
||||
async def test_setup_fails(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that setup fails with missing required configuration items."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert "Invalid config" in caplog.text
|
||||
|
||||
|
||||
|
@ -170,10 +170,10 @@ async def test_setup_fails(
|
|||
],
|
||||
)
|
||||
async def test_rgb_light(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test RGB light flags brightness support."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -207,10 +207,10 @@ async def test_rgb_light(
|
|||
],
|
||||
)
|
||||
async def test_state_change_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test state change via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -270,10 +270,10 @@ async def test_state_change_via_topic(
|
|||
],
|
||||
)
|
||||
async def test_state_brightness_color_effect_temp_change_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test state, bri, color, effect, color temp change."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -382,7 +382,7 @@ async def test_state_brightness_color_effect_temp_change_via_topic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of command in optimistic mode."""
|
||||
fake_state = State(
|
||||
|
@ -397,7 +397,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
|
@ -524,10 +524,10 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_non_optimistic_brightness_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending of command in optimistic mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -633,10 +633,10 @@ async def test_sending_mqtt_commands_non_optimistic_brightness_template(
|
|||
],
|
||||
)
|
||||
async def test_effect(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test effect sent over MQTT in optimistic mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -687,10 +687,10 @@ async def test_effect(
|
|||
],
|
||||
)
|
||||
async def test_flash(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test flash sent over MQTT in optimistic mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -738,10 +738,10 @@ async def test_flash(
|
|||
],
|
||||
)
|
||||
async def test_transition(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test for transition time being sent when included."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -796,11 +796,11 @@ async def test_transition(
|
|||
],
|
||||
)
|
||||
async def test_invalid_values(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that invalid values are ignored."""
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -864,58 +864,58 @@ async def test_invalid_values(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN
|
||||
hass, mqtt_mock_entry, light.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
||||
|
@ -923,23 +923,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -948,13 +948,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -963,13 +963,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1006,15 +1006,15 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one light per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, light.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered mqtt_json lights."""
|
||||
|
@ -1025,14 +1025,12 @@ async def test_discovery_removal(
|
|||
' "command_on_template": "on",'
|
||||
' "command_off_template": "off"}'
|
||||
)
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data
|
||||
)
|
||||
await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, light.DOMAIN, data)
|
||||
|
||||
|
||||
async def test_discovery_update_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
|
@ -1053,13 +1051,13 @@ async def test_discovery_update_light(
|
|||
"command_off_template": "off",
|
||||
}
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, light.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_light(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered light."""
|
||||
|
@ -1076,7 +1074,7 @@ async def test_discovery_update_unchanged_light(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
light.DOMAIN,
|
||||
data1,
|
||||
|
@ -1087,7 +1085,7 @@ async def test_discovery_update_unchanged_light(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -1101,66 +1099,66 @@ async def test_discovery_broken(
|
|||
' "command_off_template": "off"}'
|
||||
)
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, light.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, light.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT light device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT light device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
config = {
|
||||
|
@ -1177,7 +1175,7 @@ async def test_entity_debug_info_message(
|
|||
}
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
config,
|
||||
light.SERVICE_TURN_ON,
|
||||
|
@ -1203,10 +1201,10 @@ async def test_entity_debug_info_message(
|
|||
],
|
||||
)
|
||||
async def test_max_mireds(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting min_mireds and max_mireds."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.attributes.get("min_mireds") == 153
|
||||
|
@ -1238,7 +1236,7 @@ async def test_max_mireds(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -1256,7 +1254,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -1288,7 +1286,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -1300,7 +1298,7 @@ async def test_encoding_subscribable_topics(
|
|||
config["state_template"] = "{{ value }}"
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
light.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -1313,21 +1311,21 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = light.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = light.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -98,12 +98,12 @@ def lock_platform_only():
|
|||
)
|
||||
async def test_controlling_state_via_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
payload: str,
|
||||
lock_state: str,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -128,12 +128,12 @@ async def test_controlling_state_via_topic(
|
|||
)
|
||||
async def test_controlling_non_default_state_via_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
payload: str,
|
||||
lock_state: str,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -188,12 +188,12 @@ async def test_controlling_non_default_state_via_topic(
|
|||
)
|
||||
async def test_controlling_state_via_topic_and_json_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
payload: str,
|
||||
lock_state: str,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -247,12 +247,12 @@ async def test_controlling_state_via_topic_and_json_message(
|
|||
)
|
||||
async def test_controlling_non_default_state_via_topic_and_json_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
payload: str,
|
||||
lock_state: str,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -281,10 +281,10 @@ async def test_controlling_non_default_state_via_topic_and_json_message(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test optimistic mode without state topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -332,10 +332,10 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test sending commands with template."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -392,10 +392,10 @@ async def test_sending_mqtt_commands_with_template(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_explicit_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test optimistic mode without state topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -441,10 +441,10 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_support_open_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test open function of the lock without state topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -503,10 +503,10 @@ async def test_sending_mqtt_commands_support_open_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_support_open_and_explicit_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test open function of the lock without state topic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -567,10 +567,10 @@ async def test_sending_mqtt_commands_support_open_and_explicit_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_pessimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test function of the lock with state topics."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("lock.test")
|
||||
assert state.state is STATE_UNLOCKED
|
||||
|
@ -652,58 +652,58 @@ async def test_sending_mqtt_commands_pessimistic(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN
|
||||
hass, mqtt_mock_entry, lock.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
lock.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_LOCK_ATTRIBUTES_BLOCKED,
|
||||
|
@ -711,23 +711,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
lock.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -736,13 +736,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
lock.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -751,12 +751,12 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, caplog, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -784,27 +784,25 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one lock per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, lock.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_lock(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered lock."""
|
||||
data = '{ "name": "test",' ' "command_topic": "test_topic" }'
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, data
|
||||
)
|
||||
await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, lock.DOMAIN, data)
|
||||
|
||||
|
||||
async def test_discovery_update_lock(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered lock."""
|
||||
|
@ -821,13 +819,13 @@ async def test_discovery_update_lock(
|
|||
"availability_topic": "availability_topic2",
|
||||
}
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, lock.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_lock(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered lock."""
|
||||
|
@ -841,7 +839,7 @@ async def test_discovery_update_unchanged_lock(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
lock.DOMAIN,
|
||||
data1,
|
||||
|
@ -852,78 +850,78 @@ async def test_discovery_update_unchanged_lock(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }'
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, lock.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, lock.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT lock device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT lock device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, lock.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
lock.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
SERVICE_LOCK,
|
||||
|
@ -945,7 +943,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -959,7 +957,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -989,7 +987,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -998,7 +996,7 @@ async def test_encoding_subscribable_topics(
|
|||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
lock.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][lock.DOMAIN],
|
||||
topic,
|
||||
|
@ -1010,21 +1008,21 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = lock.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = lock.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -33,14 +33,14 @@ from tests.typing import MqttMockHAClientGenerator
|
|||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
||||
async def test_availability_with_shared_state_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test the state is not changed twice.
|
||||
|
||||
When an entity with a shared state_topic and availability_topic becomes available
|
||||
The state should only change once.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
events = []
|
||||
|
||||
|
|
|
@ -93,10 +93,10 @@ def number_platform_only():
|
|||
],
|
||||
)
|
||||
async def test_run_number_setup(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "test/state_number", "10")
|
||||
|
||||
|
@ -142,11 +142,11 @@ async def test_run_number_setup(
|
|||
],
|
||||
)
|
||||
async def test_value_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload with a template."""
|
||||
topic = "test/state_number"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, topic, '{"val":10}')
|
||||
|
||||
|
@ -186,7 +186,7 @@ async def test_value_template(
|
|||
],
|
||||
)
|
||||
async def test_restore_native_value(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that the stored native_value is restored."""
|
||||
|
||||
|
@ -201,7 +201,7 @@ async def test_restore_native_value(
|
|||
mock_restore_cache_with_extra_data(
|
||||
hass, ((State("number.test_number", "abc"), RESTORE_DATA),)
|
||||
)
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("number.test_number")
|
||||
assert state.state == "37.8"
|
||||
|
@ -222,7 +222,7 @@ async def test_restore_native_value(
|
|||
],
|
||||
)
|
||||
async def test_run_number_service_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that set_value service works in optimistic mode."""
|
||||
topic = "test/number"
|
||||
|
@ -239,7 +239,7 @@ async def test_run_number_service_optimistic(
|
|||
hass, ((State("number.test_number", "abc"), RESTORE_DATA),)
|
||||
)
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("number.test_number")
|
||||
assert state.state == "3"
|
||||
|
@ -300,7 +300,7 @@ async def test_run_number_service_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_run_number_service_optimistic_with_command_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that set_value service works in optimistic mode and with a command_template."""
|
||||
topic = "test/number"
|
||||
|
@ -316,7 +316,7 @@ async def test_run_number_service_optimistic_with_command_template(
|
|||
mock_restore_cache_with_extra_data(
|
||||
hass, ((State("number.test_number", "abc"), RESTORE_DATA),)
|
||||
)
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("number.test_number")
|
||||
assert state.state == "3"
|
||||
|
@ -379,13 +379,13 @@ async def test_run_number_service_optimistic_with_command_template(
|
|||
],
|
||||
)
|
||||
async def test_run_number_service(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that set_value service works in non optimistic mode."""
|
||||
cmd_topic = "test/number/set"
|
||||
state_topic = "test/number"
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, state_topic, "32")
|
||||
state = hass.states.get("number.test_number")
|
||||
|
@ -418,13 +418,13 @@ async def test_run_number_service(
|
|||
],
|
||||
)
|
||||
async def test_run_number_service_with_command_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that set_value service works in non optimistic mode and with a command_template."""
|
||||
cmd_topic = "test/number/set"
|
||||
state_topic = "test/number"
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, state_topic, "32")
|
||||
state = hass.states.get("number.test_number")
|
||||
|
@ -445,58 +445,58 @@ async def test_run_number_service_with_command_template(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN
|
||||
hass, mqtt_mock_entry, number.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
number.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_NUMBER_ATTRIBUTES_BLOCKED,
|
||||
|
@ -504,23 +504,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
number.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -529,13 +529,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
number.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -544,13 +544,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
number.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -581,27 +581,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one number per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, number.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_number(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered number."""
|
||||
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN])
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, number.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_number(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered number."""
|
||||
|
@ -617,13 +617,13 @@ async def test_discovery_update_number(
|
|||
}
|
||||
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, number.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_number(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered number."""
|
||||
|
@ -635,7 +635,7 @@ async def test_discovery_update_unchanged_number(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
number.DOMAIN,
|
||||
data1,
|
||||
|
@ -646,7 +646,7 @@ async def test_discovery_update_unchanged_number(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -656,71 +656,71 @@ async def test_discovery_broken(
|
|||
)
|
||||
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, number.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, number.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT number device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT number device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, number.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
number.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
SERVICE_SET_VALUE,
|
||||
|
@ -748,10 +748,10 @@ async def test_entity_debug_info_message(
|
|||
],
|
||||
)
|
||||
async def test_min_max_step_attributes(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test min/max/step attributes."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("number.test_number")
|
||||
assert state.attributes.get(ATTR_MIN) == 5
|
||||
|
@ -777,12 +777,12 @@ async def test_min_max_step_attributes(
|
|||
)
|
||||
async def test_invalid_min_max_attributes(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test invalid min/max attributes."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert f"'{CONF_MAX}' must be > '{CONF_MIN}'" in caplog.text
|
||||
|
||||
|
||||
|
@ -801,10 +801,10 @@ async def test_invalid_min_max_attributes(
|
|||
],
|
||||
)
|
||||
async def test_default_mode(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test default mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("number.test_number")
|
||||
assert state.attributes.get(ATTR_MODE) == "auto"
|
||||
|
@ -856,11 +856,11 @@ async def test_default_mode(
|
|||
)
|
||||
async def test_mode(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mode,
|
||||
) -> None:
|
||||
"""Test mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("number.test_number")
|
||||
assert state.attributes.get(ATTR_MODE) == mode
|
||||
|
@ -899,15 +899,15 @@ async def test_mode(
|
|||
)
|
||||
async def test_invalid_mode(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
valid: bool,
|
||||
) -> None:
|
||||
"""Test invalid mode."""
|
||||
if valid:
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
return
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -927,12 +927,12 @@ async def test_invalid_mode(
|
|||
async def test_mqtt_payload_not_a_number_warning(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test warning for MQTT payload which is not a number."""
|
||||
topic = "test/state_number"
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, topic, "not_a_number")
|
||||
|
||||
|
@ -960,13 +960,13 @@ async def test_mqtt_payload_not_a_number_warning(
|
|||
async def test_mqtt_payload_out_of_range_error(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test error when MQTT payload is out of min/max range."""
|
||||
topic = "test/state_number"
|
||||
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, topic, "115.5")
|
||||
|
||||
|
@ -991,7 +991,7 @@ async def test_mqtt_payload_out_of_range_error(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -1005,7 +1005,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -1036,7 +1036,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -1045,7 +1045,7 @@ async def test_encoding_subscribable_topics(
|
|||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
number.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN],
|
||||
topic,
|
||||
|
@ -1057,21 +1057,21 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = number.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = number.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -58,13 +58,13 @@ def scene_platform_only():
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands."""
|
||||
fake_state = State("scene.test", STATE_UNKNOWN)
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("scene.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -79,26 +79,26 @@ async def test_sending_mqtt_commands(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN
|
||||
hass, mqtt_mock_entry, scene.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, scene.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
config = {
|
||||
|
@ -112,7 +112,7 @@ async def test_default_availability_payload(
|
|||
}
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
scene.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -122,7 +122,7 @@ async def test_default_availability_payload(
|
|||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
config = {
|
||||
|
@ -137,7 +137,7 @@ async def test_custom_availability_payload(
|
|||
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
scene.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -168,27 +168,25 @@ async def test_custom_availability_payload(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one scene per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, scene.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_scene(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered scene."""
|
||||
data = '{ "name": "test",' ' "command_topic": "test_topic" }'
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, scene.DOMAIN, data
|
||||
)
|
||||
await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, scene.DOMAIN, data)
|
||||
|
||||
|
||||
async def test_discovery_update_payload(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered scene."""
|
||||
|
@ -201,7 +199,7 @@ async def test_discovery_update_payload(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
scene.DOMAIN,
|
||||
config1,
|
||||
|
@ -211,7 +209,7 @@ async def test_discovery_update_payload(
|
|||
|
||||
async def test_discovery_update_unchanged_scene(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered scene."""
|
||||
|
@ -221,7 +219,7 @@ async def test_discovery_update_unchanged_scene(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
scene.DOMAIN,
|
||||
data1,
|
||||
|
@ -232,14 +230,14 @@ async def test_discovery_update_unchanged_scene(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer" }'
|
||||
data2 = '{ "name": "Milk",' ' "command_topic": "test_topic" }'
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, scene.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, scene.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
|
@ -255,21 +253,21 @@ async def test_reloadable(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = scene.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = scene.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -99,11 +99,11 @@ def _test_run_select_setup_params(
|
|||
)
|
||||
async def test_run_select_setup(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, topic, "milk")
|
||||
|
||||
|
@ -137,10 +137,10 @@ async def test_run_select_setup(
|
|||
],
|
||||
)
|
||||
async def test_value_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload with a template."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "test/select_stat", '{"val":"milk"}')
|
||||
|
||||
|
@ -179,13 +179,13 @@ async def test_value_template(
|
|||
],
|
||||
)
|
||||
async def test_run_select_service_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that set_value service works in optimistic mode."""
|
||||
fake_state = State("select.test_select", "milk")
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("select.test_select")
|
||||
assert state.state == "milk"
|
||||
|
@ -220,13 +220,13 @@ async def test_run_select_service_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_run_select_service_optimistic_with_command_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that set_value service works in optimistic mode and with a command_template."""
|
||||
fake_state = State("select.test_select", "milk")
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("select.test_select")
|
||||
assert state.state == "milk"
|
||||
|
@ -263,13 +263,13 @@ async def test_run_select_service_optimistic_with_command_template(
|
|||
],
|
||||
)
|
||||
async def test_run_select_service(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that set_value service works in non optimistic mode."""
|
||||
cmd_topic = "test/select/set"
|
||||
state_topic = "test/select"
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, state_topic, "beer")
|
||||
state = hass.states.get("select.test_select")
|
||||
|
@ -303,13 +303,13 @@ async def test_run_select_service(
|
|||
],
|
||||
)
|
||||
async def test_run_select_service_with_command_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that set_value service works in non optimistic mode and with a command_template."""
|
||||
cmd_topic = "test/select/set"
|
||||
state_topic = "test/select"
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, state_topic, "beer")
|
||||
state = hass.states.get("select.test_select")
|
||||
|
@ -328,58 +328,58 @@ async def test_run_select_service_with_command_template(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN
|
||||
hass, mqtt_mock_entry, select.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
select.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_SELECT_ATTRIBUTES_BLOCKED,
|
||||
|
@ -387,23 +387,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
select.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -412,13 +412,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
select.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -427,13 +427,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
select.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -466,27 +466,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one select per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, select.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_select(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered select."""
|
||||
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][select.DOMAIN])
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, select.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_select(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered select."""
|
||||
|
@ -504,13 +504,13 @@ async def test_discovery_update_select(
|
|||
}
|
||||
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, select.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_select(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered select."""
|
||||
|
@ -520,7 +520,7 @@ async def test_discovery_update_unchanged_select(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
select.DOMAIN,
|
||||
data1,
|
||||
|
@ -531,7 +531,7 @@ async def test_discovery_update_unchanged_select(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -539,71 +539,71 @@ async def test_discovery_broken(
|
|||
data2 = '{ "name": "Milk", "state_topic": "test-topic", "command_topic": "test-topic", "options": ["milk", "beer"]}'
|
||||
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, select.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, select.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT select device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT select device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, select.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
select.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
select.SERVICE_SELECT_OPTION,
|
||||
|
@ -638,11 +638,11 @@ def _test_options_attributes_options_config(
|
|||
)
|
||||
async def test_options_attributes(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
options: list[str],
|
||||
) -> None:
|
||||
"""Test options attribute."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("select.test_select")
|
||||
assert state.attributes.get(ATTR_OPTIONS) == options
|
||||
|
@ -666,10 +666,10 @@ async def test_options_attributes(
|
|||
async def test_mqtt_payload_not_an_option_warning(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test warning for MQTT payload which is not a valid option."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "test/select_stat", "öl")
|
||||
|
||||
|
@ -695,7 +695,7 @@ async def test_mqtt_payload_not_an_option_warning(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -710,7 +710,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -741,7 +741,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -752,7 +752,7 @@ async def test_encoding_subscribable_topics(
|
|||
config["options"] = ["milk", "beer"]
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
select.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -764,31 +764,31 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = select.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = select.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
||||
|
||||
async def test_persistent_state_after_reconfig(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test of the state is persistent after reconfiguring the select options."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
discovery_data = '{ "name": "Milk", "state_topic": "test-topic", "command_topic": "test-topic", "options": ["milk", "beer"]}'
|
||||
await help_test_discovery_setup(hass, SELECT_DOMAIN, discovery_data, "milk")
|
||||
|
||||
|
|
|
@ -99,10 +99,10 @@ def sensor_platform_only():
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_value_via_mqtt_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic", "100.22")
|
||||
state = hass.states.get("sensor.test")
|
||||
|
@ -217,7 +217,7 @@ async def test_setting_sensor_value_via_mqtt_message(
|
|||
)
|
||||
async def test_setting_sensor_native_value_handling_via_mqtt_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
device_class: sensor.SensorDeviceClass | None,
|
||||
native_value: str,
|
||||
|
@ -225,7 +225,7 @@ async def test_setting_sensor_native_value_handling_via_mqtt_message(
|
|||
log: bool,
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic", native_value)
|
||||
state = hass.states.get("sensor.test")
|
||||
|
@ -253,11 +253,11 @@ async def test_setting_sensor_native_value_handling_via_mqtt_message(
|
|||
)
|
||||
async def test_setting_numeric_sensor_native_value_handling_via_mqtt_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test the setting of a numeric sensor value via MQTT."""
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# float value
|
||||
async_fire_mqtt_message(hass, "test-topic", '{ "power": 45.3, "current": 5.24 }')
|
||||
|
@ -308,10 +308,10 @@ async def test_setting_numeric_sensor_native_value_handling_via_mqtt_message(
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_value_expires_availability_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the expiration of the value."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("sensor.test")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
@ -342,10 +342,10 @@ async def test_setting_sensor_value_expires_availability_topic(
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_value_expires(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the expiration of the value."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# State should be unavailable since expire_after is defined and > 0
|
||||
state = hass.states.get("sensor.test")
|
||||
|
@ -420,10 +420,10 @@ async def expires_helper(hass: HomeAssistant) -> None:
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_value_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT with JSON payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic", '{ "val": "100" }')
|
||||
state = hass.states.get("sensor.test")
|
||||
|
@ -452,10 +452,10 @@ async def test_setting_sensor_value_via_mqtt_json_message(
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_value_via_mqtt_json_message_and_default_current_state(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT with fall back to current state."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "test-topic", '{ "val": "valcontent", "par": "parcontent" }'
|
||||
|
@ -488,11 +488,11 @@ async def test_setting_sensor_value_via_mqtt_json_message_and_default_current_st
|
|||
)
|
||||
async def test_setting_sensor_last_reset_via_mqtt_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the last_reset property via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "last-reset-topic", "2020-01-02 08:11:00")
|
||||
state = hass.states.get("sensor.test")
|
||||
|
@ -525,10 +525,10 @@ async def test_setting_sensor_bad_last_reset_via_mqtt_message(
|
|||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
datestring,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test the setting of the last_reset property via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "last-reset-topic", datestring)
|
||||
state = hass.states.get("sensor.test")
|
||||
|
@ -553,10 +553,10 @@ async def test_setting_sensor_bad_last_reset_via_mqtt_message(
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_empty_last_reset_via_mqtt_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the last_reset property via MQTT."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "last-reset-topic", "")
|
||||
state = hass.states.get("sensor.test")
|
||||
|
@ -581,10 +581,10 @@ async def test_setting_sensor_empty_last_reset_via_mqtt_message(
|
|||
],
|
||||
)
|
||||
async def test_setting_sensor_last_reset_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT with JSON payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass, "last-reset-topic", '{ "last_reset": "2020-01-02 08:11:00" }'
|
||||
|
@ -625,12 +625,12 @@ async def test_setting_sensor_last_reset_via_mqtt_json_message(
|
|||
)
|
||||
async def test_setting_sensor_last_reset_via_mqtt_json_message_2(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the setting of the value via MQTT with JSON payload."""
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
|
@ -662,10 +662,10 @@ async def test_setting_sensor_last_reset_via_mqtt_json_message_2(
|
|||
],
|
||||
)
|
||||
async def test_force_update_disabled(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test force update option."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
events: list[Event] = []
|
||||
|
||||
|
@ -700,10 +700,10 @@ async def test_force_update_disabled(
|
|||
],
|
||||
)
|
||||
async def test_force_update_enabled(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test force update option."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
events: list[Event] = []
|
||||
|
||||
|
@ -724,57 +724,57 @@ async def test_force_update_enabled(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_list_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_list_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_list_payload_all(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_list_payload_all(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_list_payload_any(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_list_payload_any(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -791,20 +791,20 @@ async def test_default_availability_list_single(
|
|||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_availability(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability discovery update."""
|
||||
await help_test_discovery_update_availability(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -824,12 +824,12 @@ async def test_discovery_update_availability(
|
|||
)
|
||||
async def test_invalid_device_class(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test device_class option with invalid value."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: expected SensorDeviceClass or one of" in caplog.text
|
||||
)
|
||||
|
@ -858,10 +858,10 @@ async def test_invalid_device_class(
|
|||
],
|
||||
)
|
||||
async def test_valid_device_class(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device_class option with valid values."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("sensor.test_1")
|
||||
assert state.attributes["device_class"] == "temperature"
|
||||
|
@ -887,12 +887,12 @@ async def test_valid_device_class(
|
|||
)
|
||||
async def test_invalid_state_class(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test state_class option with invalid value."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
assert (
|
||||
"Invalid config for [mqtt]: expected SensorStateClass or one of" in caplog.text
|
||||
)
|
||||
|
@ -921,10 +921,10 @@ async def test_invalid_state_class(
|
|||
],
|
||||
)
|
||||
async def test_valid_state_class(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test state_class option with valid values."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("sensor.test_1")
|
||||
assert state.attributes["state_class"] == "measurement"
|
||||
|
@ -935,21 +935,21 @@ async def test_valid_state_class(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
MQTT_SENSOR_ATTRIBUTES_BLOCKED,
|
||||
|
@ -957,23 +957,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -982,13 +982,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -997,13 +997,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
sensor.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -1032,27 +1032,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one sensor per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, sensor.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_sensor(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered sensor."""
|
||||
data = '{ "name": "test", "state_topic": "test_topic" }'
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, sensor.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, sensor.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_sensor_topic_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered sensor."""
|
||||
|
@ -1077,7 +1077,7 @@ async def test_discovery_update_sensor_topic_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
sensor.DOMAIN,
|
||||
config1,
|
||||
|
@ -1089,7 +1089,7 @@ async def test_discovery_update_sensor_topic_template(
|
|||
|
||||
async def test_discovery_update_sensor_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered sensor."""
|
||||
|
@ -1112,7 +1112,7 @@ async def test_discovery_update_sensor_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
sensor.DOMAIN,
|
||||
config1,
|
||||
|
@ -1124,7 +1124,7 @@ async def test_discovery_update_sensor_template(
|
|||
|
||||
async def test_discovery_update_unchanged_sensor(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered sensor."""
|
||||
|
@ -1134,7 +1134,7 @@ async def test_discovery_update_unchanged_sensor(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
sensor.DOMAIN,
|
||||
data1,
|
||||
|
@ -1145,76 +1145,76 @@ async def test_discovery_update_unchanged_sensor(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "name": "Beer", "state_topic": "test_topic#" }'
|
||||
data2 = '{ "name": "Milk", "state_topic": "test_topic" }'
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, sensor.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, sensor.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT sensor device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT sensor device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_hub(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT sensor device registry integration."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
registry = dr.async_get(hass)
|
||||
hub = registry.async_get_or_create(
|
||||
config_entry_id="123",
|
||||
|
@ -1241,66 +1241,66 @@ async def test_entity_device_info_with_hub(
|
|||
|
||||
|
||||
async def test_entity_debug_info(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT sensor debug info."""
|
||||
await help_test_entity_debug_info(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_max_messages(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT sensor debug info."""
|
||||
await help_test_entity_debug_info_max_messages(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG, None
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG, None
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT sensor debug info."""
|
||||
await help_test_entity_debug_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_update_entity_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT sensor debug info."""
|
||||
await help_test_entity_debug_info_update_entity_id(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_disabled_by_default(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test entity disabled by default."""
|
||||
await help_test_entity_disabled_by_default(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_entity_category(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test entity category."""
|
||||
await help_test_entity_category(
|
||||
hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, sensor.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -1325,10 +1325,10 @@ async def test_entity_category(
|
|||
],
|
||||
)
|
||||
async def test_value_template_with_entity_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the access to attributes in value_template via the entity_id."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "test-topic", "100")
|
||||
state = hass.states.get("sensor.test")
|
||||
|
@ -1373,7 +1373,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_cleanup_triggers_and_restoring_state(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
tmp_path: Path,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
|
@ -1382,7 +1382,7 @@ async def test_cleanup_triggers_and_restoring_state(
|
|||
"""Test cleanup old triggers at reloading and restoring the state."""
|
||||
freezer.move_to("2022-02-02 12:01:00+01:00")
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
async_fire_mqtt_message(hass, "test-topic1", "100")
|
||||
state = hass.states.get("sensor.test1")
|
||||
assert state.state == "38" # 100 °F -> 38 °C
|
||||
|
@ -1429,7 +1429,7 @@ async def test_cleanup_triggers_and_restoring_state(
|
|||
)
|
||||
async def test_skip_restoring_state_with_over_due_expire_trigger(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test restoring a state with over due expire timer."""
|
||||
|
@ -1444,7 +1444,7 @@ async def test_skip_restoring_state_with_over_due_expire_trigger(
|
|||
fake_extra_data = MagicMock()
|
||||
mock_restore_cache_with_extra_data(hass, ((fake_state, fake_extra_data),))
|
||||
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
state = hass.states.get("sensor.test3")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
@ -1458,7 +1458,7 @@ async def test_skip_restoring_state_with_over_due_expire_trigger(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -1467,7 +1467,7 @@ async def test_encoding_subscribable_topics(
|
|||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
sensor.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][sensor.DOMAIN],
|
||||
topic,
|
||||
|
@ -1480,21 +1480,21 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = sensor.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = sensor.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -103,10 +103,10 @@ async def async_turn_off(
|
|||
],
|
||||
)
|
||||
async def test_controlling_state_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the controlling state via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("siren.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -140,11 +140,11 @@ async def test_controlling_state_via_topic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands in optimistic mode."""
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("siren.test")
|
||||
assert state.state == STATE_OFF
|
||||
|
@ -187,11 +187,11 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
)
|
||||
async def test_controlling_state_via_topic_and_json_message(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("siren.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -230,11 +230,11 @@ async def test_controlling_state_via_topic_and_json_message(
|
|||
)
|
||||
async def test_controlling_state_and_attributes_with_json_message_without_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message without a value template."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("siren.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -324,10 +324,10 @@ async def test_controlling_state_and_attributes_with_json_message_without_templa
|
|||
],
|
||||
)
|
||||
async def test_filtering_not_supported_attributes_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting attributes with support flags optimistic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state1 = hass.states.get("siren.test1")
|
||||
assert state1.state == STATE_OFF
|
||||
|
@ -422,10 +422,10 @@ async def test_filtering_not_supported_attributes_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_filtering_not_supported_attributes_via_state(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setting attributes with support flags via state."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state1 = hass.states.get("siren.test1")
|
||||
assert state1.state == STATE_UNKNOWN
|
||||
|
@ -479,26 +479,26 @@ async def test_filtering_not_supported_attributes_via_state(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN
|
||||
hass, mqtt_mock_entry, siren.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
config = {
|
||||
|
@ -514,7 +514,7 @@ async def test_default_availability_payload(
|
|||
}
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
siren.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -524,7 +524,7 @@ async def test_default_availability_payload(
|
|||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
config = {
|
||||
|
@ -541,7 +541,7 @@ async def test_custom_availability_payload(
|
|||
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
siren.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -569,10 +569,10 @@ async def test_custom_availability_payload(
|
|||
],
|
||||
)
|
||||
async def test_custom_state_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the state payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("siren.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -590,41 +590,41 @@ async def test_custom_state_payload(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG, {}
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG, {}
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
siren.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -633,13 +633,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
siren.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -648,13 +648,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
siren.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -685,15 +685,15 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one siren per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, siren.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_siren(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered siren."""
|
||||
|
@ -702,14 +702,12 @@ async def test_discovery_removal_siren(
|
|||
' "state_topic": "test_topic",'
|
||||
' "command_topic": "test_topic" }'
|
||||
)
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, siren.DOMAIN, data
|
||||
)
|
||||
await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, siren.DOMAIN, data)
|
||||
|
||||
|
||||
async def test_discovery_update_siren_topic_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered siren."""
|
||||
|
@ -736,7 +734,7 @@ async def test_discovery_update_siren_topic_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
siren.DOMAIN,
|
||||
config1,
|
||||
|
@ -748,7 +746,7 @@ async def test_discovery_update_siren_topic_template(
|
|||
|
||||
async def test_discovery_update_siren_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered siren."""
|
||||
|
@ -773,7 +771,7 @@ async def test_discovery_update_siren_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
siren.DOMAIN,
|
||||
config1,
|
||||
|
@ -809,10 +807,10 @@ async def test_discovery_update_siren_template(
|
|||
)
|
||||
async def test_command_templates(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test siren with command templates optimistic."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state1 = hass.states.get("siren.beer")
|
||||
assert state1.state == STATE_OFF
|
||||
|
@ -875,7 +873,7 @@ async def test_command_templates(
|
|||
|
||||
async def test_discovery_update_unchanged_siren(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered siren."""
|
||||
|
@ -890,7 +888,7 @@ async def test_discovery_update_unchanged_siren(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
siren.DOMAIN,
|
||||
data1,
|
||||
|
@ -901,7 +899,7 @@ async def test_discovery_update_unchanged_siren(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -912,71 +910,71 @@ async def test_discovery_broken(
|
|||
' "command_topic": "test_topic" }'
|
||||
)
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, siren.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, siren.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT siren device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT siren device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
siren.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
siren.SERVICE_TURN_ON,
|
||||
|
@ -1005,7 +1003,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -1020,7 +1018,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -1050,7 +1048,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -1059,7 +1057,7 @@ async def test_encoding_subscribable_topics(
|
|||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
siren.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN],
|
||||
topic,
|
||||
|
@ -1071,21 +1069,21 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = siren.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = siren.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -105,10 +105,10 @@ def vacuum_platform_only():
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_default_supported_features(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that the correct supported features."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
entity = hass.states.get("vacuum.mqtttest")
|
||||
entity_features = entity.attributes.get(mqttvacuum.CONF_SUPPORTED_FEATURES, 0)
|
||||
assert sorted(services_to_strings(entity_features, SERVICE_TO_STRING)) == sorted(
|
||||
|
@ -118,10 +118,10 @@ async def test_default_supported_features(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
|
||||
async def test_all_commands(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test simple commands send to the vacuum."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True
|
||||
|
@ -201,10 +201,10 @@ async def test_all_commands(
|
|||
],
|
||||
)
|
||||
async def test_commands_without_supported_features(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test commands which are not supported by the vacuum."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True
|
||||
|
@ -254,10 +254,10 @@ async def test_commands_without_supported_features(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
|
||||
async def test_status(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
state = hass.states.get("vacuum.mqtttest")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
|
@ -310,10 +310,10 @@ async def test_status(
|
|||
],
|
||||
)
|
||||
async def test_no_fan_vacuum(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test status updates from the vacuum when fan is not supported."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
message = """{
|
||||
"battery_level": 54,
|
||||
|
@ -357,10 +357,10 @@ async def test_no_fan_vacuum(
|
|||
@pytest.mark.parametrize("hass_config", [CONFIG_ALL_SERVICES])
|
||||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_status_invalid_json(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test to make sure nothing breaks if the vacuum sends bad JSON."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}')
|
||||
state = hass.states.get("vacuum.mqtttest")
|
||||
|
@ -369,58 +369,58 @@ async def test_status_invalid_json(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG_2])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
MQTT_VACUUM_ATTRIBUTES_BLOCKED,
|
||||
|
@ -428,23 +428,23 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
|
|||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
|
@ -453,13 +453,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
|
@ -468,13 +468,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
|
@ -505,40 +505,40 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one vacuum per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, vacuum.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_vacuum(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered vacuum."""
|
||||
data = '{ "schema": "state", "name": "test", "command_topic": "test_topic"}'
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_vacuum(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered vacuum."""
|
||||
config1 = {"schema": "state", "name": "Beer", "command_topic": "test_topic"}
|
||||
config2 = {"schema": "state", "name": "Milk", "command_topic": "test_topic"}
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_vacuum(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered vacuum."""
|
||||
|
@ -548,7 +548,7 @@ async def test_discovery_update_unchanged_vacuum(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
vacuum.DOMAIN,
|
||||
data1,
|
||||
|
@ -559,78 +559,78 @@ async def test_discovery_update_unchanged_vacuum(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
data1 = '{ "schema": "state", "name": "Beer", "command_topic": "test_topic#"}'
|
||||
data2 = '{ "schema": "state", "name": "Milk", "command_topic": "test_topic"}'
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, vacuum.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT vacuum device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT vacuum device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
hass, mqtt_mock_entry, vacuum.DOMAIN, DEFAULT_CONFIG_2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG_2,
|
||||
vacuum.SERVICE_START,
|
||||
|
@ -681,7 +681,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -707,7 +707,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -748,7 +748,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -757,7 +757,7 @@ async def test_encoding_subscribable_topics(
|
|||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
vacuum.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][vacuum.DOMAIN],
|
||||
topic,
|
||||
|
@ -770,9 +770,9 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = vacuum.DOMAIN
|
||||
assert hass.states.get(f"{platform}.mqtttest")
|
||||
|
|
|
@ -23,11 +23,11 @@ def no_platforms():
|
|||
|
||||
async def test_subscribe_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test subscription to topics."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
calls1 = []
|
||||
|
||||
@callback
|
||||
|
@ -76,11 +76,11 @@ async def test_subscribe_topics(
|
|||
|
||||
async def test_modify_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test modification of topics."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
calls1 = []
|
||||
|
||||
@callback
|
||||
|
@ -143,11 +143,11 @@ async def test_modify_topics(
|
|||
|
||||
async def test_qos_encoding_default(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test default qos and encoding."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
@callback
|
||||
def msg_callback(*args):
|
||||
|
@ -165,11 +165,11 @@ async def test_qos_encoding_default(
|
|||
|
||||
async def test_qos_encoding_custom(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test custom qos and encoding."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
@callback
|
||||
def msg_callback(*args):
|
||||
|
@ -194,11 +194,11 @@ async def test_qos_encoding_custom(
|
|||
|
||||
async def test_no_change(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test subscription to topics without change."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
calls = []
|
||||
|
||||
|
|
|
@ -79,10 +79,10 @@ def switch_platform_only():
|
|||
],
|
||||
)
|
||||
async def test_controlling_state_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the controlling state via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("switch.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -122,13 +122,13 @@ async def test_controlling_state_via_topic(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands in optimistic mode."""
|
||||
fake_state = State("switch.test", "on")
|
||||
mock_restore_cache(hass, (fake_state,))
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("switch.test")
|
||||
assert state.state == STATE_ON
|
||||
|
@ -166,10 +166,10 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_sending_inital_state_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the initial state in optimistic mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("switch.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -194,10 +194,10 @@ async def test_sending_inital_state_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_controlling_state_via_topic_and_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the controlling state via topic and JSON message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("switch.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -220,26 +220,26 @@ async def test_controlling_state_via_topic_and_json_message(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN
|
||||
hass, mqtt_mock_entry, switch.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
config = {
|
||||
|
@ -255,7 +255,7 @@ async def test_default_availability_payload(
|
|||
}
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
switch.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -265,7 +265,7 @@ async def test_default_availability_payload(
|
|||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
config = {
|
||||
|
@ -282,7 +282,7 @@ async def test_custom_availability_payload(
|
|||
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
switch.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -310,10 +310,10 @@ async def test_custom_availability_payload(
|
|||
],
|
||||
)
|
||||
async def test_custom_state_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the state payload."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("switch.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -331,41 +331,41 @@ async def test_custom_state_payload(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG, {}
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG, {}
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
switch.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -374,13 +374,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
switch.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -389,13 +389,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
switch.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -426,15 +426,15 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one switch per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, switch.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_switch(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered switch."""
|
||||
|
@ -444,13 +444,13 @@ async def test_discovery_removal_switch(
|
|||
' "command_topic": "test_topic" }'
|
||||
)
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, switch.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, switch.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_switch_topic_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered switch."""
|
||||
|
@ -477,7 +477,7 @@ async def test_discovery_update_switch_topic_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
switch.DOMAIN,
|
||||
config1,
|
||||
|
@ -489,7 +489,7 @@ async def test_discovery_update_switch_topic_template(
|
|||
|
||||
async def test_discovery_update_switch_template(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered switch."""
|
||||
|
@ -514,7 +514,7 @@ async def test_discovery_update_switch_template(
|
|||
|
||||
await help_test_discovery_update(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
switch.DOMAIN,
|
||||
config1,
|
||||
|
@ -526,7 +526,7 @@ async def test_discovery_update_switch_template(
|
|||
|
||||
async def test_discovery_update_unchanged_switch(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered switch."""
|
||||
|
@ -541,7 +541,7 @@ async def test_discovery_update_unchanged_switch(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
switch.DOMAIN,
|
||||
data1,
|
||||
|
@ -552,7 +552,7 @@ async def test_discovery_update_unchanged_switch(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -563,71 +563,71 @@ async def test_discovery_broken(
|
|||
' "command_topic": "test_topic" }'
|
||||
)
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, switch.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, switch.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT switch device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT switch device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, switch.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
switch.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
switch.SERVICE_TURN_ON,
|
||||
|
@ -655,7 +655,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -669,7 +669,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -699,7 +699,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -708,7 +708,7 @@ async def test_encoding_subscribable_topics(
|
|||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
switch.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN],
|
||||
topic,
|
||||
|
@ -720,21 +720,21 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = switch.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = switch.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -64,11 +64,11 @@ def tag_mock():
|
|||
async def test_discover_bad_tag(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test bad discovery message."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
|
||||
|
||||
# Test sending bad data
|
||||
|
@ -91,11 +91,11 @@ async def test_discover_bad_tag(
|
|||
async def test_if_fires_on_mqtt_message_with_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning, with device."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
|
||||
|
@ -111,11 +111,11 @@ async def test_if_fires_on_mqtt_message_with_device(
|
|||
async def test_if_fires_on_mqtt_message_without_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning, without device."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
|
||||
|
@ -130,11 +130,11 @@ async def test_if_fires_on_mqtt_message_without_device(
|
|||
async def test_if_fires_on_mqtt_message_with_template(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning, with device."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = copy.deepcopy(DEFAULT_CONFIG_JSON)
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
|
||||
|
@ -149,11 +149,11 @@ async def test_if_fires_on_mqtt_message_with_template(
|
|||
|
||||
async def test_strip_tag_id(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test strip whitespace from tag_id."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
|
||||
|
@ -168,11 +168,11 @@ async def test_strip_tag_id(
|
|||
async def test_if_fires_on_mqtt_message_after_update_with_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning after update."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
|
||||
config1["some_future_option_1"] = "future_option_1"
|
||||
config2 = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
|
||||
|
@ -217,11 +217,11 @@ async def test_if_fires_on_mqtt_message_after_update_with_device(
|
|||
|
||||
async def test_if_fires_on_mqtt_message_after_update_without_device(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning after update."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config2 = copy.deepcopy(DEFAULT_CONFIG)
|
||||
config2["topic"] = "foobar/tag_scanned2"
|
||||
|
@ -264,11 +264,11 @@ async def test_if_fires_on_mqtt_message_after_update_without_device(
|
|||
async def test_if_fires_on_mqtt_message_after_update_with_template(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning after update."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = copy.deepcopy(DEFAULT_CONFIG_JSON)
|
||||
config2 = copy.deepcopy(DEFAULT_CONFIG_JSON)
|
||||
config2["value_template"] = "{{ value_json.RDM6300.UID }}"
|
||||
|
@ -313,10 +313,10 @@ async def test_if_fires_on_mqtt_message_after_update_with_template(
|
|||
async def test_no_resubscribe_same_topic(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test subscription to topics without change."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
config = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
|
||||
|
@ -332,11 +332,11 @@ async def test_no_resubscribe_same_topic(
|
|||
async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_with_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning after removal."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
|
||||
|
@ -368,11 +368,11 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_with_device(
|
|||
|
||||
async def test_not_fires_on_mqtt_message_after_remove_by_mqtt_without_device(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning not firing after removal."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = copy.deepcopy(DEFAULT_CONFIG)
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/tag/bla1/config", json.dumps(config))
|
||||
|
@ -405,13 +405,13 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
|||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test tag scanning after removal."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
await hass.async_block_till_done()
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
config = copy.deepcopy(DEFAULT_CONFIG_DEVICE)
|
||||
|
@ -445,10 +445,10 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
|
|||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT device registry integration."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
registry = dr.async_get(hass)
|
||||
|
||||
data = json.dumps(
|
||||
|
@ -480,10 +480,10 @@ async def test_entity_device_info_with_connection(
|
|||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT device registry integration."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
registry = dr.async_get(hass)
|
||||
|
||||
data = json.dumps(
|
||||
|
@ -513,10 +513,10 @@ async def test_entity_device_info_with_identifier(
|
|||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
registry = dr.async_get(hass)
|
||||
|
||||
config = {
|
||||
|
@ -553,12 +553,12 @@ async def test_cleanup_tag(
|
|||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test tag discovery topic is cleaned when device is removed from registry."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
mqtt_entry = hass.config_entries.async_entries("mqtt")[0]
|
||||
|
@ -636,10 +636,10 @@ async def test_cleanup_tag(
|
|||
async def test_cleanup_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test removal from device registry when tag is removed."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config = {
|
||||
"topic": "test-topic",
|
||||
"device": {"identifiers": ["helloworld"]},
|
||||
|
@ -664,11 +664,11 @@ async def test_cleanup_device(
|
|||
async def test_cleanup_device_several_tags(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test removal from device registry when the last tag is removed."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = {
|
||||
"topic": "test-topic1",
|
||||
"device": {"identifiers": ["helloworld"]},
|
||||
|
@ -712,13 +712,13 @@ async def test_cleanup_device_several_tags(
|
|||
async def test_cleanup_device_with_entity_and_trigger_1(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test removal from device registry for device with tag, entity and trigger.
|
||||
|
||||
Tag removed first, then trigger and entity.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = {
|
||||
"topic": "test-topic",
|
||||
"device": {"identifiers": ["helloworld"]},
|
||||
|
@ -779,13 +779,13 @@ async def test_cleanup_device_with_entity_and_trigger_1(
|
|||
async def test_cleanup_device_with_entity2(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test removal from device registry for device with tag, entity and trigger.
|
||||
|
||||
Trigger and entity removed first, then tag.
|
||||
"""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = {
|
||||
"topic": "test-topic",
|
||||
"device": {"identifiers": ["helloworld"]},
|
||||
|
@ -846,11 +846,11 @@ async def test_cleanup_device_with_entity2(
|
|||
@pytest.mark.xfail(raises=MultipleInvalid)
|
||||
async def test_update_with_bad_config_not_breaks_discovery(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
tag_mock,
|
||||
) -> None:
|
||||
"""Test a bad update does not break discovery."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
config1 = {
|
||||
"topic": "test-topic",
|
||||
"device": {"identifiers": ["helloworld"]},
|
||||
|
|
|
@ -87,10 +87,10 @@ async def async_set_value(
|
|||
],
|
||||
)
|
||||
async def test_controlling_state_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the controlling state via topic."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("text.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -133,11 +133,11 @@ async def test_controlling_state_via_topic(
|
|||
)
|
||||
async def test_controlling_validation_state_via_topic(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the validation of a received state."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("text.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -203,11 +203,11 @@ async def test_controlling_validation_state_via_topic(
|
|||
],
|
||||
)
|
||||
async def test_attribute_validation_max_greater_then_min(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the validation of min and max configuration attributes."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -226,11 +226,11 @@ async def test_attribute_validation_max_greater_then_min(
|
|||
],
|
||||
)
|
||||
async def test_attribute_validation_max_not_greater_then_max_state_length(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the max value of of max configuration attribute."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -248,10 +248,10 @@ async def test_attribute_validation_max_not_greater_then_max_state_length(
|
|||
],
|
||||
)
|
||||
async def test_sending_mqtt_commands_and_optimistic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the sending MQTT commands in optimistic mode."""
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("text.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -294,10 +294,10 @@ async def test_sending_mqtt_commands_and_optimistic(
|
|||
],
|
||||
)
|
||||
async def test_set_text_validation(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the initial state in optimistic mode."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
state = hass.states.get("text.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
@ -322,26 +322,26 @@ async def test_set_text_validation(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN
|
||||
hass, mqtt_mock_entry, text.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
config = {
|
||||
|
@ -355,7 +355,7 @@ async def test_default_availability_payload(
|
|||
}
|
||||
await help_test_default_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
text.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -365,7 +365,7 @@ async def test_default_availability_payload(
|
|||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
config = {
|
||||
|
@ -380,7 +380,7 @@ async def test_custom_availability_payload(
|
|||
|
||||
await help_test_custom_availability_payload(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
text.DOMAIN,
|
||||
config,
|
||||
True,
|
||||
|
@ -390,41 +390,41 @@ async def test_custom_availability_payload(
|
|||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_blocked_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG, {}
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG, {}
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
text.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -433,13 +433,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
text.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -448,13 +448,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
text.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -485,15 +485,15 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one text per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, text.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_text(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered text entity."""
|
||||
|
@ -502,14 +502,12 @@ async def test_discovery_removal_text(
|
|||
' "state_topic": "test_topic",'
|
||||
' "command_topic": "test_topic" }'
|
||||
)
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, data
|
||||
)
|
||||
await help_test_discovery_removal(hass, mqtt_mock_entry, caplog, text.DOMAIN, data)
|
||||
|
||||
|
||||
async def test_discovery_text_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered text entity."""
|
||||
|
@ -525,13 +523,13 @@ async def test_discovery_text_update(
|
|||
}
|
||||
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, text.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered update."""
|
||||
|
@ -541,7 +539,7 @@ async def test_discovery_update_unchanged_update(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
text.DOMAIN,
|
||||
data1,
|
||||
|
@ -551,20 +549,20 @@ async def test_discovery_update_unchanged_update(
|
|||
|
||||
async def test_discovery_update_text(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered text entity."""
|
||||
config1 = {"name": "Beer", "command_topic": "cmd-topic1"}
|
||||
config2 = {"name": "Milk", "command_topic": "cmd-topic2"}
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, text.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_climate(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered text entity."""
|
||||
|
@ -574,7 +572,7 @@ async def test_discovery_update_unchanged_climate(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
text.DOMAIN,
|
||||
data1,
|
||||
|
@ -585,7 +583,7 @@ async def test_discovery_update_unchanged_climate(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -596,70 +594,70 @@ async def test_discovery_broken(
|
|||
' "command_topic": "test_topic" }'
|
||||
)
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, text.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, text.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT text device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT text device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_debug_info_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT debug info."""
|
||||
await help_test_entity_debug_info_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG, None
|
||||
hass, mqtt_mock_entry, text.DOMAIN, DEFAULT_CONFIG, None
|
||||
)
|
||||
|
||||
|
||||
|
@ -677,7 +675,7 @@ async def test_entity_debug_info_message(
|
|||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service: str,
|
||||
topic: str,
|
||||
|
@ -691,7 +689,7 @@ async def test_publishing_with_custom_encoding(
|
|||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
|
@ -721,7 +719,7 @@ async def test_reloadable(
|
|||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
|
@ -730,7 +728,7 @@ async def test_encoding_subscribable_topics(
|
|||
"""Test handling of incoming encoded payload."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
text.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][text.DOMAIN],
|
||||
topic,
|
||||
|
@ -742,21 +740,21 @@ async def test_encoding_subscribable_topics(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = text.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = text.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
|
|
@ -26,10 +26,10 @@ def no_platforms():
|
|||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def setup_comp(hass: HomeAssistant, mqtt_mock_entry_no_yaml_config):
|
||||
async def setup_comp(hass: HomeAssistant, mqtt_mock_entry):
|
||||
"""Initialize components."""
|
||||
mock_component(hass, "group")
|
||||
return await mqtt_mock_entry_no_yaml_config()
|
||||
return await mqtt_mock_entry()
|
||||
|
||||
|
||||
async def test_if_fires_on_topic_match(hass: HomeAssistant, calls) -> None:
|
||||
|
|
|
@ -81,12 +81,12 @@ def update_platform_only():
|
|||
],
|
||||
)
|
||||
async def test_run_update_setup(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload."""
|
||||
installed_version_topic = "test/installed-version"
|
||||
latest_version_topic = "test/latest-version"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, installed_version_topic, "1.9.0")
|
||||
async_fire_mqtt_message(hass, latest_version_topic, "1.9.0")
|
||||
|
@ -131,12 +131,12 @@ async def test_run_update_setup(
|
|||
],
|
||||
)
|
||||
async def test_run_update_setup_float(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload when the version is parsable as a number."""
|
||||
installed_version_topic = "test/installed-version"
|
||||
latest_version_topic = "test/latest-version"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, installed_version_topic, "1.9")
|
||||
async_fire_mqtt_message(hass, latest_version_topic, "1.9")
|
||||
|
@ -179,12 +179,12 @@ async def test_run_update_setup_float(
|
|||
],
|
||||
)
|
||||
async def test_value_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload with a template."""
|
||||
installed_version_topic = "test/installed-version"
|
||||
latest_version_topic = "test/latest-version"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, installed_version_topic, '{"installed":"1.9.0"}')
|
||||
async_fire_mqtt_message(hass, latest_version_topic, '{"latest":"1.9.0"}')
|
||||
|
@ -227,12 +227,12 @@ async def test_value_template(
|
|||
],
|
||||
)
|
||||
async def test_value_template_float(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that it fetches the given payload with a template when the version is parsable as a number."""
|
||||
installed_version_topic = "test/installed-version"
|
||||
latest_version_topic = "test/latest-version"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, installed_version_topic, '{"installed":"1.9"}')
|
||||
async_fire_mqtt_message(hass, latest_version_topic, '{"latest":"1.9"}')
|
||||
|
@ -272,11 +272,11 @@ async def test_value_template_float(
|
|||
],
|
||||
)
|
||||
async def test_empty_json_state_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test an empty JSON payload."""
|
||||
state_topic = "test/state-topic"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, state_topic, "{}")
|
||||
|
||||
|
@ -300,11 +300,11 @@ async def test_empty_json_state_message(
|
|||
],
|
||||
)
|
||||
async def test_json_state_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test whether it fetches data from a JSON payload."""
|
||||
state_topic = "test/state-topic"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(
|
||||
hass,
|
||||
|
@ -358,11 +358,11 @@ async def test_json_state_message(
|
|||
],
|
||||
)
|
||||
async def test_json_state_message_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test whether it fetches data from a JSON payload with template."""
|
||||
state_topic = "test/state-topic"
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, state_topic, '{"installed":"1.9.0","latest":"1.9.0"}')
|
||||
|
||||
|
@ -400,14 +400,14 @@ async def test_json_state_message_with_template(
|
|||
],
|
||||
)
|
||||
async def test_run_install_service(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that install service works."""
|
||||
installed_version_topic = "test/installed-version"
|
||||
latest_version_topic = "test/latest-version"
|
||||
command_topic = "test/install-command"
|
||||
|
||||
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
|
||||
mqtt_mock = await mqtt_mock_entry()
|
||||
|
||||
async_fire_mqtt_message(hass, installed_version_topic, "1.9.0")
|
||||
async_fire_mqtt_message(hass, latest_version_topic, "2.0.0")
|
||||
|
@ -429,69 +429,69 @@ async def test_run_install_service(
|
|||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_when_connection_lost(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability after MQTT disconnection."""
|
||||
await help_test_availability_when_connection_lost(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN
|
||||
hass, mqtt_mock_entry, update.DOMAIN
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_availability_without_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability without defined availability topic."""
|
||||
await help_test_availability_without_topic(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_default_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by default payload with defined topic."""
|
||||
await help_test_default_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_custom_availability_payload(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test availability by custom payload with defined topic."""
|
||||
await help_test_custom_availability_payload(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_setting_attribute_with_template(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
await help_test_setting_attribute_with_template(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
update.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -500,13 +500,13 @@ async def test_update_with_json_attrs_not_dict(
|
|||
|
||||
async def test_update_with_json_attrs_bad_json(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
await help_test_update_with_json_attrs_bad_json(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
update.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -515,13 +515,13 @@ async def test_update_with_json_attrs_bad_json(
|
|||
|
||||
async def test_discovery_update_attr(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
await help_test_discovery_update_attr(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
update.DOMAIN,
|
||||
DEFAULT_CONFIG,
|
||||
|
@ -552,27 +552,27 @@ async def test_discovery_update_attr(
|
|||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique id option only creates one update per unique_id."""
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry, update.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test removal of discovered update."""
|
||||
data = json.dumps(DEFAULT_CONFIG[mqtt.DOMAIN][update.DOMAIN])
|
||||
await help_test_discovery_removal(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, update.DOMAIN, data
|
||||
hass, mqtt_mock_entry, caplog, update.DOMAIN, data
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered update."""
|
||||
|
@ -588,13 +588,13 @@ async def test_discovery_update_update(
|
|||
}
|
||||
|
||||
await help_test_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, update.DOMAIN, config1, config2
|
||||
hass, mqtt_mock_entry, caplog, update.DOMAIN, config1, config2
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_unchanged_update(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test update of discovered update."""
|
||||
|
@ -604,7 +604,7 @@ async def test_discovery_update_unchanged_update(
|
|||
) as discovery_update:
|
||||
await help_test_discovery_update_unchanged(
|
||||
hass,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
mqtt_mock_entry,
|
||||
caplog,
|
||||
update.DOMAIN,
|
||||
data1,
|
||||
|
@ -615,7 +615,7 @@ async def test_discovery_update_unchanged_update(
|
|||
@pytest.mark.no_fail_on_log_exception
|
||||
async def test_discovery_broken(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test handling of bad discovery message."""
|
||||
|
@ -623,74 +623,74 @@ async def test_discovery_broken(
|
|||
data2 = '{ "name": "Milk", "state_topic": "installed-topic", "latest_version_topic": "latest-topic" }'
|
||||
|
||||
await help_test_discovery_broken(
|
||||
hass, mqtt_mock_entry_no_yaml_config, caplog, update.DOMAIN, data1, data2
|
||||
hass, mqtt_mock_entry, caplog, update.DOMAIN, data1, data2
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_connection(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT update device registry integration."""
|
||||
await help_test_entity_device_info_with_connection(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT update device registry integration."""
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry update."""
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_remove(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test device registry remove."""
|
||||
await help_test_entity_device_info_remove(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update_discovery_update(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT discovery update when entity_id is updated."""
|
||||
await help_test_entity_id_update_discovery_update(
|
||||
hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry, update.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
await mqtt_mock_entry()
|
||||
platform = update.DOMAIN
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
async def test_unload_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> None:
|
||||
"""Test unloading the config entry."""
|
||||
domain = update.DOMAIN
|
||||
config = DEFAULT_CONFIG
|
||||
await help_test_unload_config_entry_with_platform(
|
||||
hass, mqtt_mock_entry_no_yaml_config, domain, config
|
||||
hass, mqtt_mock_entry, domain, config
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -906,11 +906,11 @@ async def mqtt_mock(
|
|||
mock_hass_config: None,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_config_entry_data: dict[str, Any] | None,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
) -> AsyncGenerator[MqttMockHAClient, None]:
|
||||
"""Fixture to mock MQTT component."""
|
||||
with patch("homeassistant.components.mqtt.PLATFORMS", []):
|
||||
return await mqtt_mock_entry_no_yaml_config()
|
||||
return await mqtt_mock_entry()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
|
@ -1043,12 +1043,12 @@ def mock_hass_config_yaml(
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
async def mqtt_mock_entry_no_yaml_config(
|
||||
async def mqtt_mock_entry(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_config_entry_data: dict[str, Any] | None,
|
||||
) -> AsyncGenerator[MqttMockHAClientGenerator, None]:
|
||||
"""Set up an MQTT config entry without MQTT yaml config."""
|
||||
"""Set up an MQTT config entry."""
|
||||
|
||||
async def _async_setup_config_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
|
@ -1068,30 +1068,6 @@ async def mqtt_mock_entry_no_yaml_config(
|
|||
yield _setup_mqtt_entry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mqtt_mock_entry_with_yaml_config(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mqtt_config_entry_data: dict[str, Any] | None,
|
||||
) -> AsyncGenerator[MqttMockHAClientGenerator, None]:
|
||||
"""Set up an MQTT config entry with MQTT yaml config."""
|
||||
|
||||
async def _async_do_not_setup_config_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> bool:
|
||||
"""Do nothing."""
|
||||
return True
|
||||
|
||||
async def _setup_mqtt_entry() -> MqttMockHAClient:
|
||||
"""Set up the MQTT config entry."""
|
||||
return await mqtt_mock_entry(_async_do_not_setup_config_entry)
|
||||
|
||||
async with _mqtt_mock_entry(
|
||||
hass, mqtt_client_mock, mqtt_config_entry_data
|
||||
) as mqtt_mock_entry:
|
||||
yield _setup_mqtt_entry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_network() -> Generator[None, None, None]:
|
||||
"""Mock network."""
|
||||
|
|
Loading…
Add table
Reference in a new issue