feat: add multiple records in one request
This commit is contained in:
34
main.py
34
main.py
@@ -17,15 +17,22 @@ router = AsusRouter(
|
||||
use_ssl=credentials.get('use_ssl', False)
|
||||
)
|
||||
|
||||
async def main(rule_name):
|
||||
# Start connection to router
|
||||
existing_rules = []
|
||||
new_rules = []
|
||||
|
||||
async def main(rule_tag, new_ip):
|
||||
|
||||
global existing_rules
|
||||
global new_rules
|
||||
await router.async_connect()
|
||||
|
||||
# Get port forwarding rules
|
||||
pfwd = await router.async_get_data(AsusData.PORT_FORWARDING)
|
||||
|
||||
# Store existing rules that match tag
|
||||
for rule in pfwd['rules']:
|
||||
if(rule_name in rule.name):
|
||||
rules = [
|
||||
if rule_tag in rule.name:
|
||||
existing_rules += [
|
||||
PortForwardingRule(
|
||||
name=rule.name,
|
||||
ip_address=rule.ip_address,
|
||||
@@ -35,12 +42,21 @@ async def main(rule_name):
|
||||
port_external=rule.port_external
|
||||
)
|
||||
]
|
||||
result = await router.async_remove_port_forwarding_rules(rules=rules)
|
||||
print(result)
|
||||
new_rules += [
|
||||
PortForwardingRule(
|
||||
name=rule.name,
|
||||
ip_address=rule.ip_address,
|
||||
port=rule.port,
|
||||
protocol=rule.protocol,
|
||||
ip_external=new_ip,
|
||||
port_external=rule.port_external
|
||||
)
|
||||
]
|
||||
|
||||
result = await router.async_set_port_forwarding_rules(new_rules)
|
||||
if result:
|
||||
print("New records set.")
|
||||
|
||||
# End connection to router
|
||||
await router.async_disconnect()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main(""))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user