redo kidcontrol switches

This commit is contained in:
Tomaae 2022-02-04 21:25:01 +01:00
parent 9a799828b0
commit 64303a3297
2 changed files with 62 additions and 0 deletions

View file

@ -62,6 +62,8 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
"filter", "filter",
"ppp_secret", "ppp_secret",
"queue", "queue",
"kidcontrol_enable",
"kidcontrol_pause",
], ],
# Entity function # Entity function
[ [
@ -71,6 +73,8 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
MikrotikControllerFilterSwitch, MikrotikControllerFilterSwitch,
MikrotikControllerSwitch, MikrotikControllerSwitch,
MikrotikControllerQueueSwitch, MikrotikControllerQueueSwitch,
MikrotikControllerSwitch,
MikrotikControllerKidcontrolPauseSwitch,
], ],
): ):
uid_switch = SWITCH_TYPES[switch] uid_switch = SWITCH_TYPES[switch]
@ -551,3 +555,28 @@ class MikrotikControllerQueueSwitch(MikrotikControllerSwitch):
mod_param = self.entity_description.data_switch_parameter mod_param = self.entity_description.data_switch_parameter
self._ctrl.set_value(path, param, value, mod_param, True) self._ctrl.set_value(path, param, value, mod_param, True)
await self._ctrl.async_update() await self._ctrl.async_update()
# ---------------------------
# MikrotikControllerKidcontrolPauseSwitch
# ---------------------------
class MikrotikControllerKidcontrolPauseSwitch(MikrotikControllerSwitch):
"""Representation of a queue switch."""
async def async_turn_on(self) -> None:
"""Turn on the switch."""
path = self.entity_description.data_switch_path
param = self.entity_description.data_reference
value = self._data[self.entity_description.data_reference]
command = "resume"
self._ctrl.execute(path, command, param, value)
await self._ctrl.force_update()
async def async_turn_off(self) -> None:
"""Turn off the switch."""
path = self.entity_description.data_switch_path
param = self.entity_description.data_reference
value = self._data[self.entity_description.data_reference]
command = "pause"
self._ctrl.execute(path, command, param, value)
await self._ctrl.async_update()

View file

@ -257,4 +257,37 @@ SWITCH_TYPES = {
data_reference="name", data_reference="name",
data_attributes_list=DEVICE_ATTRIBUTES_QUEUE, data_attributes_list=DEVICE_ATTRIBUTES_QUEUE,
), ),
"kidcontrol_enable": MikrotikSwitchEntityDescription(
key="kidcontrol_enable",
name="kidcontrol",
icon_enabled="mdi:account",
icon_disabled="mdi:account-off",
entity_category=None,
ha_group="Kidcontrol",
ha_connection=DOMAIN,
ha_connection_value="Kidcontrol",
data_path="kid-control",
data_switch_path="/ip/kid-control",
data_name="name",
data_uid="name",
data_reference="name",
data_attributes_list=DEVICE_ATTRIBUTES_KIDCONTROL,
),
"kidcontrol_pause": MikrotikSwitchEntityDescription(
key="kidcontrol_paused",
name="kidcontrol paused",
icon_enabled="mdi:account-outline",
icon_disabled="mdi:account-off-outline",
entity_category=None,
ha_group="Kidcontrol",
ha_connection=DOMAIN,
ha_connection_value="Kidcontrol",
data_path="kid-control",
data_is_on="paused",
data_switch_path="/ip/kid-control",
data_name="name",
data_uid="name",
data_reference="name",
data_attributes_list=DEVICE_ATTRIBUTES_KIDCONTROL,
),
} }