Raise on bad update data instead of log in PassiveBluetoothDataUpdateCoordinator (#75536)

This commit is contained in:
J. Nick Koston 2022-07-21 09:44:53 -05:00 committed by GitHub
parent 8523c66bb5
commit f3c4bf571b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -261,12 +261,9 @@ class PassiveBluetoothDataUpdateCoordinator(Generic[_T]):
if not isinstance(new_data, PassiveBluetoothDataUpdate):
self.last_update_success = False # type: ignore[unreachable]
self.logger.error(
"The update_method for %s returned %s instead of a PassiveBluetoothDataUpdate",
self.name,
new_data,
raise ValueError(
f"The update_method for {self.name} returned {new_data} instead of a PassiveBluetoothDataUpdate"
)
return
if not self.last_update_success:
self.last_update_success = True

View File

@ -7,6 +7,7 @@ import time
from unittest.mock import MagicMock, patch
from home_assistant_bluetooth import BluetoothServiceInfo
import pytest
from homeassistant.components.bluetooth import BluetoothChange
from homeassistant.components.bluetooth.passive_update_coordinator import (
@ -337,7 +338,7 @@ async def test_exception_from_update_method(hass, caplog):
cancel_coordinator()
async def test_bad_data_from_update_method(hass, caplog):
async def test_bad_data_from_update_method(hass):
"""Test we handle bad data from the update method."""
run_count = 0
@ -373,9 +374,9 @@ async def test_bad_data_from_update_method(hass, caplog):
assert coordinator.available is True
# We should go unavailable once we get bad data
saved_callback(GENERIC_BLUETOOTH_SERVICE_INFO, BluetoothChange.ADVERTISEMENT)
assert "update_method" in caplog.text
assert "bad_data" in caplog.text
with pytest.raises(ValueError):
saved_callback(GENERIC_BLUETOOTH_SERVICE_INFO, BluetoothChange.ADVERTISEMENT)
assert coordinator.available is False
# We should go available again once we get good data again