mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-04 06:24:32 +02:00
added option to specify router name for services
This commit is contained in:
parent
4e66101038
commit
7d0a614a86
3 changed files with 17 additions and 5 deletions
|
@ -5,7 +5,6 @@ import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.const import CONF_NAME
|
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
DATA_CLIENT,
|
DATA_CLIENT,
|
||||||
|
@ -15,7 +14,9 @@ from .mikrotik_controller import MikrotikControllerData
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SCRIPT_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string})
|
SCRIPT_SCHEMA = vol.Schema(
|
||||||
|
{vol.Required("router"): cv.string, vol.Required("script"): cv.string}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
|
@ -194,8 +194,16 @@ class MikrotikControllerData:
|
||||||
def run_script(self, name):
|
def run_script(self, name):
|
||||||
"""Run script using Mikrotik API"""
|
"""Run script using Mikrotik API"""
|
||||||
if type(name) != str:
|
if type(name) != str:
|
||||||
if CONF_NAME in name.data:
|
if "router" not in name.data:
|
||||||
name = name.data.get(CONF_NAME)
|
return
|
||||||
|
|
||||||
|
if self.config_entry.data["name"] != name.data.get("router"):
|
||||||
|
return
|
||||||
|
|
||||||
|
if "script" in name.data:
|
||||||
|
name = name.data.get("script")
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.api.run_script(name)
|
self.api.run_script(name)
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
run_script:
|
run_script:
|
||||||
description: Run script on Mikrotik
|
description: Run script on Mikrotik
|
||||||
fields:
|
fields:
|
||||||
name:
|
router:
|
||||||
|
description: Name of the router
|
||||||
|
example: "Mikrotik"
|
||||||
|
script:
|
||||||
description: Name of the script
|
description: Name of the script
|
||||||
example: "MyScript"
|
example: "MyScript"
|
Loading…
Add table
Add a link
Reference in a new issue