Skip to content
Snippets Groups Projects
Unverified Commit 57848cdf authored by J. Nick Koston's avatar J. Nick Koston Committed by GitHub
Browse files

Add the ability to reload ping platforms from yaml (#39344)

parent 85869be2
No related branches found
No related tags found
No related merge requests found
"""The ping component."""
DOMAIN = "ping"
PLATFORMS = ["binary_sensor"]
......@@ -12,7 +12,9 @@ import voluptuous as vol
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity
from homeassistant.const import CONF_HOST, CONF_NAME
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.reload import setup_reload_service
from . import DOMAIN, PLATFORMS
from .const import PING_TIMEOUT
_LOGGER = logging.getLogger(__name__)
......@@ -56,6 +58,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None) -> None:
"""Set up the Ping Binary sensor."""
setup_reload_service(hass, DOMAIN, PLATFORMS)
host = config[CONF_HOST]
count = config[CONF_PING_COUNT]
name = config.get(CONF_NAME, f"{DEFAULT_NAME} {host}")
......
reload:
description: Reload all ping entities.
......@@ -391,6 +391,9 @@ huawei-lte-api==1.4.12
# homeassistant.components.iaqualink
iaqualink==0.3.4
# homeassistant.components.ping
icmplib==1.1.1
# homeassistant.components.influxdb
influxdb-client==1.8.0
......
"""Tests for ping component."""
"""The test for the ping binary_sensor platform."""
from os import path
from homeassistant import config as hass_config, setup
from homeassistant.components.ping import DOMAIN
from homeassistant.const import SERVICE_RELOAD
from tests.async_mock import patch
async def test_reload(hass):
"""Verify we can reload trend sensors."""
await setup.async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "ping",
"name": "test",
"host": "127.0.0.1",
"count": 1,
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1
assert hass.states.get("binary_sensor.test")
yaml_path = path.join(
_get_fixtures_base_path(),
"fixtures",
"ping/configuration.yaml",
)
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
await hass.services.async_call(
DOMAIN,
SERVICE_RELOAD,
{},
blocking=True,
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1
assert hass.states.get("binary_sensor.test") is None
assert hass.states.get("binary_sensor.test2")
def _get_fixtures_base_path():
return path.dirname(path.dirname(path.dirname(__file__)))
binary_sensor:
- platform: ping
name: test2
host: 127.0.0.1
count: 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment