2020-10-14 08:19:12 +00:00
|
|
|
"""Tests for 1-Wire integration."""
|
2020-10-24 01:57:16 +00:00
|
|
|
from asynctest.mock import patch
|
|
|
|
|
|
|
|
from homeassistant.components.onewire.const import (
|
2020-10-26 15:33:13 +00:00
|
|
|
CONF_MOUNT_DIR,
|
2020-10-24 01:57:16 +00:00
|
|
|
CONF_TYPE_OWSERVER,
|
|
|
|
CONF_TYPE_SYSBUS,
|
|
|
|
DEFAULT_SYSBUS_MOUNT_DIR,
|
|
|
|
DOMAIN,
|
|
|
|
)
|
|
|
|
from homeassistant.config_entries import CONN_CLASS_LOCAL_POLL
|
|
|
|
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE
|
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
async def setup_onewire_sysbus_integration(hass):
|
|
|
|
"""Create the 1-Wire integration."""
|
|
|
|
config_entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
source="user",
|
|
|
|
data={
|
|
|
|
CONF_TYPE: CONF_TYPE_SYSBUS,
|
2020-10-26 15:33:13 +00:00
|
|
|
CONF_MOUNT_DIR: DEFAULT_SYSBUS_MOUNT_DIR,
|
2020-10-24 01:57:16 +00:00
|
|
|
},
|
|
|
|
unique_id=f"{CONF_TYPE_SYSBUS}:{DEFAULT_SYSBUS_MOUNT_DIR}",
|
|
|
|
connection_class=CONN_CLASS_LOCAL_POLL,
|
|
|
|
options={},
|
|
|
|
entry_id="1",
|
|
|
|
)
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
|
2020-10-26 15:33:13 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.onewire.onewirehub.os.path.isdir", return_value=True
|
|
|
|
):
|
|
|
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
2020-10-24 01:57:16 +00:00
|
|
|
|
|
|
|
return config_entry
|
|
|
|
|
|
|
|
|
|
|
|
async def setup_onewire_owserver_integration(hass):
|
|
|
|
"""Create the 1-Wire integration."""
|
|
|
|
config_entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
source="user",
|
|
|
|
data={
|
|
|
|
CONF_TYPE: CONF_TYPE_OWSERVER,
|
|
|
|
CONF_HOST: "1.2.3.4",
|
|
|
|
CONF_PORT: "1234",
|
|
|
|
},
|
|
|
|
unique_id=f"{CONF_TYPE_OWSERVER}:1.2.3.4:1234",
|
|
|
|
connection_class=CONN_CLASS_LOCAL_POLL,
|
|
|
|
options={},
|
|
|
|
entry_id="2",
|
|
|
|
)
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
with patch(
|
2020-10-26 15:33:13 +00:00
|
|
|
"homeassistant.components.onewire.onewirehub.protocol.proxy",
|
2020-10-24 01:57:16 +00:00
|
|
|
):
|
|
|
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
return config_entry
|