Move imports in mqtt component (#27835)
* move imports to top-level in mqtt server * move imports to top-level in mqtt configflow * move imports to top-level in mqtt init * move imports to top-level in mqtt vacuum * move imports to top-level in mqtt light
This commit is contained in:
1 parent
7637ceb880
commit
1a5b4c105a
19 files changed
+130
-144
No files matched your search
@@ -5,10 +5,8 @@ import json
|
||||
from homeassistant.components import mqtt, vacuum
|
||||
from homeassistant.components.mqtt import CONF_COMMAND_TOPIC
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
from homeassistant.components.mqtt.vacuum import (
|
||||
schema_legacy as mqttvacuum,
|
||||
services_to_strings,
|
||||
)
|
||||
from homeassistant.components.mqtt.vacuum import schema_legacy as mqttvacuum
|
||||
from homeassistant.components.mqtt.vacuum.schema import services_to_strings
|
||||
from homeassistant.components.mqtt.vacuum.schema_legacy import (
|
||||
ALL_SERVICES,
|
||||
SERVICE_TO_STRING,
|
||||
@@ -80,7 +78,7 @@ async def test_default_supported_features(hass, mqtt_mock):
|
||||
async def test_all_commands(hass, mqtt_mock):
|
||||
"""Test simple commands to the vacuum."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
@@ -221,7 +219,7 @@ async def test_attributes_without_supported_features(hass, mqtt_mock):
|
||||
async def test_status(hass, mqtt_mock):
|
||||
"""Test status updates from the vacuum."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
@@ -260,7 +258,7 @@ async def test_status(hass, mqtt_mock):
|
||||
async def test_status_battery(hass, mqtt_mock):
|
||||
"""Test status updates from the vacuum."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
@@ -277,7 +275,7 @@ async def test_status_battery(hass, mqtt_mock):
|
||||
async def test_status_cleaning(hass, mqtt_mock):
|
||||
"""Test status updates from the vacuum."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
@@ -294,7 +292,7 @@ async def test_status_cleaning(hass, mqtt_mock):
|
||||
async def test_status_docked(hass, mqtt_mock):
|
||||
"""Test status updates from the vacuum."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
@@ -311,7 +309,7 @@ async def test_status_docked(hass, mqtt_mock):
|
||||
async def test_status_charging(hass, mqtt_mock):
|
||||
"""Test status updates from the vacuum."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
@@ -328,7 +326,7 @@ async def test_status_charging(hass, mqtt_mock):
|
||||
async def test_status_fan_speed(hass, mqtt_mock):
|
||||
"""Test status updates from the vacuum."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
@@ -345,7 +343,7 @@ async def test_status_fan_speed(hass, mqtt_mock):
|
||||
async def test_status_error(hass, mqtt_mock):
|
||||
"""Test status updates from the vacuum."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
@@ -371,7 +369,7 @@ async def test_battery_template(hass, mqtt_mock):
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config.update(
|
||||
{
|
||||
mqttvacuum.CONF_SUPPORTED_FEATURES: mqttvacuum.services_to_strings(
|
||||
mqttvacuum.CONF_SUPPORTED_FEATURES: services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
),
|
||||
mqttvacuum.CONF_BATTERY_LEVEL_TOPIC: "retroroomba/battery_level",
|
||||
@@ -390,7 +388,7 @@ async def test_battery_template(hass, mqtt_mock):
|
||||
async def test_status_invalid_json(hass, mqtt_mock):
|
||||
"""Test to make sure nothing breaks if the vacuum sends bad JSON."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
|
||||
@@ -19,9 +19,13 @@ class TestMQTT:
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@patch("passlib.apps.custom_app_context", Mock(return_value=""))
|
||||
@patch(
|
||||
"homeassistant.components.mqtt.server.custom_app_context", Mock(return_value="")
|
||||
)
|
||||
@patch("tempfile.NamedTemporaryFile", Mock(return_value=MagicMock()))
|
||||
@patch("hbmqtt.broker.Broker", Mock(return_value=MagicMock()))
|
||||
@patch(
|
||||
"homeassistant.components.mqtt.server.Broker", Mock(return_value=MagicMock())
|
||||
)
|
||||
@patch("hbmqtt.broker.Broker.start", Mock(return_value=mock_coro()))
|
||||
@patch("homeassistant.components.mqtt.MQTT")
|
||||
def test_creating_config_with_pass_and_no_http_pass(self, mock_mqtt):
|
||||
@@ -41,9 +45,13 @@ class TestMQTT:
|
||||
assert mock_mqtt.mock_calls[1][2]["username"] == "homeassistant"
|
||||
assert mock_mqtt.mock_calls[1][2]["password"] == password
|
||||
|
||||
@patch("passlib.apps.custom_app_context", Mock(return_value=""))
|
||||
@patch(
|
||||
"homeassistant.components.mqtt.server.custom_app_context", Mock(return_value="")
|
||||
)
|
||||
@patch("tempfile.NamedTemporaryFile", Mock(return_value=MagicMock()))
|
||||
@patch("hbmqtt.broker.Broker", Mock(return_value=MagicMock()))
|
||||
@patch(
|
||||
"homeassistant.components.mqtt.server.Broker", Mock(return_value=MagicMock())
|
||||
)
|
||||
@patch("hbmqtt.broker.Broker.start", Mock(return_value=mock_coro()))
|
||||
@patch("homeassistant.components.mqtt.MQTT")
|
||||
def test_creating_config_with_pass_and_http_pass(self, mock_mqtt):
|
||||
|
||||
@@ -5,11 +5,8 @@ import json
|
||||
from homeassistant.components import mqtt, vacuum
|
||||
from homeassistant.components.mqtt import CONF_COMMAND_TOPIC, CONF_STATE_TOPIC
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
from homeassistant.components.mqtt.vacuum import (
|
||||
CONF_SCHEMA,
|
||||
schema_state as mqttvacuum,
|
||||
services_to_strings,
|
||||
)
|
||||
from homeassistant.components.mqtt.vacuum import CONF_SCHEMA, schema_state as mqttvacuum
|
||||
from homeassistant.components.mqtt.vacuum.schema import services_to_strings
|
||||
from homeassistant.components.mqtt.vacuum.schema_state import SERVICE_TO_STRING
|
||||
from homeassistant.components.vacuum import (
|
||||
ATTR_BATTERY_ICON,
|
||||
@@ -259,7 +256,7 @@ async def test_no_fan_vacuum(hass, mqtt_mock):
|
||||
async def test_status_invalid_json(hass, mqtt_mock):
|
||||
"""Test to make sure nothing breaks if the vacuum sends bad JSON."""
|
||||
config = deepcopy(DEFAULT_CONFIG)
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = mqttvacuum.services_to_strings(
|
||||
config[mqttvacuum.CONF_SUPPORTED_FEATURES] = services_to_strings(
|
||||
mqttvacuum.ALL_SERVICES, SERVICE_TO_STRING
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user