mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-14 19:34:29 +02:00
crosscheck NAT .id in case of mikrotik reboot
This commit is contained in:
parent
ce98668f1e
commit
8f8817a1f7
3 changed files with 20 additions and 3 deletions
|
@ -34,6 +34,10 @@ DEVICE_ATTRIBUTES = [
|
||||||
"default-name",
|
"default-name",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# format_attribute
|
||||||
|
# ---------------------------
|
||||||
def format_attribute(attr):
|
def format_attribute(attr):
|
||||||
res = attr.replace("-", " ")
|
res = attr.replace("-", " ")
|
||||||
res = res.capitalize()
|
res = res.capitalize()
|
||||||
|
|
|
@ -347,7 +347,8 @@ class MikrotikControllerData():
|
||||||
if uid not in self.data['nat']:
|
if uid not in self.data['nat']:
|
||||||
self.data['nat'][uid] = {}
|
self.data['nat'][uid] = {}
|
||||||
|
|
||||||
self.data['nat'][uid]['name'] = entry['protocol'] + ':' + str(entry['dst-port'])
|
self.data['nat'][uid]['name'] = "{}:{}".format(entry['protocol'], entry['dst-port'])
|
||||||
|
self.data['nat'][uid]['.id'] = from_entry(entry, '.id')
|
||||||
self.data['nat'][uid]['protocol'] = from_entry(entry, 'protocol')
|
self.data['nat'][uid]['protocol'] = from_entry(entry, 'protocol')
|
||||||
self.data['nat'][uid]['dst-port'] = from_entry(entry, 'dst-port')
|
self.data['nat'][uid]['dst-port'] = from_entry(entry, 'dst-port')
|
||||||
self.data['nat'][uid]['in-interface'] = from_entry(entry, 'in-interface', 'any')
|
self.data['nat'][uid]['in-interface'] = from_entry(entry, 'in-interface', 'any')
|
||||||
|
|
|
@ -55,6 +55,10 @@ DEVICE_ATTRIBUTES_SCRIPT = [
|
||||||
"run-count",
|
"run-count",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# format_attribute
|
||||||
|
# ---------------------------
|
||||||
def format_attribute(attr):
|
def format_attribute(attr):
|
||||||
res = attr.replace("-", " ")
|
res = attr.replace("-", " ")
|
||||||
res = res.capitalize()
|
res = res.capitalize()
|
||||||
|
@ -306,7 +310,11 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
path = '/ip/firewall/nat'
|
path = '/ip/firewall/nat'
|
||||||
param = '.id'
|
param = '.id'
|
||||||
value = self._uid
|
value = None
|
||||||
|
for uid in self._ctrl.data['nat']:
|
||||||
|
if self._ctrl.data['nat'][uid]['name'] == "{}:{}".format(self._data['protocol'], self._data['dst-port']):
|
||||||
|
value = self._ctrl.data['nat'][uid]['.id']
|
||||||
|
|
||||||
mod_param = 'disabled'
|
mod_param = 'disabled'
|
||||||
mod_value = False
|
mod_value = False
|
||||||
self._ctrl.set_value(path, param, value, mod_param, mod_value)
|
self._ctrl.set_value(path, param, value, mod_param, mod_value)
|
||||||
|
@ -317,7 +325,11 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
path = '/ip/firewall/nat'
|
path = '/ip/firewall/nat'
|
||||||
param = '.id'
|
param = '.id'
|
||||||
value = self._uid
|
value = None
|
||||||
|
for uid in self._ctrl.data['nat']:
|
||||||
|
if self._ctrl.data['nat'][uid]['name'] == "{}:{}".format(self._data['protocol'], self._data['dst-port']):
|
||||||
|
value = self._ctrl.data['nat'][uid]['.id']
|
||||||
|
|
||||||
mod_param = 'disabled'
|
mod_param = 'disabled'
|
||||||
mod_value = True
|
mod_value = True
|
||||||
self._ctrl.set_value(path, param, value, mod_param, mod_value)
|
self._ctrl.set_value(path, param, value, mod_param, mod_value)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue