Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ omit =
homeassistant/components/arwn/sensor.py
homeassistant/components/asterisk_cdr/mailbox.py
homeassistant/components/asterisk_mbox/*
homeassistant/components/asuswrt/device_tracker.py
homeassistant/components/aten_pe/*
homeassistant/components/atome/*
homeassistant/components/august/*
Expand Down
17 changes: 13 additions & 4 deletions homeassistant/components/asuswrt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@

_LOGGER = logging.getLogger(__name__)

CONF_DNSMASQ = "dnsmasq"
CONF_INTERFACE = "interface"
CONF_PUB_KEY = "pub_key"
CONF_REQUIRE_IP = "require_ip"
CONF_SENSORS = "sensors"
CONF_SSH_KEY = "ssh_key"

DOMAIN = "asuswrt"
DATA_ASUSWRT = DOMAIN

DEFAULT_SSH_PORT = 22
DEFAULT_INTERFACE = "eth0"
DEFAULT_DNSMASQ = "/var/lib/misc"

SECRET_GROUP = "Password or SSH Key"
SENSOR_TYPES = ["upload_speed", "download_speed", "download", "upload"]
Expand All @@ -45,6 +50,8 @@
vol.Optional(CONF_SENSORS): vol.All(
cv.ensure_list, [vol.In(SENSOR_TYPES)]
),
vol.Optional(CONF_INTERFACE, default=DEFAULT_INTERFACE): cv.string,
vol.Optional(CONF_DNSMASQ, default=DEFAULT_DNSMASQ): cv.isdir,
}
)
},
Expand All @@ -59,13 +66,15 @@ async def async_setup(hass, config):

api = AsusWrt(
conf[CONF_HOST],
conf.get(CONF_PORT),
conf.get(CONF_PROTOCOL) == "telnet",
conf[CONF_PORT],
conf[CONF_PROTOCOL] == "telnet",
conf[CONF_USERNAME],
conf.get(CONF_PASSWORD, ""),
conf.get("ssh_key", conf.get("pub_key", "")),
conf.get(CONF_MODE),
conf.get(CONF_REQUIRE_IP),
conf[CONF_MODE],
conf[CONF_REQUIRE_IP],
conf[CONF_INTERFACE],
conf[CONF_DNSMASQ],
)

await api.connection.async_connect()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/asuswrt/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "asuswrt",
"name": "Asuswrt",
"documentation": "https://www.home-assistant.io/integrations/asuswrt",
"requirements": ["aioasuswrt==1.1.22"],
"requirements": ["aioasuswrt==1.2.2"],
"dependencies": [],
"codeowners": ["@kennedyshead"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ aio_geojson_nsw_rfs_incidents==0.1
aioambient==1.0.2

# homeassistant.components.asuswrt
aioasuswrt==1.1.22
aioasuswrt==1.2.2

# homeassistant.components.automatic
aioautomatic==0.6.5
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ aio_geojson_nsw_rfs_incidents==0.1
aioambient==1.0.2

# homeassistant.components.asuswrt
aioasuswrt==1.1.22
aioasuswrt==1.2.2

# homeassistant.components.automatic
aioautomatic==0.6.5
Expand Down
90 changes: 72 additions & 18 deletions tests/components/asuswrt/test_device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,26 @@
from unittest.mock import patch

from homeassistant.components.asuswrt import (
CONF_MODE,
CONF_PORT,
CONF_PROTOCOL,
CONF_DNSMASQ,
CONF_INTERFACE,
DATA_ASUSWRT,
DOMAIN,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PLATFORM, CONF_USERNAME
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.setup import async_setup_component

from tests.common import mock_coro_func

FAKEFILE = None

VALID_CONFIG_ROUTER_SSH = {
DOMAIN: {
CONF_PLATFORM: "asuswrt",
CONF_HOST: "fake_host",
CONF_USERNAME: "fake_user",
CONF_PROTOCOL: "ssh",
CONF_MODE: "router",
CONF_PORT: "22",
}
}


async def test_password_or_pub_key_required(hass):
"""Test creating an AsusWRT scanner without a pass or pubkey."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().is_connected = False
result = await async_setup_component(
hass, DOMAIN, {DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}}
hass,
DOMAIN,
{DOMAIN: {CONF_HOST: "fake_host", CONF_USERNAME: "fake_user"}},
)
assert not result

Expand All @@ -53,8 +41,74 @@ async def test_get_scanner_with_password_no_pubkey(hass):
CONF_HOST: "fake_host",
CONF_USERNAME: "fake_user",
CONF_PASSWORD: "4321",
CONF_DNSMASQ: "/",
}
},
)
assert result
assert hass.data[DATA_ASUSWRT] is not None


async def test_specify_non_directory_path_for_dnsmasq(hass):
"""Test creating an AsusWRT scanner with a dnsmasq location which is not a valid directory."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().is_connected = False
result = await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_HOST: "fake_host",
CONF_USERNAME: "fake_user",
CONF_PASSWORD: "4321",
CONF_DNSMASQ: "?non_directory?",
}
},
)
assert not result


async def test_interface(hass):
"""Test creating an AsusWRT scanner using interface eth1."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().connection.async_get_connected_devices = mock_coro_func(
return_value={}
)
result = await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_HOST: "fake_host",
CONF_USERNAME: "fake_user",
CONF_PASSWORD: "4321",
CONF_DNSMASQ: "/",
CONF_INTERFACE: "eth1",
}
},
)
assert result
assert hass.data[DATA_ASUSWRT] is not None


async def test_no_interface(hass):
"""Test creating an AsusWRT scanner using no interface."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()
AsusWrt().is_connected = False
result = await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
CONF_HOST: "fake_host",
CONF_USERNAME: "fake_user",
CONF_PASSWORD: "4321",
CONF_DNSMASQ: "/",
CONF_INTERFACE: None,
}
},
)
assert not result
42 changes: 42 additions & 0 deletions tests/components/asuswrt/test_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""The tests for the ASUSWRT sensor platform."""
from unittest.mock import patch

# import homeassistant.components.sensor as sensor
from homeassistant.components.asuswrt import (
CONF_DNSMASQ,
CONF_INTERFACE,
CONF_MODE,
CONF_PORT,
CONF_PROTOCOL,
CONF_SENSORS,
DATA_ASUSWRT,
DOMAIN,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.setup import async_setup_component

from tests.common import mock_coro_func

VALID_CONFIG_ROUTER_SSH = {
DOMAIN: {
CONF_DNSMASQ: "/",
CONF_HOST: "fake_host",
CONF_INTERFACE: "eth0",
CONF_MODE: "router",
CONF_PORT: "22",
CONF_PROTOCOL: "ssh",
CONF_USERNAME: "fake_user",
CONF_PASSWORD: "fake_pass",
CONF_SENSORS: "upload",
}
}


async def test_default_sensor_setup(hass):
"""Test creating an AsusWRT sensor."""
with patch("homeassistant.components.asuswrt.AsusWrt") as AsusWrt:
AsusWrt().connection.async_connect = mock_coro_func()

result = await async_setup_component(hass, DOMAIN, VALID_CONFIG_ROUTER_SSH)
assert result
assert hass.data[DATA_ASUSWRT] is not None