Remove yaml config from modem_callerid (#59526)
This commit is contained in:
parent
27b2aa04c9
commit
68e80f1431
4 changed files with 10 additions and 102 deletions
|
@ -1,10 +1,9 @@
|
||||||
"""Config flow for Modem Caller ID integration."""
|
"""Config flow for Modem Caller ID integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from phone_modem import DEFAULT_PORT, PhoneModem
|
from phone_modem import PhoneModem
|
||||||
import serial.tools.list_ports
|
import serial.tools.list_ports
|
||||||
from serial.tools.list_ports_common import ListPortInfo
|
from serial.tools.list_ports_common import ListPortInfo
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -16,8 +15,6 @@ from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import DEFAULT_NAME, DOMAIN, EXCEPTIONS
|
from .const import DEFAULT_NAME, DOMAIN, EXCEPTIONS
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
DATA_SCHEMA = vol.Schema({"name": str, "device": str})
|
DATA_SCHEMA = vol.Schema({"name": str, "device": str})
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,30 +99,6 @@ class PhoneModemFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
schema = vol.Schema({vol.Required(CONF_DEVICE): vol.In(unused_ports)})
|
schema = vol.Schema({vol.Required(CONF_DEVICE): vol.In(unused_ports)})
|
||||||
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
|
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
|
||||||
|
|
||||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
|
||||||
"""Import a config entry from configuration.yaml."""
|
|
||||||
if self._async_current_entries():
|
|
||||||
_LOGGER.warning(
|
|
||||||
"Loading Modem_callerid via platform setup is deprecated; Please remove it from your configuration"
|
|
||||||
)
|
|
||||||
if CONF_DEVICE not in config:
|
|
||||||
config[CONF_DEVICE] = DEFAULT_PORT
|
|
||||||
ports = await self.hass.async_add_executor_job(serial.tools.list_ports.comports)
|
|
||||||
for port in ports:
|
|
||||||
if port.device == config[CONF_DEVICE]:
|
|
||||||
if (
|
|
||||||
await self.validate_device_errors(
|
|
||||||
dev_path=port.device,
|
|
||||||
unique_id=_generate_unique_id(port),
|
|
||||||
)
|
|
||||||
is None
|
|
||||||
):
|
|
||||||
return self.async_create_entry(
|
|
||||||
title=config.get(CONF_NAME, DEFAULT_NAME),
|
|
||||||
data={CONF_DEVICE: port.device},
|
|
||||||
)
|
|
||||||
return self.async_abort(reason="cannot_connect")
|
|
||||||
|
|
||||||
async def validate_device_errors(
|
async def validate_device_errors(
|
||||||
self, dev_path: str, unique_id: str
|
self, dev_path: str, unique_id: str
|
||||||
) -> dict[str, str] | None:
|
) -> dict[str, str] | None:
|
||||||
|
|
|
@ -5,7 +5,6 @@ from phone_modem import exceptions
|
||||||
from serial import SerialException
|
from serial import SerialException
|
||||||
|
|
||||||
DATA_KEY_API = "api"
|
DATA_KEY_API = "api"
|
||||||
DATA_KEY_COORDINATOR = "coordinator"
|
|
||||||
DEFAULT_NAME = "Phone Modem"
|
DEFAULT_NAME = "Phone Modem"
|
||||||
DOMAIN = "modem_callerid"
|
DOMAIN = "modem_callerid"
|
||||||
ICON = "mdi:phone-classic"
|
ICON = "mdi:phone-classic"
|
||||||
|
|
|
@ -1,48 +1,15 @@
|
||||||
"""A sensor for incoming calls using a USB modem that supports caller ID."""
|
"""A sensor for incoming calls using a USB modem that supports caller ID."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from phone_modem import DEFAULT_PORT, PhoneModem
|
from phone_modem import PhoneModem
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_DEVICE, EVENT_HOMEASSISTANT_STOP, STATE_IDLE
|
||||||
CONF_DEVICE,
|
|
||||||
CONF_NAME,
|
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
|
||||||
STATE_IDLE,
|
|
||||||
)
|
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import entity_platform
|
||||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
|
||||||
|
|
||||||
from .const import CID, DATA_KEY_API, DEFAULT_NAME, DOMAIN, ICON, SERVICE_REJECT_CALL
|
from .const import CID, DATA_KEY_API, DOMAIN, ICON, SERVICE_REJECT_CALL
|
||||||
|
|
||||||
# Deprecated in Home Assistant 2021.10
|
|
||||||
PLATFORM_SCHEMA = cv.deprecated(
|
|
||||||
vol.All(
|
|
||||||
PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
vol.Optional(CONF_DEVICE, default=DEFAULT_PORT): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigEntry,
|
|
||||||
async_add_entities: entity_platform.AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the Modem Caller ID component."""
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
|
@ -5,8 +5,8 @@ import phone_modem
|
||||||
import serial.tools.list_ports
|
import serial.tools.list_ports
|
||||||
|
|
||||||
from homeassistant.components import usb
|
from homeassistant.components import usb
|
||||||
from homeassistant.components.modem_callerid.const import DEFAULT_NAME, DOMAIN
|
from homeassistant.components.modem_callerid.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USB, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USB, SOURCE_USER
|
||||||
from homeassistant.const import CONF_DEVICE, CONF_SOURCE
|
from homeassistant.const import CONF_DEVICE, CONF_SOURCE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import (
|
from homeassistant.data_entry_flow import (
|
||||||
|
@ -15,7 +15,7 @@ from homeassistant.data_entry_flow import (
|
||||||
RESULT_TYPE_FORM,
|
RESULT_TYPE_FORM,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import CONF_DATA, IMPORT_DATA, _patch_config_flow_modem
|
from . import _patch_config_flow_modem
|
||||||
|
|
||||||
DISCOVERY_INFO = {
|
DISCOVERY_INFO = {
|
||||||
"device": phone_modem.DEFAULT_PORT,
|
"device": phone_modem.DEFAULT_PORT,
|
||||||
|
@ -171,34 +171,3 @@ async def test_abort_user_with_existing_flow(hass: HomeAssistant):
|
||||||
|
|
||||||
assert result2["type"] == RESULT_TYPE_ABORT
|
assert result2["type"] == RESULT_TYPE_ABORT
|
||||||
assert result2["reason"] == "already_in_progress"
|
assert result2["reason"] == "already_in_progress"
|
||||||
|
|
||||||
|
|
||||||
@patch("serial.tools.list_ports.comports", MagicMock(return_value=[com_port()]))
|
|
||||||
async def test_flow_import(hass: HomeAssistant):
|
|
||||||
"""Test import step."""
|
|
||||||
with _patch_config_flow_modem(AsyncMock()):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=IMPORT_DATA
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result["title"] == DEFAULT_NAME
|
|
||||||
assert result["data"] == CONF_DATA
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=IMPORT_DATA
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_ABORT
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_flow_import_cannot_connect(hass: HomeAssistant):
|
|
||||||
"""Test import connection error."""
|
|
||||||
with _patch_config_flow_modem(AsyncMock()) as modemmock:
|
|
||||||
modemmock.side_effect = phone_modem.exceptions.SerialError
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=IMPORT_DATA
|
|
||||||
)
|
|
||||||
assert result["type"] == RESULT_TYPE_ABORT
|
|
||||||
assert result["reason"] == "cannot_connect"
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue