Skip to content

Commit

Permalink
Add data drop when needed (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaskivskyi authored Nov 9, 2023
1 parent d7c705b commit 42ed7f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
38 changes: 29 additions & 9 deletions asusrouter/asusrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,19 @@ def _transform_data(self, datatype: AsusData, data: Any) -> Any:

return data

def _drop_data(self, datatype: AsusData, endpoint: Endpoint) -> bool:
"""Check whether data should be dropped. This is required
for some data obtained from multiple endpoints."""

if not self._identity:
return False

if datatype == AsusData.OPENVPN_CLIENT:
if self._identity.merlin is True:
return endpoint == Endpoint.HOOK

return False

def _check_state(self, datatype: Optional[AsusData]) -> None:
"""Make sure the state object is available."""

Expand Down Expand Up @@ -513,17 +526,24 @@ async def async_get_data(self, datatype: AsusData, force: bool = False) -> Any:
if not self._identity:
self._identity = await self.async_get_identity()

result = merge_dicts(
result,
process(
endpoint,
data,
self._state,
self._identity.firmware,
self._identity.wlan,
),
processed = process(
endpoint,
data,
self._state,
self._identity.firmware,
self._identity.wlan,
)

# Check whether data should be dropped
to_drop = []
for key, value in processed.items():
if self._drop_data(key, endpoint):
to_drop.append(key)
for key in to_drop:
processed.pop(key, None)

result = merge_dicts(result, processed)

# Check if we have data and data finder merge is ANY
if result and data_finder.merge == AsusDataMerge.ANY:
break
Expand Down
2 changes: 1 addition & 1 deletion asusrouter/modules/endpoint/hook_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from asusrouter.modules.ip_address import read_dns_ip_address, read_ip_address_type
from asusrouter.modules.openvpn import AsusOVPNServer
from asusrouter.modules.wireguard import AsusWireGuardServer
from asusrouter.modules.wireguard import AsusWireGuardClient, AsusWireGuardServer
from asusrouter.tools.converters import (
safe_bool,
safe_int,
Expand Down

0 comments on commit 42ed7f3

Please sign in to comment.