Skip to content

Commit

Permalink
Remove outdated HAOS check from bluetooth (#93809)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed May 30, 2023
1 parent 1056087 commit 17d1c07
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 89 deletions.
61 changes: 4 additions & 57 deletions homeassistant/components/bluetooth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import platform
from typing import TYPE_CHECKING

from awesomeversion import AwesomeVersion
from bleak_retry_connector import BleakSlotManager
from bluetooth_adapters import (
ADAPTER_ADDRESS,
Expand All @@ -25,12 +24,8 @@
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 (
Expand All @@ -40,11 +35,7 @@
)
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
Expand Down Expand Up @@ -121,8 +112,6 @@

_LOGGER = logging.getLogger(__name__)

RECOMMENDED_MIN_HAOS_VERSION = AwesomeVersion("9.0.dev0")

CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)


Expand All @@ -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))
Expand Down Expand Up @@ -242,12 +194,7 @@ def _async_trigger_discovery() -> None:
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


Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/bluetooth/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"domain": "bluetooth",
"name": "Bluetooth",
"after_dependencies": ["hassio"],
"codeowners": ["@bdraco"],
"config_flow": true,
"dependencies": ["logger", "usb"],
Expand Down
6 changes: 0 additions & 6 deletions homeassistant/components/bluetooth/strings.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
27 changes: 2 additions & 25 deletions tests/components/bluetooth/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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 (
Expand Down Expand Up @@ -2922,35 +2921,13 @@ def _async_register_scan_request_callback(_hass, _callback):
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)
Expand Down

0 comments on commit 17d1c07

Please sign in to comment.