Remove outdated HAOS check from bluetooth (#93809)

pull/93811/merge
J. Nick Koston 2023-05-30 12:41:51 -05:00 committed by GitHub
parent 105608792e
commit 17d1c0733d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 89 deletions

View File

@ -6,7 +6,6 @@ import logging
import platform
from typing import TYPE_CHECKING
from awesomeversion import AwesomeVersion
from bleak_retry_connector import BleakSlotManager
from bluetooth_adapters import (
ADAPTER_ADDRESS,
@ -25,12 +24,8 @@ from bluetooth_adapters import (
from home_assistant_bluetooth import BluetoothServiceInfo, BluetoothServiceInfoBleak
from homeassistant.components import usb
from homeassistant.config_entries import (
SOURCE_IGNORE,
SOURCE_INTEGRATION_DISCOVERY,
ConfigEntry,
)
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEntry
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.core import Event, HassJob, HomeAssistant, callback as hass_callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import (
@ -40,11 +35,7 @@ from homeassistant.helpers import (
)
from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.issue_registry import (
IssueSeverity,
async_create_issue,
async_delete_issue,
)
from homeassistant.helpers.issue_registry import async_delete_issue
from homeassistant.loader import async_get_bluetooth
from . import models
@ -121,8 +112,6 @@ __all__ = [
_LOGGER = logging.getLogger(__name__)
RECOMMENDED_MIN_HAOS_VERSION = AwesomeVersion("9.0.dev0")
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
@ -133,43 +122,6 @@ async def _async_get_adapter_from_address(
return await _get_manager(hass).async_get_adapter_from_address(address)
@hass_callback
def _async_haos_is_new_enough(hass: HomeAssistant) -> bool:
"""Check if the version of Home Assistant Operating System is new enough."""
# Only warn if a USB adapter is plugged in
if not any(
entry
for entry in hass.config_entries.async_entries(DOMAIN)
if entry.source != SOURCE_IGNORE
):
return True
if (
not hass.components.hassio.is_hassio()
or not (os_info := hass.components.hassio.get_os_info())
or not (haos_version := os_info.get("version"))
or AwesomeVersion(haos_version) >= RECOMMENDED_MIN_HAOS_VERSION
):
return True
return False
@hass_callback
def _async_check_haos(hass: HomeAssistant) -> None:
"""Create or delete an the haos_outdated issue."""
if _async_haos_is_new_enough(hass):
async_delete_issue(hass, DOMAIN, "haos_outdated")
return
async_create_issue(
hass,
DOMAIN,
"haos_outdated",
is_fixable=False,
severity=IssueSeverity.WARNING,
learn_more_url="/config/updates",
translation_key="haos_outdated",
)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the bluetooth integration."""
integration_matcher = IntegrationMatcher(await async_get_bluetooth(hass))
@ -242,12 +194,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
EVENT_HOMEASSISTANT_STOP, hass_callback(lambda event: cancel())
)
# Wait to check until after start to make sure
# that the system info is available.
hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STARTED,
hass_callback(lambda event: _async_check_haos(hass)),
)
async_delete_issue(hass, DOMAIN, "haos_outdated")
return True

View File

@ -1,7 +1,6 @@
{
"domain": "bluetooth",
"name": "Bluetooth",
"after_dependencies": ["hassio"],
"codeowners": ["@bdraco"],
"config_flow": true,
"dependencies": ["logger", "usb"],

View File

@ -1,10 +1,4 @@
{
"issues": {
"haos_outdated": {
"title": "Update to Home Assistant Operating System 9.0 or later",
"description": "To improve Bluetooth reliability and performance, we highly recommend you update to version 9.0 or later of the Home Assistant Operating System."
}
},
"config": {
"flow_title": "{name}",
"step": {

View File

@ -8,7 +8,6 @@ from bleak import BleakError
from bleak.backends.scanner import AdvertisementData, BLEDevice
from bluetooth_adapters import DEFAULT_ADDRESS
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components import bluetooth
from homeassistant.components.bluetooth import (
@ -2922,35 +2921,13 @@ async def test_discover_new_usb_adapters_with_firmware_fallback_delay(
assert len(hass.config_entries.flow.async_progress(DOMAIN)) == 1
async def test_issue_outdated_haos(
hass: HomeAssistant,
mock_bleak_scanner_start: MagicMock,
one_adapter: None,
operating_system_85: None,
snapshot: SnapshotAssertion,
) -> None:
"""Test we create an issue on outdated haos."""
entry = MockConfigEntry(
domain=bluetooth.DOMAIN, data={}, unique_id="00:00:00:00:00:01"
)
entry.add_to_hass(hass)
assert await async_setup_component(hass, bluetooth.DOMAIN, {})
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
registry = async_get_issue_registry(hass)
issue = registry.async_get_issue(DOMAIN, "haos_outdated")
assert issue is not None
assert issue == snapshot
async def test_issue_outdated_haos_no_adapters(
async def test_issue_outdated_haos_removed(
hass: HomeAssistant,
mock_bleak_scanner_start: MagicMock,
no_adapters: None,
operating_system_85: None,
) -> None:
"""Test we do not create an issue on outdated haos if there are no adapters."""
"""Test we do not create an issue on outdated haos anymore."""
assert await async_setup_component(hass, bluetooth.DOMAIN, {})
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)