mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 13:45:12 +02:00
OTBR homeassistant_hardware
platform
This commit is contained in:
54
homeassistant/components/otbr/homeassistant_hardware.py
Normal file
54
homeassistant/components/otbr/homeassistant_hardware.py
Normal 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,
|
||||
)
|
@@ -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."""
|
||||
|
Reference in New Issue
Block a user