Do async_setup_platform in background (#36244)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Paulus SchoutsenandJ. Nick Koston authored and GitHub committed 2020-05-31 22:18:30 -07:00
1 parent d488c779fc
commit 276f3afb00
161 files changed
+1184 -305

No files matched your search

@@ -107,6 +107,7 @@ async def test_update_state_via_state_topic(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@@ -132,6 +133,7 @@ async def test_ignore_update_state_if_unknown_via_state_topic(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
entity_id = "alarm_control_panel.test"
@@ -146,6 +148,7 @@ async def test_arm_home_publishes_mqtt(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
await common.async_alarm_arm_home(hass)
mqtt_mock.async_publish.assert_called_once_with(
@@ -175,6 +178,7 @@ async def test_arm_home_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG_CODE)
config[alarm_control_panel.DOMAIN]["code_arm_required"] = False
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_arm_home(hass)
mqtt_mock.async_publish.assert_called_once_with(
@@ -187,6 +191,7 @@ async def test_arm_away_publishes_mqtt(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
await common.async_alarm_arm_away(hass)
mqtt_mock.async_publish.assert_called_once_with(
@@ -216,6 +221,7 @@ async def test_arm_away_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG_CODE)
config[alarm_control_panel.DOMAIN]["code_arm_required"] = False
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_arm_away(hass)
mqtt_mock.async_publish.assert_called_once_with(
@@ -228,6 +234,7 @@ async def test_arm_night_publishes_mqtt(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
await common.async_alarm_arm_night(hass)
mqtt_mock.async_publish.assert_called_once_with(
@@ -257,6 +264,7 @@ async def test_arm_night_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG_CODE)
config[alarm_control_panel.DOMAIN]["code_arm_required"] = False
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_arm_night(hass)
mqtt_mock.async_publish.assert_called_once_with(
@@ -278,6 +286,7 @@ async def test_arm_custom_bypass_publishes_mqtt(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await common.async_alarm_arm_custom_bypass(hass)
mqtt_mock.async_publish.assert_called_once_with(
@@ -306,6 +315,7 @@ async def test_arm_custom_bypass_not_publishes_mqtt_with_invalid_code_when_req(
}
},
)
await hass.async_block_till_done()
call_count = mqtt_mock.async_publish.call_count
await common.async_alarm_arm_custom_bypass(hass, "abcd")
@@ -331,6 +341,7 @@ async def test_arm_custom_bypass_publishes_mqtt_when_code_not_req(hass, mqtt_moc
}
},
)
await hass.async_block_till_done()
await common.async_alarm_arm_custom_bypass(hass)
mqtt_mock.async_publish.assert_called_once_with(
@@ -343,6 +354,7 @@ async def test_disarm_publishes_mqtt(hass, mqtt_mock):
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN, DEFAULT_CONFIG,
)
await hass.async_block_till_done()
await common.async_alarm_disarm(hass)
mqtt_mock.async_publish.assert_called_once_with("alarm/command", "DISARM", 0, False)
@@ -359,6 +371,7 @@ async def test_disarm_publishes_mqtt_with_template(hass, mqtt_mock):
'{"action":"{{ action }}",' '"code":"{{ code }}"}'
)
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_disarm(hass, 1234)
mqtt_mock.async_publish.assert_called_once_with(
@@ -375,6 +388,7 @@ async def test_disarm_publishes_mqtt_when_code_not_req(hass, mqtt_mock):
config[alarm_control_panel.DOMAIN]["code"] = "1234"
config[alarm_control_panel.DOMAIN]["code_disarm_required"] = False
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config,)
await hass.async_block_till_done()
await common.async_alarm_disarm(hass)
mqtt_mock.async_publish.assert_called_once_with("alarm/command", "DISARM", 0, False)
@@ -414,6 +428,7 @@ async def test_update_state_via_state_topic_template(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("alarm_control_panel.test")
assert state.state == STATE_UNKNOWN
@@ -430,6 +445,7 @@ async def test_attributes_code_number(hass, mqtt_mock):
config[alarm_control_panel.DOMAIN]["code"] = CODE_NUMBER
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("alarm_control_panel.test")
assert (
@@ -444,6 +460,7 @@ async def test_attributes_code_text(hass, mqtt_mock):
config[alarm_control_panel.DOMAIN]["code"] = CODE_TEXT
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("alarm_control_panel.test")
assert (
@@ -71,6 +71,7 @@ async def test_setting_sensor_value_expires_availability_topic(hass, mqtt_mock,
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state.state == STATE_UNAVAILABLE
@@ -99,6 +100,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
}
},
)
await hass.async_block_till_done()
# State should be unavailable since expire_after is defined and > 0
state = hass.states.get("binary_sensor.test")
@@ -172,6 +174,7 @@ async def test_setting_sensor_value_via_mqtt_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
@@ -201,6 +204,7 @@ async def test_invalid_sensor_value_via_mqtt_message(hass, mqtt_mock, caplog):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
@@ -240,6 +244,7 @@ async def test_setting_sensor_value_via_mqtt_message_and_template(hass, mqtt_moc
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state.state == STATE_OFF
@@ -267,6 +272,7 @@ async def test_valid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state.attributes.get("device_class") == "motion"
@@ -286,6 +292,7 @@ async def test_invalid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.test")
assert state is None
@@ -327,6 +334,7 @@ async def test_force_update_disabled(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
@@ -362,6 +370,7 @@ async def test_force_update_enabled(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
@@ -398,6 +407,7 @@ async def test_off_delay(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
+1
View File
@@ -49,6 +49,7 @@ async def test_run_camera_setup(hass, aiohttp_client):
"camera",
{"camera": {"platform": "mqtt", "topic": topic, "name": "Test Camera"}},
)
await hass.async_block_till_done()
url = hass.states.get("camera.test_camera").attributes["entity_picture"]
+35
View File
@@ -72,6 +72,7 @@ DEFAULT_CONFIG = {
async def test_setup_params(hass, mqtt_mock):
"""Test the initial parameters."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21
@@ -85,6 +86,7 @@ async def test_setup_params(hass, mqtt_mock):
async def test_supported_features(hass, mqtt_mock):
"""Test the supported_features."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
support = (
@@ -102,6 +104,7 @@ async def test_supported_features(hass, mqtt_mock):
async def test_get_hvac_modes(hass, mqtt_mock):
"""Test that the operation list returns the correct modes."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
modes = state.attributes.get("hvac_modes")
@@ -121,6 +124,7 @@ async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
Also check the state.
"""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@@ -136,6 +140,7 @@ async def test_set_operation_bad_attr_and_state(hass, mqtt_mock, caplog):
async def test_set_operation(hass, mqtt_mock):
"""Test setting of new operation mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@@ -151,6 +156,7 @@ async def test_set_operation_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["mode_state_topic"] = "mode-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "unknown"
@@ -173,6 +179,7 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["power_command_topic"] = "power-command"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.state == "off"
@@ -196,6 +203,7 @@ async def test_set_operation_with_power_command(hass, mqtt_mock):
async def test_set_fan_mode_bad_attr(hass, mqtt_mock, caplog):
"""Test setting fan mode without required attribute."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low"
@@ -213,6 +221,7 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["fan_mode_state_topic"] = "fan-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") is None
@@ -233,6 +242,7 @@ async def test_set_fan_mode_pessimistic(hass, mqtt_mock):
async def test_set_fan_mode(hass, mqtt_mock):
"""Test setting of new fan mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("fan_mode") == "low"
@@ -245,6 +255,7 @@ async def test_set_fan_mode(hass, mqtt_mock):
async def test_set_swing_mode_bad_attr(hass, mqtt_mock, caplog):
"""Test setting swing mode without required attribute."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off"
@@ -262,6 +273,7 @@ async def test_set_swing_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["swing_mode_state_topic"] = "swing-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") is None
@@ -282,6 +294,7 @@ async def test_set_swing_pessimistic(hass, mqtt_mock):
async def test_set_swing(hass, mqtt_mock):
"""Test setting of new swing mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("swing_mode") == "off"
@@ -294,6 +307,7 @@ async def test_set_swing(hass, mqtt_mock):
async def test_set_target_temperature(hass, mqtt_mock):
"""Test setting the target temperature."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") == 21
@@ -326,6 +340,7 @@ async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["temperature_state_topic"] = "temperature-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("temperature") is None
@@ -346,6 +361,7 @@ async def test_set_target_temperature_pessimistic(hass, mqtt_mock):
async def test_set_target_temperature_low_high(hass, mqtt_mock):
"""Test setting the low/high target temperature."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, target_temp_low=20, target_temp_high=23, entity_id=ENTITY_CLIMATE
@@ -363,6 +379,7 @@ async def test_set_target_temperature_low_highpessimistic(hass, mqtt_mock):
config["climate"]["temperature_low_state_topic"] = "temperature-low-state"
config["climate"]["temperature_high_state_topic"] = "temperature-high-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("target_temp_low") is None
@@ -398,6 +415,7 @@ async def test_receive_mqtt_temperature(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["current_temperature_topic"] = "current_temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "current_temperature", "47")
state = hass.states.get(ENTITY_CLIMATE)
@@ -409,6 +427,7 @@ async def test_set_away_mode_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["away_mode_state_topic"] = "away-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@@ -437,6 +456,7 @@ async def test_set_away_mode(hass, mqtt_mock):
config["climate"]["payload_off"] = "AUS"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@@ -467,6 +487,7 @@ async def test_set_hvac_action(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["action_topic"] = "action"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("hvac_action") is None
@@ -481,6 +502,7 @@ async def test_set_hold_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["hold_state_topic"] = "hold-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("hold_mode") is None
@@ -501,6 +523,7 @@ async def test_set_hold_pessimistic(hass, mqtt_mock):
async def test_set_hold(hass, mqtt_mock):
"""Test setting the hold mode."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@@ -525,6 +548,7 @@ async def test_set_hold(hass, mqtt_mock):
async def test_set_preset_mode_twice(hass, mqtt_mock):
"""Test setting of the same mode twice only publishes once."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("preset_mode") is None
@@ -543,6 +567,7 @@ async def test_set_aux_pessimistic(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["aux_state_topic"] = "aux-state"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("aux_heat") == "off"
@@ -567,6 +592,7 @@ async def test_set_aux_pessimistic(hass, mqtt_mock):
async def test_set_aux(hass, mqtt_mock):
"""Test setting of the aux heating."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
assert state.attributes.get("aux_heat") == "off"
@@ -612,6 +638,7 @@ async def test_set_target_temperature_low_high_with_templates(hass, mqtt_mock, c
config["climate"]["temperature_high_state_template"] = "{{ value_json.temp_high }}"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
@@ -658,6 +685,7 @@ async def test_set_with_templates(hass, mqtt_mock, caplog):
config["climate"]["current_temperature_topic"] = "current-temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
# Operation Mode
state = hass.states.get(ENTITY_CLIMATE)
@@ -745,6 +773,7 @@ async def test_min_temp_custom(hass, mqtt_mock):
config["climate"]["min_temp"] = 26
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
min_temp = state.attributes.get("min_temp")
@@ -759,6 +788,7 @@ async def test_max_temp_custom(hass, mqtt_mock):
config["climate"]["max_temp"] = 60
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
max_temp = state.attributes.get("max_temp")
@@ -773,6 +803,7 @@ async def test_temp_step_custom(hass, mqtt_mock):
config["climate"]["temp_step"] = 0.01
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_CLIMATE)
temp_step = state.attributes.get("target_temp_step")
@@ -788,6 +819,7 @@ async def test_temperature_unit(hass, mqtt_mock):
config["climate"]["current_temperature_topic"] = "current_temperature"
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "current_temperature", "77")
@@ -945,6 +977,7 @@ async def test_entity_debug_info_message(hass, mqtt_mock):
async def test_precision_default(hass, mqtt_mock):
"""Test that setting precision to tenths works as intended."""
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
@@ -959,6 +992,7 @@ async def test_precision_halves(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["precision"] = 0.5
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
@@ -973,6 +1007,7 @@ async def test_precision_whole(hass, mqtt_mock):
config = copy.deepcopy(DEFAULT_CONFIG)
config["climate"]["precision"] = 1.0
assert await async_setup_component(hass, CLIMATE_DOMAIN, config)
await hass.async_block_till_done()
await common.async_set_temperature(
hass, temperature=23.67, entity_id=ENTITY_CLIMATE
+10 -1
View File
@@ -39,6 +39,7 @@ async def help_test_availability_without_topic(hass, mqtt_mock, domain, config):
"""Test availability without defined availability topic."""
assert "availability_topic" not in config[domain]
assert await async_setup_component(hass, domain, config)
await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test")
assert state.state != STATE_UNAVAILABLE
@@ -61,6 +62,7 @@ async def help_test_default_availability_payload(
config = copy.deepcopy(config)
config[domain]["availability_topic"] = "availability-topic"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test")
assert state.state == STATE_UNAVAILABLE
@@ -108,6 +110,7 @@ async def help_test_custom_availability_payload(
config[domain]["payload_available"] = "good"
config[domain]["payload_not_available"] = "nogood"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test")
assert state.state == STATE_UNAVAILABLE
@@ -147,6 +150,7 @@ async def help_test_setting_attribute_via_mqtt_json_message(
config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "attr-topic", '{ "val": "100" }')
state = hass.states.get(f"{domain}.test")
@@ -164,6 +168,7 @@ async def help_test_setting_attribute_with_template(hass, mqtt_mock, domain, con
config[domain]["json_attributes_topic"] = "attr-topic"
config[domain]["json_attributes_template"] = "{{ value_json['Timer1'] | tojson }}"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
async_fire_mqtt_message(
hass, "attr-topic", json.dumps({"Timer1": {"Arm": 0, "Time": "22:18"}})
@@ -185,6 +190,7 @@ async def help_test_update_with_json_attrs_not_dict(
config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "attr-topic", '[ "list", "of", "things"]')
state = hass.states.get(f"{domain}.test")
@@ -204,6 +210,7 @@ async def help_test_update_with_json_attrs_bad_JSON(
config = copy.deepcopy(config)
config[domain]["json_attributes_topic"] = "attr-topic"
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "attr-topic", "This is not JSON")
@@ -251,7 +258,8 @@ async def help_test_discovery_update_attr(hass, mqtt_mock, caplog, domain, confi
async def help_test_unique_id(hass, domain, config):
"""Test unique id option only creates one entity per unique_id."""
await async_mock_mqtt_component(hass)
assert await async_setup_component(hass, domain, config,)
assert await async_setup_component(hass, domain, config)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(domain)) == 1
@@ -459,6 +467,7 @@ async def help_test_entity_id_update_subscriptions(
registry = mock_registry(hass, {})
mock_mqtt = await async_mock_mqtt_component(hass)
assert await async_setup_component(hass, domain, config,)
await hass.async_block_till_done()
state = hass.states.get(f"{domain}.test")
assert state is not None
+34
View File
@@ -76,6 +76,7 @@ async def test_state_via_state_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -112,6 +113,7 @@ async def test_opening_and_closing_state_via_custom_state_payload(hass, mqtt_moc
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -152,6 +154,7 @@ async def test_open_closed_state_from_position_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -199,6 +202,7 @@ async def test_position_via_position_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -236,6 +240,7 @@ async def test_state_via_template(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -267,6 +272,7 @@ async def test_position_via_template(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -301,6 +307,7 @@ async def test_optimistic_state_change(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -358,6 +365,7 @@ async def test_optimistic_state_change_with_position(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -419,6 +427,7 @@ async def test_send_open_cover_command(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -447,6 +456,7 @@ async def test_send_close_cover_command(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -475,6 +485,7 @@ async def test_send_stop__cover_command(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@@ -507,6 +518,7 @@ async def test_current_cover_position(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state_attributes_dict = hass.states.get("cover.test").attributes
assert not (ATTR_CURRENT_POSITION in state_attributes_dict)
@@ -557,6 +569,7 @@ async def test_current_cover_position_inverted(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state_attributes_dict = hass.states.get("cover.test").attributes
assert not (ATTR_CURRENT_POSITION in state_attributes_dict)
@@ -613,6 +626,7 @@ async def test_optimistic_position(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state is None
@@ -638,6 +652,7 @@ async def test_position_update(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state_attributes_dict = hass.states.get("cover.test").attributes
assert not (ATTR_CURRENT_POSITION in state_attributes_dict)
@@ -675,6 +690,7 @@ async def test_set_position_templated(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -706,6 +722,7 @@ async def test_set_position_untemplated(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -737,6 +754,7 @@ async def test_set_position_untemplated_custom_percentage_range(hass, mqtt_mock)
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -766,6 +784,7 @@ async def test_no_command_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("cover.test").attributes["supported_features"] == 240
@@ -787,6 +806,7 @@ async def test_no_payload_stop(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("cover.test").attributes["supported_features"] == 3
@@ -810,6 +830,7 @@ async def test_with_command_topic_and_tilt(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("cover.test").attributes["supported_features"] == 251
@@ -834,6 +855,7 @@ async def test_tilt_defaults(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state_attributes_dict = hass.states.get("cover.test").attributes
assert ATTR_CURRENT_TILT_POSITION in state_attributes_dict
@@ -864,6 +886,7 @@ async def test_tilt_via_invocation_defaults(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -943,6 +966,7 @@ async def test_tilt_given_value(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -1023,6 +1047,7 @@ async def test_tilt_given_value_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -1079,6 +1104,7 @@ async def test_tilt_given_value_altered_range(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -1145,6 +1171,7 @@ async def test_tilt_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "tilt-status-topic", "0")
@@ -1184,6 +1211,7 @@ async def test_tilt_via_topic_template(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "tilt-status-topic", "99")
@@ -1222,6 +1250,7 @@ async def test_tilt_via_topic_altered_range(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "tilt-status-topic", "0")
@@ -1270,6 +1299,7 @@ async def test_tilt_via_topic_template_altered_range(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "tilt-status-topic", "99")
@@ -1313,6 +1343,7 @@ async def test_tilt_position(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -1348,6 +1379,7 @@ async def test_tilt_position_altered_range(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
cover.DOMAIN,
@@ -1738,6 +1770,7 @@ async def test_valid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state.attributes.get("device_class") == "garage"
@@ -1757,6 +1790,7 @@ async def test_invalid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("cover.test")
assert state is None
+9
View File
@@ -50,6 +50,7 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
assert await async_setup_component(
hass, fan.DOMAIN, {fan.DOMAIN: {"platform": "mqtt", "name": "test"}}
)
await hass.async_block_till_done()
assert hass.states.get("fan.test") is None
@@ -79,6 +80,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@@ -141,6 +143,7 @@ async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@@ -207,6 +210,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@@ -300,6 +304,7 @@ async def test_on_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@@ -352,6 +357,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@@ -450,6 +456,7 @@ async def test_attributes(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@@ -537,6 +544,7 @@ async def test_custom_speed_list(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test")
assert state.state is STATE_OFF
@@ -577,6 +585,7 @@ async def test_supported_features(hass, mqtt_mock):
]
},
)
await hass.async_block_till_done()
state = hass.states.get("fan.test1")
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 0
@@ -76,6 +76,7 @@ async def test_default_supported_features(hass, mqtt_mock):
assert await async_setup_component(
hass, vacuum.DOMAIN, {vacuum.DOMAIN: DEFAULT_CONFIG}
)
await hass.async_block_till_done()
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(
@@ -99,6 +100,7 @@ async def test_all_commands(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
await common.async_turn_on(hass, "vacuum.mqtttest")
mqtt_mock.async_publish.assert_called_once_with(
@@ -178,6 +180,7 @@ async def test_commands_without_supported_features(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
await common.async_turn_on(hass, "vacuum.mqtttest")
mqtt_mock.async_publish.assert_not_called()
@@ -225,6 +228,7 @@ async def test_attributes_without_supported_features(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54,
@@ -250,6 +254,7 @@ async def test_status(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54,
@@ -289,6 +294,7 @@ async def test_status_battery(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54
@@ -306,6 +312,7 @@ async def test_status_cleaning(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"cleaning": true
@@ -323,6 +330,7 @@ async def test_status_docked(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"docked": true
@@ -340,6 +348,7 @@ async def test_status_charging(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"charging": true
@@ -357,6 +366,7 @@ async def test_status_fan_speed(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"fan_speed": "max"
@@ -374,6 +384,7 @@ async def test_status_fan_speed_list(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == ["min", "medium", "high", "max"]
@@ -391,6 +402,7 @@ async def test_status_no_fan_speed_list(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None
@@ -404,6 +416,7 @@ async def test_status_error(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"error": "Error1"
@@ -434,6 +447,7 @@ async def test_battery_template(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "retroroomba/battery_level", "54")
state = hass.states.get("vacuum.mqtttest")
@@ -449,6 +463,7 @@ async def test_status_invalid_json(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}')
state = hass.states.get("vacuum.mqtttest")
@@ -462,6 +477,7 @@ async def test_missing_battery_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_BATTERY_LEVEL_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@@ -473,6 +489,7 @@ async def test_missing_charging_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_CHARGING_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@@ -484,6 +501,7 @@ async def test_missing_cleaning_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_CLEANING_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@@ -495,6 +513,7 @@ async def test_missing_docked_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_DOCKED_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@@ -506,6 +525,7 @@ async def test_missing_error_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_ERROR_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
@@ -517,6 +537,7 @@ async def test_missing_fan_speed_template(hass, mqtt_mock):
config.pop(mqttvacuum.CONF_FAN_SPEED_TEMPLATE)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
state = hass.states.get("vacuum.mqtttest")
assert state is None
+25
View File
@@ -201,6 +201,7 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
assert await async_setup_component(
hass, light.DOMAIN, {light.DOMAIN: {"platform": "mqtt", "name": "test"}}
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
@@ -218,6 +219,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(hass, mqt
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -269,6 +271,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -365,6 +368,7 @@ async def test_invalid_state_via_topic(hass, mqtt_mock, caplog):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -456,6 +460,7 @@ async def test_brightness_controlling_scale(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -501,6 +506,7 @@ async def test_brightness_from_rgb_controlling_scale(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -540,6 +546,7 @@ async def test_white_value_controlling_scale(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -599,6 +606,7 @@ async def test_controlling_state_via_topic_with_templates(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -676,6 +684,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
):
with assert_setup_component(1, light.DOMAIN):
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_ON
@@ -751,6 +760,7 @@ async def test_sending_mqtt_rgb_command_with_template(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -786,6 +796,7 @@ async def test_sending_mqtt_color_temp_command_with_template(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -818,6 +829,7 @@ async def test_show_brightness_if_only_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -843,6 +855,7 @@ async def test_show_color_temp_only_if_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -868,6 +881,7 @@ async def test_show_effect_only_if_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -893,6 +907,7 @@ async def test_show_hs_if_only_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -918,6 +933,7 @@ async def test_show_white_value_if_only_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -943,6 +959,7 @@ async def test_show_xy_if_only_command_topic(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -968,6 +985,7 @@ async def test_on_command_first(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -1002,6 +1020,7 @@ async def test_on_command_last(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -1038,6 +1057,7 @@ async def test_on_command_brightness(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -1091,6 +1111,7 @@ async def test_on_command_brightness_scaled(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -1153,6 +1174,7 @@ async def test_on_command_rgb(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -1243,6 +1265,7 @@ async def test_on_command_rgb_template(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -1279,6 +1302,7 @@ async def test_effect(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -1498,6 +1522,7 @@ async def test_max_mireds(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153
+15
View File
@@ -156,6 +156,7 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
light.DOMAIN,
{light.DOMAIN: {"platform": "mqtt", "schema": "json", "name": "test"}},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
@@ -174,6 +175,7 @@ async def test_no_color_brightness_color_temp_white_val_if_no_topics(hass, mqtt_
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -222,6 +224,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -346,6 +349,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_ON
@@ -457,6 +461,7 @@ async def test_sending_hs_color(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -519,6 +524,7 @@ async def test_sending_rgb_color_no_brightness(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -572,6 +578,7 @@ async def test_sending_rgb_color_with_brightness(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -641,6 +648,7 @@ async def test_sending_rgb_color_with_scaled_brightness(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -709,6 +717,7 @@ async def test_sending_xy_color(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -771,6 +780,7 @@ async def test_effect(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -830,6 +840,7 @@ async def test_flash_short_and_long(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -869,6 +880,7 @@ async def test_transition(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -916,6 +928,7 @@ async def test_brightness_scale(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -959,6 +972,7 @@ async def test_invalid_values(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -1235,6 +1249,7 @@ async def test_max_mireds(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153
@@ -84,6 +84,7 @@ async def test_setup_fails(hass, mqtt_mock):
light.DOMAIN,
{light.DOMAIN: {"platform": "mqtt", "schema": "template", "name": "test"}},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
with assert_setup_component(0, light.DOMAIN):
@@ -99,6 +100,7 @@ async def test_setup_fails(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
with assert_setup_component(0, light.DOMAIN):
@@ -115,6 +117,7 @@ async def test_setup_fails(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
with assert_setup_component(0, light.DOMAIN):
@@ -131,6 +134,7 @@ async def test_setup_fails(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
assert hass.states.get("light.test") is None
@@ -159,6 +163,7 @@ async def test_state_change_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -214,6 +219,7 @@ async def test_state_brightness_color_effect_temp_white_change_via_topic(
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -313,6 +319,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_ON
@@ -454,6 +461,7 @@ async def test_sending_mqtt_commands_non_optimistic_brightness_template(
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -567,6 +575,7 @@ async def test_effect(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -617,6 +626,7 @@ async def test_flash(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -664,6 +674,7 @@ async def test_transition(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -719,6 +730,7 @@ async def test_invalid_values(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.state == STATE_OFF
@@ -994,6 +1006,7 @@ async def test_max_mireds(hass, mqtt_mock):
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("light.test")
assert state.attributes.get("min_mireds") == 153
+6
View File
@@ -58,6 +58,7 @@ async def test_controlling_state_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@@ -92,6 +93,7 @@ async def test_controlling_non_default_state_via_topic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@@ -127,6 +129,7 @@ async def test_controlling_state_via_topic_and_json_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@@ -163,6 +166,7 @@ async def test_controlling_non_default_state_via_topic_and_json_message(
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@@ -195,6 +199,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
@@ -240,6 +245,7 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("lock.test")
assert state.state is STATE_UNLOCKED
+6
View File
@@ -64,6 +64,7 @@ async def test_setting_sensor_value_via_mqtt_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "test-topic", "100")
state = hass.states.get("sensor.test")
@@ -88,6 +89,7 @@ async def test_setting_sensor_value_expires(hass, mqtt_mock, caplog):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert state.state == "unknown"
@@ -155,6 +157,7 @@ async def test_setting_sensor_value_via_mqtt_json_message(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "test-topic", '{ "val": "100" }')
state = hass.states.get("sensor.test")
@@ -176,6 +179,7 @@ async def test_force_update_disabled(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
@@ -209,6 +213,7 @@ async def test_force_update_enabled(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
events = []
@@ -262,6 +267,7 @@ async def test_invalid_device_class(hass, mqtt_mock):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert state is None
@@ -82,6 +82,7 @@ async def test_default_supported_features(hass, mqtt_mock):
assert await async_setup_component(
hass, vacuum.DOMAIN, {vacuum.DOMAIN: DEFAULT_CONFIG}
)
await hass.async_block_till_done()
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(
@@ -97,6 +98,7 @@ async def test_all_commands(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True
@@ -168,6 +170,7 @@ async def test_commands_without_supported_features(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN, SERVICE_START, {"entity_id": ENTITY_MATCH_ALL}, blocking=True
@@ -223,6 +226,7 @@ async def test_status(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54,
@@ -260,6 +264,7 @@ async def test_no_fan_vacuum(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
message = """{
"battery_level": 54,
@@ -309,6 +314,7 @@ async def test_status_invalid_json(hass, mqtt_mock):
)
assert await async_setup_component(hass, vacuum.DOMAIN, {vacuum.DOMAIN: config})
await hass.async_block_till_done()
async_fire_mqtt_message(hass, "vacuum/state", '{"asdfasas false}')
state = hass.states.get("vacuum.mqtttest")
+4
View File
@@ -59,6 +59,7 @@ async def test_controlling_state_via_topic(hass, mock_publish):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
@@ -97,6 +98,7 @@ async def test_sending_mqtt_commands_and_optimistic(hass, mock_publish):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_ON
@@ -137,6 +139,7 @@ async def test_controlling_state_via_topic_and_json_message(hass, mock_publish):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_OFF
@@ -213,6 +216,7 @@ async def test_custom_state_payload(hass, mock_publish):
}
},
)
await hass.async_block_till_done()
state = hass.states.get("switch.test")
assert state.state == STATE_OFF