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 a1099e2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 49 deletions.
23 changes: 23 additions & 0 deletions 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.debug(f"[async_setup_entry init] 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
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 = "25.0"

UNDO_UPDATE_LISTENER = "undo_update_listener"

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 a1099e2

Please sign in to comment.