mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Raise on bad update data instead of log in PassiveBluetoothDataUpdateCoordinator (#75536)
This commit is contained in:
parent
8523c66bb5
commit
f3c4bf571b
@ -261,12 +261,9 @@ class PassiveBluetoothDataUpdateCoordinator(Generic[_T]):
|
|||||||
|
|
||||||
if not isinstance(new_data, PassiveBluetoothDataUpdate):
|
if not isinstance(new_data, PassiveBluetoothDataUpdate):
|
||||||
self.last_update_success = False # type: ignore[unreachable]
|
self.last_update_success = False # type: ignore[unreachable]
|
||||||
self.logger.error(
|
raise ValueError(
|
||||||
"The update_method for %s returned %s instead of a PassiveBluetoothDataUpdate",
|
f"The update_method for {self.name} returned {new_data} instead of a PassiveBluetoothDataUpdate"
|
||||||
self.name,
|
|
||||||
new_data,
|
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
if not self.last_update_success:
|
if not self.last_update_success:
|
||||||
self.last_update_success = True
|
self.last_update_success = True
|
||||||
|
@ -7,6 +7,7 @@ import time
|
|||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from home_assistant_bluetooth import BluetoothServiceInfo
|
from home_assistant_bluetooth import BluetoothServiceInfo
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.bluetooth import BluetoothChange
|
from homeassistant.components.bluetooth import BluetoothChange
|
||||||
from homeassistant.components.bluetooth.passive_update_coordinator import (
|
from homeassistant.components.bluetooth.passive_update_coordinator import (
|
||||||
@ -337,7 +338,7 @@ async def test_exception_from_update_method(hass, caplog):
|
|||||||
cancel_coordinator()
|
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."""
|
"""Test we handle bad data from the update method."""
|
||||||
run_count = 0
|
run_count = 0
|
||||||
|
|
||||||
@ -373,9 +374,9 @@ async def test_bad_data_from_update_method(hass, caplog):
|
|||||||
assert coordinator.available is True
|
assert coordinator.available is True
|
||||||
|
|
||||||
# We should go unavailable once we get bad data
|
# We should go unavailable once we get bad data
|
||||||
|
with pytest.raises(ValueError):
|
||||||
saved_callback(GENERIC_BLUETOOTH_SERVICE_INFO, BluetoothChange.ADVERTISEMENT)
|
saved_callback(GENERIC_BLUETOOTH_SERVICE_INFO, BluetoothChange.ADVERTISEMENT)
|
||||||
assert "update_method" in caplog.text
|
|
||||||
assert "bad_data" in caplog.text
|
|
||||||
assert coordinator.available is False
|
assert coordinator.available is False
|
||||||
|
|
||||||
# We should go available again once we get good data again
|
# We should go available again once we get good data again
|
||||||
|
Loading…
x
Reference in New Issue
Block a user