mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Remove outdated HAOS check from bluetooth (#93809)
This commit is contained in:
parent
105608792e
commit
17d1c0733d
@ -6,7 +6,6 @@ import logging
|
|||||||
import platform
|
import platform
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from awesomeversion import AwesomeVersion
|
|
||||||
from bleak_retry_connector import BleakSlotManager
|
from bleak_retry_connector import BleakSlotManager
|
||||||
from bluetooth_adapters import (
|
from bluetooth_adapters import (
|
||||||
ADAPTER_ADDRESS,
|
ADAPTER_ADDRESS,
|
||||||
@ -25,12 +24,8 @@ from bluetooth_adapters import (
|
|||||||
from home_assistant_bluetooth import BluetoothServiceInfo, BluetoothServiceInfoBleak
|
from home_assistant_bluetooth import BluetoothServiceInfo, BluetoothServiceInfoBleak
|
||||||
|
|
||||||
from homeassistant.components import usb
|
from homeassistant.components import usb
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import SOURCE_INTEGRATION_DISCOVERY, ConfigEntry
|
||||||
SOURCE_IGNORE,
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
SOURCE_INTEGRATION_DISCOVERY,
|
|
||||||
ConfigEntry,
|
|
||||||
)
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
|
|
||||||
from homeassistant.core import Event, HassJob, HomeAssistant, callback as hass_callback
|
from homeassistant.core import Event, HassJob, HomeAssistant, callback as hass_callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
@ -40,11 +35,7 @@ from homeassistant.helpers import (
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
from homeassistant.helpers.issue_registry import (
|
from homeassistant.helpers.issue_registry import async_delete_issue
|
||||||
IssueSeverity,
|
|
||||||
async_create_issue,
|
|
||||||
async_delete_issue,
|
|
||||||
)
|
|
||||||
from homeassistant.loader import async_get_bluetooth
|
from homeassistant.loader import async_get_bluetooth
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
@ -121,8 +112,6 @@ __all__ = [
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
RECOMMENDED_MIN_HAOS_VERSION = AwesomeVersion("9.0.dev0")
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
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)
|
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:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the bluetooth integration."""
|
"""Set up the bluetooth integration."""
|
||||||
integration_matcher = IntegrationMatcher(await async_get_bluetooth(hass))
|
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())
|
EVENT_HOMEASSISTANT_STOP, hass_callback(lambda event: cancel())
|
||||||
)
|
)
|
||||||
|
|
||||||
# Wait to check until after start to make sure
|
async_delete_issue(hass, DOMAIN, "haos_outdated")
|
||||||
# that the system info is available.
|
|
||||||
hass.bus.async_listen_once(
|
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
|
||||||
hass_callback(lambda event: _async_check_haos(hass)),
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"domain": "bluetooth",
|
"domain": "bluetooth",
|
||||||
"name": "Bluetooth",
|
"name": "Bluetooth",
|
||||||
"after_dependencies": ["hassio"],
|
|
||||||
"codeowners": ["@bdraco"],
|
"codeowners": ["@bdraco"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": ["logger", "usb"],
|
"dependencies": ["logger", "usb"],
|
||||||
|
@ -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": {
|
"config": {
|
||||||
"flow_title": "{name}",
|
"flow_title": "{name}",
|
||||||
"step": {
|
"step": {
|
||||||
|
@ -8,7 +8,6 @@ from bleak import BleakError
|
|||||||
from bleak.backends.scanner import AdvertisementData, BLEDevice
|
from bleak.backends.scanner import AdvertisementData, BLEDevice
|
||||||
from bluetooth_adapters import DEFAULT_ADDRESS
|
from bluetooth_adapters import DEFAULT_ADDRESS
|
||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
|
||||||
|
|
||||||
from homeassistant.components import bluetooth
|
from homeassistant.components import bluetooth
|
||||||
from homeassistant.components.bluetooth import (
|
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
|
assert len(hass.config_entries.flow.async_progress(DOMAIN)) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_issue_outdated_haos(
|
async def test_issue_outdated_haos_removed(
|
||||||
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(
|
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_bleak_scanner_start: MagicMock,
|
mock_bleak_scanner_start: MagicMock,
|
||||||
no_adapters: None,
|
no_adapters: None,
|
||||||
operating_system_85: None,
|
operating_system_85: None,
|
||||||
) -> 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, {})
|
assert await async_setup_component(hass, bluetooth.DOMAIN, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user