Remove YAML import from streamlabswater (#119783)

This commit is contained in:
G Johansson 2024-06-17 10:04:18 +02:00 committed by GitHub
parent 09b49ee505
commit d1d21811fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 2 additions and 159 deletions

View file

@ -3,17 +3,10 @@
from streamlabswater.streamlabswater import StreamlabsClient
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, Platform
from homeassistant.core import (
DOMAIN as HOMEASSISTANT_DOMAIN,
HomeAssistant,
ServiceCall,
)
from homeassistant.data_entry_flow import FlowResultType
from homeassistant.core import HomeAssistant, ServiceCall
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN
from .coordinator import StreamlabsCoordinator
@ -26,17 +19,6 @@ AWAY_MODE_HOME = "home"
CONF_LOCATION_ID = "location_id"
ISSUE_PLACEHOLDER = {"url": "/config/integrations/dashboard/add?domain=streamlabswater"}
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_API_KEY): cv.string,
vol.Optional(CONF_LOCATION_ID): cv.string,
}
)
},
extra=vol.ALLOW_EXTRA,
)
SET_AWAY_MODE_SCHEMA = vol.Schema(
{
@ -48,50 +30,6 @@ SET_AWAY_MODE_SCHEMA = vol.Schema(
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the streamlabs water integration."""
if DOMAIN not in config:
return True
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_API_KEY: config[DOMAIN][CONF_API_KEY]},
)
if (
result["type"] == FlowResultType.CREATE_ENTRY
or result["reason"] == "already_configured"
):
async_create_issue(
hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
breaks_in_ha_version="2024.7.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "StreamLabs",
},
)
else:
async_create_issue(
hass,
DOMAIN,
f"deprecated_yaml_import_issue_{result['reason']}",
breaks_in_ha_version="2024.7.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key=f"deprecated_yaml_import_issue_{result['reason']}",
translation_placeholders=ISSUE_PLACEHOLDER,
)
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up StreamLabs from a config entry."""

View file

@ -57,19 +57,6 @@ class StreamlabsConfigFlow(ConfigFlow, domain=DOMAIN):
errors=errors,
)
async def async_step_import(self, user_input: dict[str, Any]) -> ConfigFlowResult:
"""Import the yaml config."""
self._async_abort_entries_match(user_input)
try:
await validate_input(self.hass, user_input[CONF_API_KEY])
except CannotConnect:
return self.async_abort(reason="cannot_connect")
except Exception: # noqa: BLE001
LOGGER.exception("Unexpected exception")
return self.async_abort(reason="unknown")
return self.async_create_entry(title="Streamlabs", data=user_input)
class CannotConnect(HomeAssistantError):
"""Error to indicate we cannot connect."""

View file

@ -48,15 +48,5 @@
"name": "Yearly usage"
}
}
},
"issues": {
"deprecated_yaml_import_issue_cannot_connect": {
"title": "The Streamlabs water YAML configuration import failed",
"description": "Configuring Streamlabs water using YAML is being removed but there was a connection error importing your YAML configuration.\n\nEnsure connection to Streamlabs water works and restart Home Assistant to try again or remove the Streamlabs water YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
},
"deprecated_yaml_import_issue_unknown": {
"title": "The Streamlabs water YAML configuration import failed",
"description": "Configuring Streamlabs water using YAML is being removed but there was an unknown error when trying to import the YAML configuration.\n\nEnsure the imported configuration is correct and remove the Streamlabs water YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
}
}
}

View file

@ -120,75 +120,3 @@ async def test_form_entry_already_exists(hass: HomeAssistant) -> None:
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
async def test_import(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"""Test import flow."""
with patch("homeassistant.components.streamlabswater.config_flow.StreamlabsClient"):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={CONF_API_KEY: "abc"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "Streamlabs"
assert result["data"] == {CONF_API_KEY: "abc"}
assert len(mock_setup_entry.mock_calls) == 1
async def test_import_cannot_connect(
hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test we handle cannot connect error."""
with patch(
"homeassistant.components.streamlabswater.config_flow.StreamlabsClient.get_locations",
return_value={},
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={CONF_API_KEY: "abc"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "cannot_connect"
async def test_import_unknown(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"""Test we handle unknown error."""
with patch(
"homeassistant.components.streamlabswater.config_flow.StreamlabsClient.get_locations",
side_effect=Exception,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={CONF_API_KEY: "abc"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "unknown"
async def test_import_entry_already_exists(hass: HomeAssistant) -> None:
"""Test we handle if the entry already exists."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_API_KEY: "abc"},
)
entry.add_to_hass(hass)
with patch("homeassistant.components.streamlabswater.config_flow.StreamlabsClient"):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={CONF_API_KEY: "abc"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"