2019-09-03 23:18:06 +00:00
|
|
|
"""Test pi_hole component."""
|
|
|
|
|
|
|
|
from homeassistant.components import pi_hole
|
2019-12-09 08:38:14 +00:00
|
|
|
|
2020-05-13 13:25:06 +00:00
|
|
|
from . import _create_mocked_hole, _patch_config_flow_hole
|
|
|
|
|
|
|
|
from tests.async_mock import patch
|
2019-09-03 23:18:06 +00:00
|
|
|
from tests.common import async_setup_component
|
|
|
|
|
2020-05-13 13:25:06 +00:00
|
|
|
|
|
|
|
def _patch_init_hole(mocked_hole):
|
|
|
|
return patch("homeassistant.components.pi_hole.Hole", return_value=mocked_hole)
|
2019-09-03 23:18:06 +00:00
|
|
|
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
|
|
|
|
async def test_setup_minimal_config(hass):
|
|
|
|
"""Tests component setup with minimal config."""
|
2020-05-13 13:25:06 +00:00
|
|
|
mocked_hole = _create_mocked_hole()
|
|
|
|
with _patch_config_flow_hole(mocked_hole), _patch_init_hole(mocked_hole):
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
assert await async_setup_component(
|
|
|
|
hass, pi_hole.DOMAIN, {pi_hole.DOMAIN: [{"host": "pi.hole"}]}
|
|
|
|
)
|
2019-09-03 23:18:06 +00:00
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.pi_hole_ads_blocked_today").name
|
|
|
|
== "Pi-Hole Ads Blocked Today"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.pi_hole_ads_percentage_blocked_today").name
|
|
|
|
== "Pi-Hole Ads Percentage Blocked Today"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.pi_hole_dns_queries_cached").name
|
|
|
|
== "Pi-Hole DNS Queries Cached"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.pi_hole_dns_queries_forwarded").name
|
|
|
|
== "Pi-Hole DNS Queries Forwarded"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.pi_hole_dns_queries_today").name
|
|
|
|
== "Pi-Hole DNS Queries Today"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.pi_hole_dns_unique_clients").name
|
|
|
|
== "Pi-Hole DNS Unique Clients"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.pi_hole_dns_unique_domains").name
|
|
|
|
== "Pi-Hole DNS Unique Domains"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.pi_hole_domains_blocked").name
|
|
|
|
== "Pi-Hole Domains Blocked"
|
|
|
|
)
|
|
|
|
assert hass.states.get("sensor.pi_hole_seen_clients").name == "Pi-Hole Seen Clients"
|
|
|
|
|
|
|
|
assert hass.states.get("sensor.pi_hole_ads_blocked_today").state == "0"
|
|
|
|
assert hass.states.get("sensor.pi_hole_ads_percentage_blocked_today").state == "0"
|
|
|
|
assert hass.states.get("sensor.pi_hole_dns_queries_cached").state == "0"
|
|
|
|
assert hass.states.get("sensor.pi_hole_dns_queries_forwarded").state == "0"
|
|
|
|
assert hass.states.get("sensor.pi_hole_dns_queries_today").state == "0"
|
|
|
|
assert hass.states.get("sensor.pi_hole_dns_unique_clients").state == "0"
|
|
|
|
assert hass.states.get("sensor.pi_hole_dns_unique_domains").state == "0"
|
|
|
|
assert hass.states.get("sensor.pi_hole_domains_blocked").state == "0"
|
|
|
|
assert hass.states.get("sensor.pi_hole_seen_clients").state == "0"
|
|
|
|
|
|
|
|
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
async def test_setup_name_config(hass):
|
|
|
|
"""Tests component setup with a custom name."""
|
2020-05-13 13:25:06 +00:00
|
|
|
mocked_hole = _create_mocked_hole()
|
|
|
|
with _patch_config_flow_hole(mocked_hole), _patch_init_hole(mocked_hole):
|
2019-09-03 23:18:06 +00:00
|
|
|
assert await async_setup_component(
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
hass,
|
|
|
|
pi_hole.DOMAIN,
|
|
|
|
{pi_hole.DOMAIN: [{"host": "pi.hole", "name": "Custom"}]},
|
2019-09-03 23:18:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert (
|
|
|
|
hass.states.get("sensor.custom_ads_blocked_today").name
|
|
|
|
== "Custom Ads Blocked Today"
|
|
|
|
)
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_disable_service_call(hass):
|
|
|
|
"""Test disable service call with no Pi-hole named."""
|
2020-05-13 13:25:06 +00:00
|
|
|
mocked_hole = _create_mocked_hole()
|
|
|
|
with _patch_config_flow_hole(mocked_hole), _patch_init_hole(mocked_hole):
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
pi_hole.DOMAIN,
|
|
|
|
{
|
|
|
|
pi_hole.DOMAIN: [
|
2020-05-13 13:25:06 +00:00
|
|
|
{"host": "pi.hole1", "api_key": "1"},
|
|
|
|
{"host": "pi.hole2", "name": "Custom", "api_key": "2"},
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
pi_hole.DOMAIN,
|
|
|
|
pi_hole.SERVICE_DISABLE,
|
|
|
|
{pi_hole.SERVICE_DISABLE_ATTR_DURATION: "00:00:01"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-05-13 13:25:06 +00:00
|
|
|
assert mocked_hole.disable.call_count == 2
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_enable_service_call(hass):
|
|
|
|
"""Test enable service call with no Pi-hole named."""
|
2020-05-13 13:25:06 +00:00
|
|
|
mocked_hole = _create_mocked_hole()
|
|
|
|
with _patch_config_flow_hole(mocked_hole), _patch_init_hole(mocked_hole):
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
pi_hole.DOMAIN,
|
|
|
|
{
|
|
|
|
pi_hole.DOMAIN: [
|
2020-05-13 13:25:06 +00:00
|
|
|
{"host": "pi.hole1", "api_key": "1"},
|
|
|
|
{"host": "pi.hole2", "name": "Custom", "api_key": "2"},
|
(Re)Add support for multiple Pi-Holes (#27569)
* Update configuration schema to support multiple Pi-holes
* Construct sensors for each configured Pi-hole
* Ensure each Pi-hole has a unique name
* Update services to handle multiple Pi-holes
* Update tests for multiple configurations
* Refactor tests to support service testing
* Fix else-raise per pyliunt
* Per code review, add all entities in a single call
* Per code review, add the default name as default.
* Per code review, add cv.ensure_list to prevent breaking change
* Per code review, move name validation to schema
* Remove default name
* Per code review, validate api_key in schema definition
* Per code review, rename variables
* Per code review, use list comprehension
* Ensure unique slug names in config validation
* Per code review, refactor to CoroutineMock
* Fix adding sensor entities
* Per code review, refactor mock function creation
* Per code review, refactor mock function return values
2019-12-12 18:43:49 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
pi_hole.DOMAIN, pi_hole.SERVICE_ENABLE, {}, blocking=True
|
|
|
|
)
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-05-13 13:25:06 +00:00
|
|
|
assert mocked_hole.enable.call_count == 2
|