Skip to content

Commit

Permalink
additional gateway attrs
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
  • Loading branch information
travisghansen committed Feb 16, 2024
1 parent 3ddba38 commit cc0f8ce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.6.4

Released 2024-02-16

- additional attrs to gateway entites
- more defensive handling of rules

# v0.6.3

Released 2024-02-16
Expand Down
1 change: 1 addition & 0 deletions custom_components/pfsense/pypfsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@ def get_telemetry(self):
"ipsec" => [],
"gateways" => return_gateways_status(true),
"gateways_detail" => return_gateways_array(),
];
foreach($filesystems as $fs) {
Expand Down
22 changes: 22 additions & 0 deletions custom_components/pfsense/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,16 @@ def _pfsense_get_gateway(self):
break
return found

def _pfsense_get_gateway_details(self):
state = self.coordinator.data
found = None
gateway_name = self._pfsense_get_gateway_name()
for i_gateway_name in state["telemetry"]["gateways_detail"].keys():
if i_gateway_name == gateway_name:
found = state["telemetry"]["gateways_detail"][i_gateway_name]
break
return found

@property
def available(self) -> bool:
gateway = self._pfsense_get_gateway()
Expand All @@ -596,12 +606,24 @@ def available(self) -> bool:
def extra_state_attributes(self):
attributes = {}
gateway = self._pfsense_get_gateway()
gateway_detail = self._pfsense_get_gateway_details()
for attr in ["monitorip", "srcip", "substatus"]:
value = gateway[attr]
if attr == "substatus" and gateway[attr] == "none":
value = None
attributes[attr] = value

if gateway_detail:
for attr in ["weight", "isdefaultgw", "interface", "gateway"]:
if attr in gateway_detail:
value = gateway_detail[attr]
attributes[attr] = value
else:
# value is omitted when false by pfsense function
if attr == "isdefaultgw":
value = False
attributes[attr] = value

return attributes

@property
Expand Down
4 changes: 4 additions & 0 deletions custom_components/pfsense/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def process_entities_callback(hass, config_entry):
rules = dict_get(state, "config.nat.rule")
if isinstance(rules, list):
for rule in rules:
if not isinstance(rule, dict):
continue
icon = "mdi:network"
# likely only want very specific rules to manipulate from actions
enabled_default = False
Expand Down Expand Up @@ -121,6 +123,8 @@ def process_entities_callback(hass, config_entry):
rules = dict_get(state, "config.nat.outbound.rule")
if isinstance(rules, list):
for rule in rules:
if not isinstance(rule, dict):
continue
icon = "mdi:network"
# likely only want very specific rules to manipulate from actions
enabled_default = False
Expand Down

0 comments on commit cc0f8ce

Please sign in to comment.