Skip to content

Commit

Permalink
Create issue if OPNsense Firmware too low
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffy2 committed Sep 10, 2024
1 parent 4599a13 commit cc60608
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 53 deletions.
24 changes: 23 additions & 1 deletion custom_components/opnsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import Any, Callable

import async_timeout
from awesomeversion import AwesomeVersion
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_PASSWORD,
Expand All @@ -22,6 +23,7 @@
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.entity_registry import async_get
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
Expand All @@ -43,6 +45,7 @@
DOMAIN,
LOADED_PLATFORMS,
OPNSENSE_CLIENT,
OPNSENSE_MIN_FIRMWARE,
PLATFORMS,
SHOULD_RELOAD,
UNDO_UPDATE_LISTENER,
Expand Down Expand Up @@ -159,6 +162,26 @@ async def async_update_device_tracker_data():
# Fetch initial data so we have data when entities subscribe
await device_tracker_coordinator.async_config_entry_first_refresh()

firmware: str | None = coordinator.data.get("host_firmware_version", None)
_LOGGER.info(f"OPNsense Firmware {firmware}")

if AwesomeVersion(firmware) < AwesomeVersion(OPNSENSE_MIN_FIRMWARE):
async_create_issue(
hass,
DOMAIN,
f"opnsense_{firmware}_below_min_firmware_{OPNSENSE_MIN_FIRMWARE}",
is_fixable=False,
is_persistent=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="below_min_firmware",
translation_placeholders={
"version": VERSION,
"min_firmware": OPNSENSE_MIN_FIRMWARE,
"firmware": firmware,
},
)

await hass.config_entries.async_forward_entry_setups(entry, platforms)

service_registar = ServiceRegistrar(hass)
Expand Down Expand Up @@ -513,7 +536,6 @@ def coordinator_context(self):
def device_info(self) -> Mapping[str, Any]:
"""Device info for the firewall."""
state: Mapping[str, Any] = self.coordinator.data
# _LOGGER.debug(f"[device_info] state: {state}")
model: str = "OPNsense"
manufacturer: str = "Deciso B.V."
if state is None:
Expand Down
1 change: 1 addition & 0 deletions custom_components/opnsense/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
VERSION = "v0.2.0"
DEFAULT_USERNAME = ""
DOMAIN = "opnsense"
OPNSENSE_MIN_FIRMWARE = "24.7"

UNDO_UPDATE_LISTENER = "undo_update_listener"

Expand Down
3 changes: 0 additions & 3 deletions custom_components/opnsense/pyopnsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ def _exec_php(self, script, calling_method="") -> Mapping[str, Any]:
@_apply_timeout
@_log_errors
def get_host_firmware_version(self) -> None | str:
# return self._get_proxy().opnsense.firmware_version()
firmware_info: Mapping[str, Any] | list = self._get("/api/core/firmware/status")
# _LOGGER.debug(f"[get_host_firmware_version] firmware_info: {firmware_info}")
if not isinstance(firmware_info, Mapping):
return None
firmware: str | None = firmware_info.get("product_version", None)
Expand Down Expand Up @@ -1018,7 +1016,6 @@ def get_telemetry(self) -> Mapping[str, Any]:
firmware: str | None = self.get_host_firmware_version()
if firmware is None:
firmware: str = "24.7"
# _LOGGER.debug(f"[get_telemetry] firmware: {firmware}")
if AwesomeVersion(firmware) < AwesomeVersion("24.7"):
_LOGGER.debug(
f"[get_telemetry] Using legacy telemetry method for OPNsense < 24.7"
Expand Down
49 changes: 0 additions & 49 deletions custom_components/opnsense/strings.json

This file was deleted.

6 changes: 6 additions & 0 deletions custom_components/opnsense/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,11 @@
}
}
},
"issues": {
"below_min_firmware": {
"title": "OPNsense Firmware below Recommended Version",
"description": "Some hass-opnsense {version} functions require OPNsense firmware {min_firmware} or later. With firmware {firmware}, some functions may not work and there may be errors in the logs."
}
},
"title": "OPNsense"
}

0 comments on commit cc60608

Please sign in to comment.