mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-16 12:24:30 +02:00
fixed switch control
This commit is contained in:
parent
727a075dbb
commit
eae9fd7e2d
1 changed files with 68 additions and 68 deletions
|
@ -74,27 +74,27 @@ class MikrotikSwitch(MikrotikEntity, SwitchEntity, RestoreEntity):
|
||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = self.entity_description.data_reference
|
param = self.entity_description.data_reference
|
||||||
value = self._data[self.entity_description.data_reference]
|
value = self._data[self.entity_description.data_reference]
|
||||||
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, False)
|
self.coordinator.set_value(path, param, value, mod_param, False)
|
||||||
await self._ctrl.force_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_turn_off(self) -> None:
|
async def async_turn_off(self) -> None:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = self.entity_description.data_reference
|
param = self.entity_description.data_reference
|
||||||
value = self._data[self.entity_description.data_reference]
|
value = self._data[self.entity_description.data_reference]
|
||||||
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.coordinator.set_value(path, param, value, mod_param, True)
|
||||||
await self._ctrl.async_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -140,7 +140,7 @@ class MikrotikPortSwitch(MikrotikSwitch):
|
||||||
|
|
||||||
async def async_turn_on(self) -> Optional[str]:
|
async def async_turn_on(self) -> Optional[str]:
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
|
@ -152,17 +152,17 @@ class MikrotikPortSwitch(MikrotikSwitch):
|
||||||
param = "name"
|
param = "name"
|
||||||
value = self._data[self.entity_description.data_reference]
|
value = self._data[self.entity_description.data_reference]
|
||||||
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, False)
|
self.coordinator.set_value(path, param, value, mod_param, False)
|
||||||
|
|
||||||
if "poe-out" in self._data and self._data["poe-out"] == "off":
|
if "poe-out" in self._data and self._data["poe-out"] == "off":
|
||||||
path = "/interface/ethernet"
|
path = "/interface/ethernet"
|
||||||
self._ctrl.set_value(path, param, value, "poe-out", "auto-on")
|
self.coordinator.set_value(path, param, value, "poe-out", "auto-on")
|
||||||
|
|
||||||
await self._ctrl.force_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_turn_off(self) -> Optional[str]:
|
async def async_turn_off(self) -> Optional[str]:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
|
@ -174,13 +174,13 @@ class MikrotikPortSwitch(MikrotikSwitch):
|
||||||
param = "name"
|
param = "name"
|
||||||
value = self._data[self.entity_description.data_reference]
|
value = self._data[self.entity_description.data_reference]
|
||||||
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.coordinator.set_value(path, param, value, mod_param, True)
|
||||||
|
|
||||||
if "poe-out" in self._data and self._data["poe-out"] == "auto-on":
|
if "poe-out" in self._data and self._data["poe-out"] == "auto-on":
|
||||||
path = "/interface/ethernet"
|
path = "/interface/ethernet"
|
||||||
self._ctrl.set_value(path, param, value, "poe-out", "off")
|
self.coordinator.set_value(path, param, value, "poe-out", "off")
|
||||||
|
|
||||||
await self._ctrl.async_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -191,43 +191,43 @@ class MikrotikNATSwitch(MikrotikSwitch):
|
||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = ".id"
|
param = ".id"
|
||||||
value = None
|
value = None
|
||||||
for uid in self._ctrl.data["nat"]:
|
for uid in self.coordinator.data["nat"]:
|
||||||
if self._ctrl.data["nat"][uid]["uniq-id"] == (
|
if self.coordinator.data["nat"][uid]["uniq-id"] == (
|
||||||
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},"
|
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},"
|
||||||
f"{self._data['in-interface']}:{self._data['dst-port']}-"
|
f"{self._data['in-interface']}:{self._data['dst-port']}-"
|
||||||
f"{self._data['out-interface']}:{self._data['to-addresses']}:{self._data['to-ports']}"
|
f"{self._data['out-interface']}:{self._data['to-addresses']}:{self._data['to-ports']}"
|
||||||
):
|
):
|
||||||
value = self._ctrl.data["nat"][uid][".id"]
|
value = self.coordinator.data["nat"][uid][".id"]
|
||||||
|
|
||||||
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, False)
|
self.coordinator.set_value(path, param, value, mod_param, False)
|
||||||
await self._ctrl.force_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_turn_off(self) -> None:
|
async def async_turn_off(self) -> None:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = ".id"
|
param = ".id"
|
||||||
value = None
|
value = None
|
||||||
for uid in self._ctrl.data["nat"]:
|
for uid in self.coordinator.data["nat"]:
|
||||||
if self._ctrl.data["nat"][uid]["uniq-id"] == (
|
if self.coordinator.data["nat"][uid]["uniq-id"] == (
|
||||||
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},"
|
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},"
|
||||||
f"{self._data['in-interface']}:{self._data['dst-port']}-"
|
f"{self._data['in-interface']}:{self._data['dst-port']}-"
|
||||||
f"{self._data['out-interface']}:{self._data['to-addresses']}:{self._data['to-ports']}"
|
f"{self._data['out-interface']}:{self._data['to-addresses']}:{self._data['to-ports']}"
|
||||||
):
|
):
|
||||||
value = self._ctrl.data["nat"][uid][".id"]
|
value = self.coordinator.data["nat"][uid][".id"]
|
||||||
|
|
||||||
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.coordinator.set_value(path, param, value, mod_param, True)
|
||||||
await self._ctrl.async_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -238,45 +238,45 @@ class MikrotikMangleSwitch(MikrotikSwitch):
|
||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = ".id"
|
param = ".id"
|
||||||
value = None
|
value = None
|
||||||
for uid in self._ctrl.data["mangle"]:
|
for uid in self.coordinator.data["mangle"]:
|
||||||
if self._ctrl.data["mangle"][uid]["uniq-id"] == (
|
if self.coordinator.data["mangle"][uid]["uniq-id"] == (
|
||||||
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},"
|
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},"
|
||||||
f"{self._data['src-address']}:{self._data['src-port']}-"
|
f"{self._data['src-address']}:{self._data['src-port']}-"
|
||||||
f"{self._data['dst-address']}:{self._data['dst-port']},"
|
f"{self._data['dst-address']}:{self._data['dst-port']},"
|
||||||
f"{self._data['src-address-list']}-{self._data['dst-address-list']}"
|
f"{self._data['src-address-list']}-{self._data['dst-address-list']}"
|
||||||
):
|
):
|
||||||
value = self._ctrl.data["mangle"][uid][".id"]
|
value = self.coordinator.data["mangle"][uid][".id"]
|
||||||
|
|
||||||
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, False)
|
self.coordinator.set_value(path, param, value, mod_param, False)
|
||||||
await self._ctrl.force_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_turn_off(self) -> None:
|
async def async_turn_off(self) -> None:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = ".id"
|
param = ".id"
|
||||||
value = None
|
value = None
|
||||||
for uid in self._ctrl.data["mangle"]:
|
for uid in self.coordinator.data["mangle"]:
|
||||||
if self._ctrl.data["mangle"][uid]["uniq-id"] == (
|
if self.coordinator.data["mangle"][uid]["uniq-id"] == (
|
||||||
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},"
|
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},"
|
||||||
f"{self._data['src-address']}:{self._data['src-port']}-"
|
f"{self._data['src-address']}:{self._data['src-port']}-"
|
||||||
f"{self._data['dst-address']}:{self._data['dst-port']},"
|
f"{self._data['dst-address']}:{self._data['dst-port']},"
|
||||||
f"{self._data['src-address-list']}-{self._data['dst-address-list']}"
|
f"{self._data['src-address-list']}-{self._data['dst-address-list']}"
|
||||||
):
|
):
|
||||||
value = self._ctrl.data["mangle"][uid][".id"]
|
value = self.coordinator.data["mangle"][uid][".id"]
|
||||||
|
|
||||||
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.coordinator.set_value(path, param, value, mod_param, True)
|
||||||
await self._ctrl.async_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -287,43 +287,43 @@ class MikrotikFilterSwitch(MikrotikSwitch):
|
||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = ".id"
|
param = ".id"
|
||||||
value = None
|
value = None
|
||||||
for uid in self._ctrl.data["filter"]:
|
for uid in self.coordinator.data["filter"]:
|
||||||
if self._ctrl.data["filter"][uid]["uniq-id"] == (
|
if self.coordinator.data["filter"][uid]["uniq-id"] == (
|
||||||
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},{self._data['layer7-protocol']},"
|
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},{self._data['layer7-protocol']},"
|
||||||
f"{self._data['in-interface']},{self._data['in-interface-list']}:{self._data['src-address']},{self._data['src-address-list']}:{self._data['src-port']}-"
|
f"{self._data['in-interface']},{self._data['in-interface-list']}:{self._data['src-address']},{self._data['src-address-list']}:{self._data['src-port']}-"
|
||||||
f"{self._data['out-interface']},{self._data['out-interface-list']}:{self._data['dst-address']},{self._data['dst-address-list']}:{self._data['dst-port']}"
|
f"{self._data['out-interface']},{self._data['out-interface-list']}:{self._data['dst-address']},{self._data['dst-address-list']}:{self._data['dst-port']}"
|
||||||
):
|
):
|
||||||
value = self._ctrl.data["filter"][uid][".id"]
|
value = self.coordinator.data["filter"][uid][".id"]
|
||||||
|
|
||||||
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, False)
|
self.coordinator.set_value(path, param, value, mod_param, False)
|
||||||
await self._ctrl.force_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_turn_off(self) -> None:
|
async def async_turn_off(self) -> None:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = ".id"
|
param = ".id"
|
||||||
value = None
|
value = None
|
||||||
for uid in self._ctrl.data["filter"]:
|
for uid in self.coordinator.data["filter"]:
|
||||||
if self._ctrl.data["filter"][uid]["uniq-id"] == (
|
if self.coordinator.data["filter"][uid]["uniq-id"] == (
|
||||||
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},{self._data['layer7-protocol']},"
|
f"{self._data['chain']},{self._data['action']},{self._data['protocol']},{self._data['layer7-protocol']},"
|
||||||
f"{self._data['in-interface']},{self._data['in-interface-list']}:{self._data['src-address']},{self._data['src-address-list']}:{self._data['src-port']}-"
|
f"{self._data['in-interface']},{self._data['in-interface-list']}:{self._data['src-address']},{self._data['src-address-list']}:{self._data['src-port']}-"
|
||||||
f"{self._data['out-interface']},{self._data['out-interface-list']}:{self._data['dst-address']},{self._data['dst-address-list']}:{self._data['dst-port']}"
|
f"{self._data['out-interface']},{self._data['out-interface-list']}:{self._data['dst-address']},{self._data['dst-address-list']}:{self._data['dst-port']}"
|
||||||
):
|
):
|
||||||
value = self._ctrl.data["filter"][uid][".id"]
|
value = self.coordinator.data["filter"][uid][".id"]
|
||||||
|
|
||||||
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.coordinator.set_value(path, param, value, mod_param, True)
|
||||||
await self._ctrl.async_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -334,35 +334,35 @@ class MikrotikQueueSwitch(MikrotikSwitch):
|
||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = ".id"
|
param = ".id"
|
||||||
value = None
|
value = None
|
||||||
for uid in self._ctrl.data["queue"]:
|
for uid in self.coordinator.data["queue"]:
|
||||||
if self._ctrl.data["queue"][uid]["name"] == f"{self._data['name']}":
|
if self.coordinator.data["queue"][uid]["name"] == f"{self._data['name']}":
|
||||||
value = self._ctrl.data["queue"][uid][".id"]
|
value = self.coordinator.data["queue"][uid][".id"]
|
||||||
|
|
||||||
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, False)
|
self.coordinator.set_value(path, param, value, mod_param, False)
|
||||||
await self._ctrl.force_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_turn_off(self) -> None:
|
async def async_turn_off(self) -> None:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = ".id"
|
param = ".id"
|
||||||
value = None
|
value = None
|
||||||
for uid in self._ctrl.data["queue"]:
|
for uid in self.coordinator.data["queue"]:
|
||||||
if self._ctrl.data["queue"][uid]["name"] == f"{self._data['name']}":
|
if self.coordinator.data["queue"][uid]["name"] == f"{self._data['name']}":
|
||||||
value = self._ctrl.data["queue"][uid][".id"]
|
value = self.coordinator.data["queue"][uid][".id"]
|
||||||
|
|
||||||
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.coordinator.set_value(path, param, value, mod_param, True)
|
||||||
await self._ctrl.async_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -373,24 +373,24 @@ class MikrotikKidcontrolPauseSwitch(MikrotikSwitch):
|
||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = self.entity_description.data_reference
|
param = self.entity_description.data_reference
|
||||||
value = self._data[self.entity_description.data_reference]
|
value = self._data[self.entity_description.data_reference]
|
||||||
command = "resume"
|
command = "resume"
|
||||||
self._ctrl.execute(path, command, param, value)
|
self.coordinator.execute(path, command, param, value)
|
||||||
await self._ctrl.force_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_turn_off(self) -> None:
|
async def async_turn_off(self) -> None:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
if "write" not in self._ctrl.data["access"]:
|
if "write" not in self.coordinator.data["access"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
param = self.entity_description.data_reference
|
param = self.entity_description.data_reference
|
||||||
value = self._data[self.entity_description.data_reference]
|
value = self._data[self.entity_description.data_reference]
|
||||||
command = "pause"
|
command = "pause"
|
||||||
self._ctrl.execute(path, command, param, value)
|
self.coordinator.execute(path, command, param, value)
|
||||||
await self._ctrl.async_update()
|
await self.coordinator.async_refresh()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue