OTBR homeassistant_hardware platform

This commit is contained in:
puddly
2025-01-27 12:21:50 -05:00
parent a3d5571abd
commit 83f7a6dbd8
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
"""Home Assistant Hardware firmware utilities."""
from __future__ import annotations
import voluptuous as vol
from yarl import URL
from homeassistant.components.hassio import valid_addon
from homeassistant.components.homeassistant_hardware.util import (
ApplicationType,
FirmwareInfo,
OwningAddon,
OwningIntegration,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.hassio import is_hassio
from . import OTBRConfigEntry
from .const import DOMAIN
async def get_firmware_info(
hass: HomeAssistant, config_entry: OTBRConfigEntry
) -> FirmwareInfo | None:
"""Return firmware information for the OpenThread Border Router."""
device = config_entry.data["device"]
if device is None:
return None
owners: list[OwningIntegration | OwningAddon] = [
OwningIntegration(config_entry_id=config_entry.entry_id)
]
if is_hassio(hass) and (host := URL(config_entry.data["url"]).host) is not None:
try:
valid_addon(host)
except vol.Invalid:
pass
else:
owners.append(OwningAddon(slug=host))
try:
firmware_version = await config_entry.runtime_data.get_coprocessor_version()
except HomeAssistantError:
firmware_version = None
return FirmwareInfo(
device=device,
firmware_type=ApplicationType.SPINEL,
firmware_version=firmware_version,
source=DOMAIN,
owners=owners,
)

View File

@@ -163,6 +163,11 @@ class OTBRData:
"""Get extended address (EUI-64)."""
return await self.api.get_extended_address()
@_handle_otbr_error
async def get_coprocessor_version(self) -> str:
"""Get coprocessor firmware version."""
return await self.api.get_coprocessor_version()
async def get_allowed_channel(hass: HomeAssistant, otbr_url: str) -> int | None:
"""Return the allowed channel, or None if there's no restriction."""