Skip to content

Commit

Permalink
Remove Spider integration (#127346)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Oct 3, 2024
1 parent 0ae0047 commit 48a6dab
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 648 deletions.
2 changes: 0 additions & 2 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1384,8 +1384,6 @@ build.json @home-assistant/supervisor
/tests/components/spaceapi/ @fabaff
/homeassistant/components/speedtestdotnet/ @rohankapoorcom @engrbm87
/tests/components/speedtestdotnet/ @rohankapoorcom @engrbm87
/homeassistant/components/spider/ @peternijssen
/tests/components/spider/ @peternijssen
/homeassistant/components/splunk/ @Bre77
/homeassistant/components/spotify/ @frenck @joostlek
/tests/components/spotify/ @frenck @joostlek
Expand Down
104 changes: 28 additions & 76 deletions homeassistant/components/spider/__init__.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,39 @@
"""Support for Spider Smart devices."""
"""The Spider integration."""

import logging
from __future__ import annotations

from spiderpy.spiderapi import SpiderApi, SpiderApiException, UnauthorizedException
import voluptuous as vol

from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType

from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, PLATFORMS

_LOGGER = logging.getLogger(__name__)

CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): cv.time_period,
}
)
from homeassistant.helpers import issue_registry as ir

DOMAIN = "spider"


async def async_setup_entry(hass: HomeAssistant, _: ConfigEntry) -> bool:
"""Set up Spider from a config entry."""
ir.async_create_issue(
hass,
DOMAIN,
DOMAIN,
is_fixable=False,
severity=ir.IssueSeverity.ERROR,
translation_key="integration_removed",
translation_placeholders={
"link": "https://www.ithodaalderop.nl/additionelespiderproducten",
"entries": "/config/integrations/integration/spider",
},
),
extra=vol.ALLOW_EXTRA,
)


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up a config entry."""
hass.data[DOMAIN] = {}
if DOMAIN not in config:
return True

conf = config[DOMAIN]

if not hass.config_entries.async_entries(DOMAIN):
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=conf
)
)

return True


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Spider via config entry."""
try:
api = await hass.async_add_executor_job(
SpiderApi,
entry.data[CONF_USERNAME],
entry.data[CONF_PASSWORD],
entry.data[CONF_SCAN_INTERVAL],
)
except UnauthorizedException:
_LOGGER.error("Authorization failed")
return False
except SpiderApiException as err:
_LOGGER.error("Can't connect to the Spider API: %s", err)
raise ConfigEntryNotReady from err

hass.data[DOMAIN][entry.entry_id] = api

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
)

return True


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload Spider entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if not unload_ok:
return False

hass.data[DOMAIN].pop(entry.entry_id)
"""Unload a config entry."""
if all(
config_entry.state is ConfigEntryState.NOT_LOADED
for config_entry in hass.config_entries.async_entries(DOMAIN)
if config_entry.entry_id != entry.entry_id
):
ir.async_delete_issue(hass, DOMAIN, DOMAIN)

return True
144 changes: 0 additions & 144 deletions homeassistant/components/spider/climate.py

This file was deleted.

84 changes: 4 additions & 80 deletions homeassistant/components/spider/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,11 @@
"""Config flow for Spider."""
"""Config flow for Spider integration."""

import logging
from typing import Any
from homeassistant.config_entries import ConfigFlow

from spiderpy.spiderapi import SpiderApi, SpiderApiException, UnauthorizedException
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME

from .const import DEFAULT_SCAN_INTERVAL, DOMAIN

_LOGGER = logging.getLogger(__name__)

DATA_SCHEMA_USER = vol.Schema(
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
)

RESULT_AUTH_FAILED = "auth_failed"
RESULT_CONN_ERROR = "conn_error"
RESULT_SUCCESS = "success"
from . import DOMAIN


class SpiderConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a Spider config flow."""
"""Handle a config flow for Spider."""

VERSION = 1

def __init__(self) -> None:
"""Initialize the Spider flow."""
self.data = {
CONF_USERNAME: "",
CONF_PASSWORD: "",
CONF_SCAN_INTERVAL: DEFAULT_SCAN_INTERVAL,
}

def _try_connect(self):
"""Try to connect and check auth."""
try:
SpiderApi(
self.data[CONF_USERNAME],
self.data[CONF_PASSWORD],
self.data[CONF_SCAN_INTERVAL],
)
except SpiderApiException:
return RESULT_CONN_ERROR
except UnauthorizedException:
return RESULT_AUTH_FAILED

return RESULT_SUCCESS

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a flow initiated by the user."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")

errors = {}
if user_input is not None:
self.data[CONF_USERNAME] = user_input["username"]
self.data[CONF_PASSWORD] = user_input["password"]

result = await self.hass.async_add_executor_job(self._try_connect)

if result == RESULT_SUCCESS:
return self.async_create_entry(
title=DOMAIN,
data=self.data,
)
if result != RESULT_AUTH_FAILED:
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
return self.async_abort(reason=result)

errors["base"] = "invalid_auth"

return self.async_show_form(
step_id="user",
data_schema=DATA_SCHEMA_USER,
errors=errors,
)

async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
"""Import spider config from configuration.yaml."""
return await self.async_step_user(import_data)
8 changes: 0 additions & 8 deletions homeassistant/components/spider/const.py

This file was deleted.

7 changes: 3 additions & 4 deletions homeassistant/components/spider/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"domain": "spider",
"name": "Itho Daalderop Spider",
"codeowners": ["@peternijssen"],
"config_flow": true,
"codeowners": [],
"documentation": "https://www.home-assistant.io/integrations/spider",
"integration_type": "system",
"iot_class": "cloud_polling",
"loggers": ["spiderpy"],
"requirements": ["spiderpy==1.6.1"]
"requirements": []
}
Loading

0 comments on commit 48a6dab

Please sign in to comment.