Skip to content

Commit

Permalink
Merge pull request #209 from Snuffy2/Remove-unused-methods---take-2
Browse files Browse the repository at this point in the history
Remove unused methods - take 2
  • Loading branch information
alexdelprete authored Sep 22, 2024
2 parents 843bc53 + 7d6e82d commit 8da05ef
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 78 deletions.
75 changes: 0 additions & 75 deletions custom_components/opnsense/pyopnsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,81 +616,6 @@ async def disable_nat_outbound_rule_by_created_time(self, created_time) -> None:
await self._restore_config_section("nat", config["nat"])
await self._filter_configure()

@_log_errors
async def get_configured_interface_descriptions(self) -> Mapping[str, Any]:
script: str = r"""
$toreturn = [
"data" => get_configured_interface_with_descr(),
];
"""
response: Mapping[str, Any] = await self._exec_php(script)
if response is None or not isinstance(response, Mapping):
_LOGGER.error(
"Invalid data returned from get_configured_interface_descriptions"
)
return {}
return response.get("data", {})

@_log_errors
async def get_gateways(self) -> Mapping[str, Any]:
# {'GW_WAN': {'interface': '<if>', 'gateway': '<ip>', 'name': 'GW_WAN', 'weight': '1', 'ipprotocol': 'inet', 'interval': '', 'descr': 'Interface wan Gateway', 'monitor': '<ip>', 'friendlyiface': 'wan', 'friendlyifdescr': 'WAN', 'isdefaultgw': True, 'attribute': 0, 'tiername': 'Default (IPv4)'}}
script: str = r"""
$gateways = new \OPNsense\Routing\Gateways(legacy_interfaces_details());
//$default_gwv4 = $gateways->getDefaultGW(return_down_gateways(), "inet");
//$default_gwv6 = $gateways->getDefaultGW(return_down_gateways(), "inet6");
$a_gateways = array_values($gateways->gatewaysIndexedByName(true, false, true));
$result = [];
if (is_iterable($a_gateways)) {
foreach ($a_gateways as $g) {
$result[$g["name"]] = $g;
}
}
$toreturn = [
"data" => $result,
];
"""
response: Mapping[str, Any] = await self._exec_php(script)
if response is None or not isinstance(response, Mapping):
_LOGGER.error("Invalid data returned from get_gateways")
return {}
return response.get("data", {})

@_log_errors
async def get_gateway(self, gateway):
gateways = await self.get_gateways()
for g in gateways.keys():
if g == gateway:
return gateways[g]

@_log_errors
async def get_gateways_status(self) -> Mapping[str, Any]:
# {'GW_WAN': {'monitorip': '<ip>', 'srcip': '<ip>', 'name': 'GW_WAN', 'delay': '0.387ms', 'stddev': '0.097ms', 'loss': '0.0%', 'status': 'online', 'substatus': 'none'}}
script: str = r"""
$toreturn = [
// function return_gateways_status($byname = false, $gways = false)
"data" => return_gateways_status(true),
];
"""
response: Mapping[str, Any] = await self._exec_php(script)
if response is None or not isinstance(response, Mapping):
_LOGGER.error("Invalid data returned from get_gateways_status")
return {}
for gateway_name, gateway in response.get("data", {}).items():
if gateway["status"] == "none":
gateway["status"] = "online"
return response.get("data", {})

@_log_errors
async def get_gateway_status(self, gateway):
gateways = await self.get_gateways_status()
for g in gateways.keys():
if g == gateway:
if gateways[g]["status"] == "none":
gateways[g]["status"] = "online"
return gateways[g]

@_log_errors
async def get_arp_table(self, resolve_hostnames=False) -> Mapping[str, Any]:
# [{'hostname': '?', 'ip-address': '<ip>', 'mac-address': '<mac>', 'interface': 'em0', 'expires': 1199, 'type': 'ethernet'}, ...]
Expand Down
3 changes: 0 additions & 3 deletions function_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
| Disable NAT Port Forward Rule | Yes | No as of 24.7 | Uses Get Config, Filter Configure and Restore Config Section. |
| Enable NAT Outbound Rule | Yes | No as of 24.7 | Uses Get Config, Filter Configure and Restore Config Section. |
| Disable NAT Outbound Rule | Yes | No as of 24.7 | Uses Get Config, Filter Configure and Restore Config Section. |
| Get Configured Interface Descriptions | Yes | | Doesn't appear to be used anymore. Probably just remove altogether. |
| Get Gateways | Yes | Yes | Doesn't appear to be used anymore. Probably just remove altogether. |
| Get Gateways Status | Yes | | Doesn't appear to be used anymore. Probably just remove altogether. |
| Get DHCP Leases | Yes | Yes | Currently not in use, but desired feature. Will need to handle both the legacy DHCP and Kea endpoints. |
| Get Device ID | Yes | Maybe | Used as Unique ID for device. It is just a random 10 digit number generated the first time it is requested. May be able to transition to using the Config Entry ID or something else as a Unique ID. |
| Get Interfaces | Yes | Yes | Uses Get Config. Can use same function that is used for the Interface data for the Telemetry data. |
Expand Down

0 comments on commit 8da05ef

Please sign in to comment.