mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 03:35:09 +02:00
Rename MQTT entry mock and cleanup (#91223)
Rename to mqtt_mock_entry and cleanup
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
Reference in New Issue
Block a user