mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-28 14:34:28 +02:00
Kid control implementation for both disable and pause #147
This commit is contained in:
parent
d373149c02
commit
052c1f1e7d
1 changed files with 99 additions and 2 deletions
|
@ -196,11 +196,32 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
|
|||
"script",
|
||||
"queue",
|
||||
"kid-control",
|
||||
"kid-control",
|
||||
],
|
||||
# Data point unique id
|
||||
["name", "uniq-id", "uniq-id", "uniq-id", "name", "name", "name", "name"],
|
||||
[
|
||||
"name",
|
||||
"uniq-id",
|
||||
"uniq-id",
|
||||
"uniq-id",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
],
|
||||
# Entry Name
|
||||
["name", "name", "name", "name", "name", "name", "name", "name"],
|
||||
[
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
],
|
||||
# Entry Unique id
|
||||
[
|
||||
"port-mac-address",
|
||||
|
@ -211,6 +232,7 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
|
|||
"name",
|
||||
"name",
|
||||
"name",
|
||||
"name",
|
||||
],
|
||||
# Attr
|
||||
[
|
||||
|
@ -222,6 +244,7 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
|
|||
DEVICE_ATTRIBUTES_SCRIPT,
|
||||
DEVICE_ATTRIBUTES_QUEUE,
|
||||
DEVICE_ATTRIBUTES_KIDCONTROL,
|
||||
DEVICE_ATTRIBUTES_KIDCONTROL,
|
||||
],
|
||||
# Switch function
|
||||
[
|
||||
|
@ -233,10 +256,14 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
|
|||
MikrotikControllerScriptSwitch,
|
||||
MikrotikControllerQueueSwitch,
|
||||
MikrotikControllerKidcontrolSwitch,
|
||||
MikrotikControllerKidcontrolPauseSwitch,
|
||||
],
|
||||
):
|
||||
for uid in mikrotik_controller.data[sid]:
|
||||
item_id = f"{inst}-{sid}-{mikrotik_controller.data[sid][uid][sid_uid]}"
|
||||
if sid_func.__name__ == "MikrotikControllerKidcontrolPauseSwitch":
|
||||
item_id = f"{inst}-kid-control-pause-{mikrotik_controller.data[sid][uid][sid_uid]}"
|
||||
|
||||
_LOGGER.debug("Updating switch %s", item_id)
|
||||
if item_id in switches:
|
||||
if switches[item_id].enabled:
|
||||
|
@ -891,6 +918,76 @@ class MikrotikControllerKidcontrolSwitch(MikrotikControllerSwitch):
|
|||
"""Initialize."""
|
||||
super().__init__(inst, uid, mikrotik_controller, sid_data)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon."""
|
||||
if not self._data["enabled"]:
|
||||
icon = "mdi:account-off"
|
||||
else:
|
||||
icon = "mdi:account"
|
||||
|
||||
return icon
|
||||
|
||||
@property
|
||||
def device_info(self) -> Dict[str, Any]:
|
||||
"""Return a 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) -> None:
|
||||
"""Turn on the 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) -> None:
|
||||
"""Turn off the 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()
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# MikrotikControllerKidcontrolPauseSwitch
|
||||
# ---------------------------
|
||||
class MikrotikControllerKidcontrolPauseSwitch(MikrotikControllerSwitch):
|
||||
"""Representation of a queue switch."""
|
||||
|
||||
def __init__(self, inst, uid, mikrotik_controller, sid_data):
|
||||
"""Initialize."""
|
||||
super().__init__(inst, uid, mikrotik_controller, sid_data)
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name."""
|
||||
return f"{self._inst} {self._sid_data['sid']} Pause {self._data[self._sid_data['sid_name']]}"
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique id for this entity."""
|
||||
return f"{self._inst.lower()}-{self._sid_data['sid']}-pause_switch-{self._data[self._sid_data['sid_ref']]}"
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if device is on."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue