mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-08-03 01:14:30 +02:00
added run_script service #30
This commit is contained in:
parent
46f7c582ab
commit
4e66101038
4 changed files with 23 additions and 1 deletions
|
@ -1,17 +1,22 @@
|
|||
"""Mikrotik Router integration."""
|
||||
|
||||
import logging
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from homeassistant.const import CONF_NAME
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
DATA_CLIENT,
|
||||
RUN_SCRIPT_COMMAND,
|
||||
)
|
||||
from .mikrotik_controller import MikrotikControllerData
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SCRIPT_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string})
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# async_setup
|
||||
|
@ -55,6 +60,10 @@ async def async_setup_entry(hass, config_entry):
|
|||
hass.config_entries.async_forward_entry_setup(config_entry, "switch")
|
||||
)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, RUN_SCRIPT_COMMAND, controller.run_script, schema=SCRIPT_SCHEMA
|
||||
)
|
||||
|
||||
device_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
|
@ -77,6 +86,7 @@ async def async_unload_entry(hass, config_entry):
|
|||
await hass.config_entries.async_forward_entry_unload(config_entry, "binary_sensor")
|
||||
await hass.config_entries.async_forward_entry_unload(config_entry, "device_tracker")
|
||||
await hass.config_entries.async_forward_entry_unload(config_entry, "switch")
|
||||
hass.services.async_remove(DOMAIN, RUN_SCRIPT_COMMAND)
|
||||
await controller.async_reset()
|
||||
hass.data[DOMAIN][DATA_CLIENT].pop(config_entry.entry_id)
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue