mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-14 11:24:31 +02:00
Implemented kid-control #70
This commit is contained in:
parent
7379199d40
commit
9b4a9f8252
3 changed files with 116 additions and 10 deletions
|
@ -261,12 +261,12 @@ class MikrotikControllerOptionsFlowHandler(OptionsFlow):
|
|||
CONF_SENSOR_MANGLE, DEFAULT_SENSOR_MANGLE
|
||||
),
|
||||
): bool,
|
||||
# vol.Optional(
|
||||
# CONF_SENSOR_KIDCONTROL,
|
||||
# default=self.config_entry.options.get(
|
||||
# CONF_SENSOR_KIDCONTROL, DEFAULT_SENSOR_KIDCONTROL
|
||||
# ),
|
||||
# ): bool,
|
||||
vol.Optional(
|
||||
CONF_SENSOR_KIDCONTROL,
|
||||
default=self.config_entry.options.get(
|
||||
CONF_SENSOR_KIDCONTROL, DEFAULT_SENSOR_KIDCONTROL
|
||||
),
|
||||
): bool,
|
||||
vol.Optional(
|
||||
CONF_SENSOR_PPP,
|
||||
default=self.config_entry.options.get(
|
||||
|
|
|
@ -80,6 +80,7 @@ class MikrotikControllerData:
|
|||
"bridge_host": {},
|
||||
"arp": {},
|
||||
"nat": {},
|
||||
"kid-control": {},
|
||||
"mangle": {},
|
||||
"ppp_secret": {},
|
||||
"ppp_active": {},
|
||||
|
@ -525,6 +526,9 @@ class MikrotikControllerData:
|
|||
if self.api.connected() and self.option_sensor_nat:
|
||||
await self.hass.async_add_executor_job(self.get_nat)
|
||||
|
||||
if self.api.connected() and self.option_sensor_kidcontrol:
|
||||
await self.hass.async_add_executor_job(self.get_kidcontrol)
|
||||
|
||||
if self.api.connected() and self.option_sensor_mangle:
|
||||
await self.hass.async_add_executor_job(self.get_mangle)
|
||||
|
||||
|
@ -878,6 +882,35 @@ class MikrotikControllerData:
|
|||
|
||||
del self.data["mangle"][uid]
|
||||
|
||||
# ---------------------------
|
||||
# get_kidcontrol
|
||||
# ---------------------------
|
||||
def get_kidcontrol(self):
|
||||
"""Get Kid-control data from Mikrotik"""
|
||||
self.data["kid-control"] = parse_api(
|
||||
data=self.data["kid-control"],
|
||||
source=self.api.path("/ip/kid-control"),
|
||||
key="name",
|
||||
vals=[
|
||||
{"name": "name"},
|
||||
{"name": "rate-limit"},
|
||||
{"name": "mon", "default": "None"},
|
||||
{"name": "tue", "default": "None"},
|
||||
{"name": "wed", "default": "None"},
|
||||
{"name": "thu", "default": "None"},
|
||||
{"name": "fri", "default": "None"},
|
||||
{"name": "sat", "default": "None"},
|
||||
{"name": "sun", "default": "None"},
|
||||
{"name": "comment"},
|
||||
{
|
||||
"name": "enabled",
|
||||
"source": "disabled",
|
||||
"type": "bool",
|
||||
"reverse": True,
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
# ---------------------------
|
||||
# get_ppp
|
||||
# ---------------------------
|
||||
|
|
|
@ -59,6 +59,17 @@ DEVICE_ATTRIBUTES_PPP_SECRET = [
|
|||
"encoding",
|
||||
]
|
||||
|
||||
DEVICE_ATTRIBUTES_KIDCONTROL = [
|
||||
"rate-limit",
|
||||
"mon",
|
||||
"tue",
|
||||
"wed",
|
||||
"thu",
|
||||
"fri",
|
||||
"sat",
|
||||
"sun",
|
||||
]
|
||||
|
||||
DEVICE_ATTRIBUTES_SCRIPT = [
|
||||
"last-started",
|
||||
"run-count",
|
||||
|
@ -130,13 +141,13 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
|
|||
# Add switches
|
||||
for sid, sid_uid, sid_name, sid_ref, sid_attr, sid_func in zip(
|
||||
# Data point name
|
||||
["interface", "nat", "mangle", "ppp_secret", "script", "queue"],
|
||||
["interface", "nat", "mangle", "ppp_secret", "script", "queue", "kid-control"],
|
||||
# Data point unique id
|
||||
["name", "uniq-id", "name", "name", "name", "name"],
|
||||
["name", "uniq-id", "name", "name", "name", "name", "name"],
|
||||
# Entry Name
|
||||
["name", "name", "comment", "name", "name", "name"],
|
||||
["name", "name", "comment", "name", "name", "name", "name"],
|
||||
# Entry Unique id
|
||||
["port-mac-address", "uniq-id", "name", "name", "name", "name"],
|
||||
["port-mac-address", "uniq-id", "name", "name", "name", "name", "name"],
|
||||
# Attr
|
||||
[
|
||||
DEVICE_ATTRIBUTES_IFACE,
|
||||
|
@ -145,6 +156,7 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
|
|||
DEVICE_ATTRIBUTES_PPP_SECRET,
|
||||
DEVICE_ATTRIBUTES_SCRIPT,
|
||||
DEVICE_ATTRIBUTES_QUEUE,
|
||||
DEVICE_ATTRIBUTES_KIDCONTROL,
|
||||
],
|
||||
# Switch function
|
||||
[
|
||||
|
@ -154,6 +166,7 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
|
|||
MikrotikControllerPPPSecretSwitch,
|
||||
MikrotikControllerScriptSwitch,
|
||||
MikrotikControllerQueueSwitch,
|
||||
MikrotikControllerKidcontrolSwitch,
|
||||
],
|
||||
):
|
||||
for uid in mikrotik_controller.data[sid]:
|
||||
|
@ -683,3 +696,63 @@ class MikrotikControllerQueueSwitch(MikrotikControllerSwitch):
|
|||
mod_value = True
|
||||
self._ctrl.set_value(path, param, value, mod_param, mod_value)
|
||||
await self._ctrl.async_update()
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# MikrotikControllerKidcontrolSwitch
|
||||
# ---------------------------
|
||||
class MikrotikControllerKidcontrolSwitch(MikrotikControllerSwitch):
|
||||
"""Representation of a queue switch."""
|
||||
|
||||
def __init__(self, inst, uid, mikrotik_controller, sid_data):
|
||||
"""Set up queue switch."""
|
||||
super().__init__(inst, uid, mikrotik_controller, sid_data)
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon."""
|
||||
if not self._data["enabled"]:
|
||||
icon = "mdi:account-off-outline"
|
||||
else:
|
||||
icon = "mdi:account-outline"
|
||||
|
||||
return icon
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return a queue switch description for device registry."""
|
||||
info = {
|
||||
"identifiers": {
|
||||
(
|
||||
DOMAIN,
|
||||
"serial-number",
|
||||
self._ctrl.data["routerboard"]["serial-number"],
|
||||
"switch",
|
||||
"Kidcontrol",
|
||||
)
|
||||
},
|
||||
"manufacturer": self._ctrl.data["resource"]["platform"],
|
||||
"model": self._ctrl.data["resource"]["board-name"],
|
||||
"name": f"{self._inst} Kidcontrol",
|
||||
}
|
||||
return info
|
||||
|
||||
async def async_turn_on(self):
|
||||
"""Turn on the queue switch."""
|
||||
path = "/ip/kid-control"
|
||||
param = "name"
|
||||
value = self._data["name"]
|
||||
mod_param = "disabled"
|
||||
mod_value = False
|
||||
self._ctrl.set_value(path, param, value, mod_param, mod_value)
|
||||
await self._ctrl.force_update()
|
||||
|
||||
async def async_turn_off(self):
|
||||
"""Turn on the queue switch."""
|
||||
path = "/ip/kid-control"
|
||||
param = "name"
|
||||
value = self._data["name"]
|
||||
mod_param = "disabled"
|
||||
mod_value = True
|
||||
self._ctrl.set_value(path, param, value, mod_param, mod_value)
|
||||
await self._ctrl.async_update()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue