Remove YAML configuration from onewire (#53728)
This commit is contained in:
parent
692665e46c
commit
87dab02ce6
5 changed files with 11 additions and 203 deletions
|
@ -164,16 +164,3 @@ class OneWireFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
data_schema=DATA_SCHEMA_MOUNTDIR,
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, platform_config: dict[str, Any]) -> FlowResult:
|
||||
"""Handle import configuration from YAML."""
|
||||
# OWServer
|
||||
if platform_config[CONF_TYPE] == CONF_TYPE_OWSERVER:
|
||||
if CONF_PORT not in platform_config:
|
||||
platform_config[CONF_PORT] = DEFAULT_OWSERVER_PORT
|
||||
return await self.async_step_owserver(platform_config)
|
||||
|
||||
# SysBus
|
||||
if CONF_MOUNT_DIR not in platform_config:
|
||||
platform_config[CONF_MOUNT_DIR] = DEFAULT_SYSBUS_MOUNT_DIR
|
||||
return await self.async_step_mount_dir(platform_config)
|
||||
|
|
|
@ -8,24 +8,20 @@ from types import MappingProxyType
|
|||
from typing import Any
|
||||
|
||||
from pi1wire import InvalidCRCException, OneWireInterface, UnsupportResponseException
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType, StateType
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .const import (
|
||||
CONF_MOUNT_DIR,
|
||||
CONF_NAMES,
|
||||
CONF_TYPE_OWSERVER,
|
||||
CONF_TYPE_SYSBUS,
|
||||
DEFAULT_OWSERVER_PORT,
|
||||
DEFAULT_SYSBUS_MOUNT_DIR,
|
||||
DOMAIN,
|
||||
SENSOR_TYPE_COUNT,
|
||||
SENSOR_TYPE_CURRENT,
|
||||
|
@ -233,16 +229,6 @@ EDS_SENSORS: dict[str, list[DeviceComponentDescription]] = {
|
|||
}
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_NAMES): {cv.string: cv.string},
|
||||
vol.Optional(CONF_MOUNT_DIR, default=DEFAULT_SYSBUS_MOUNT_DIR): cv.string,
|
||||
vol.Optional(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_OWSERVER_PORT): cv.port,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_sensor_types(device_sub_type: str) -> dict[str, Any]:
|
||||
"""Return the proper info array for the device type."""
|
||||
if "HobbyBoard" in device_sub_type:
|
||||
|
@ -252,30 +238,6 @@ def get_sensor_types(device_sub_type: str) -> dict[str, Any]:
|
|||
return DEVICE_SENSORS
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, Any],
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Old way of setting up 1-Wire platform."""
|
||||
_LOGGER.warning(
|
||||
"Loading 1-Wire via platform setup is deprecated. "
|
||||
"Please remove it from your configuration"
|
||||
)
|
||||
|
||||
if config.get(CONF_HOST):
|
||||
config[CONF_TYPE] = CONF_TYPE_OWSERVER
|
||||
elif config[CONF_MOUNT_DIR] == DEFAULT_SYSBUS_MOUNT_DIR:
|
||||
config[CONF_TYPE] = CONF_TYPE_SYSBUS
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
|
|
|
@ -30,6 +30,9 @@ async def setup_onewire_sysbus_integration(hass):
|
|||
data={
|
||||
CONF_TYPE: CONF_TYPE_SYSBUS,
|
||||
CONF_MOUNT_DIR: DEFAULT_SYSBUS_MOUNT_DIR,
|
||||
"names": {
|
||||
"10-111111111111": "My DS18B20",
|
||||
},
|
||||
},
|
||||
unique_id=f"{CONF_TYPE_SYSBUS}:{DEFAULT_SYSBUS_MOUNT_DIR}",
|
||||
options={},
|
||||
|
|
|
@ -7,11 +7,10 @@ from homeassistant.components.onewire.const import (
|
|||
CONF_MOUNT_DIR,
|
||||
CONF_TYPE_OWSERVER,
|
||||
CONF_TYPE_SYSBUS,
|
||||
DEFAULT_OWSERVER_PORT,
|
||||
DEFAULT_SYSBUS_MOUNT_DIR,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
|
@ -201,135 +200,3 @@ async def test_user_sysbus_duplicate(hass):
|
|||
assert result["reason"] == "already_configured"
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_sysbus(hass):
|
||||
"""Test import step."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.onewire.onewirehub.os.path.isdir",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.onewire.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={CONF_TYPE: CONF_TYPE_SYSBUS},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == DEFAULT_SYSBUS_MOUNT_DIR
|
||||
assert result["data"] == {
|
||||
CONF_TYPE: CONF_TYPE_SYSBUS,
|
||||
CONF_MOUNT_DIR: DEFAULT_SYSBUS_MOUNT_DIR,
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_sysbus_with_mount_dir(hass):
|
||||
"""Test import step."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.onewire.onewirehub.os.path.isdir",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.onewire.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_TYPE: CONF_TYPE_SYSBUS,
|
||||
CONF_MOUNT_DIR: DEFAULT_SYSBUS_MOUNT_DIR,
|
||||
},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == DEFAULT_SYSBUS_MOUNT_DIR
|
||||
assert result["data"] == {
|
||||
CONF_TYPE: CONF_TYPE_SYSBUS,
|
||||
CONF_MOUNT_DIR: DEFAULT_SYSBUS_MOUNT_DIR,
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_owserver(hass):
|
||||
"""Test import step."""
|
||||
|
||||
with patch("homeassistant.components.onewire.onewirehub.protocol.proxy",), patch(
|
||||
"homeassistant.components.onewire.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||
CONF_HOST: "1.2.3.4",
|
||||
},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "1.2.3.4"
|
||||
assert result["data"] == {
|
||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_PORT: DEFAULT_OWSERVER_PORT,
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_owserver_with_port(hass):
|
||||
"""Test import step."""
|
||||
|
||||
with patch("homeassistant.components.onewire.onewirehub.protocol.proxy",), patch(
|
||||
"homeassistant.components.onewire.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_PORT: 1234,
|
||||
},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "1.2.3.4"
|
||||
assert result["data"] == {
|
||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_PORT: 1234,
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_owserver_duplicate(hass):
|
||||
"""Test OWServer flow."""
|
||||
# Initialise with single entry
|
||||
with patch(
|
||||
"homeassistant.components.onewire.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
await setup_onewire_owserver_integration(hass)
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
|
||||
# Import duplicate entry
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_TYPE: CONF_TYPE_OWSERVER,
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_PORT: 1234,
|
||||
},
|
||||
)
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
|
|
@ -14,6 +14,7 @@ from homeassistant.setup import async_setup_component
|
|||
|
||||
from . import (
|
||||
setup_onewire_patched_owserver_integration,
|
||||
setup_onewire_sysbus_integration,
|
||||
setup_owproxy_mock_devices,
|
||||
setup_sysbus_mock_devices,
|
||||
)
|
||||
|
@ -25,16 +26,6 @@ MOCK_COUPLERS = {
|
|||
key: value for (key, value) in MOCK_OWPROXY_DEVICES.items() if "branches" in value
|
||||
}
|
||||
|
||||
MOCK_SYSBUS_CONFIG = {
|
||||
SENSOR_DOMAIN: {
|
||||
"platform": DOMAIN,
|
||||
"mount_dir": DEFAULT_SYSBUS_MOUNT_DIR,
|
||||
"names": {
|
||||
"10-111111111111": "My DS18B20",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async def test_setup_minimum(hass):
|
||||
"""Test old platform setup with minimum configuration."""
|
||||
|
@ -200,13 +191,11 @@ async def test_onewiredirect_setup_valid_device(hass, device_id):
|
|||
mock_device = MOCK_SYSBUS_DEVICES[device_id]
|
||||
expected_entities = mock_device.get(SENSOR_DOMAIN, [])
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.onewire.onewirehub.os.path.isdir", return_value=True
|
||||
), patch("pi1wire._finder.glob.glob", return_value=glob_result,), patch(
|
||||
with patch("pi1wire._finder.glob.glob", return_value=glob_result,), patch(
|
||||
"pi1wire.OneWire.get_temperature",
|
||||
side_effect=read_side_effect,
|
||||
):
|
||||
assert await async_setup_component(hass, SENSOR_DOMAIN, MOCK_SYSBUS_CONFIG)
|
||||
assert await setup_onewire_sysbus_integration(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(entity_registry.entities) == len(expected_entities)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue