|
6 | 6 | from typing import Any |
7 | 7 |
|
8 | 8 | from bleak import BleakError |
9 | | -from cometblue import AsyncCometBlue |
| 9 | +from cometblue import AsyncCometBlue, InvalidByteValueError |
10 | 10 |
|
11 | 11 | from homeassistant.components import bluetooth |
12 | 12 | from homeassistant.core import HomeAssistant |
13 | | -from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError |
| 13 | +from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError, ServiceValidationError |
14 | 14 | from homeassistant.helpers.device_registry import DeviceInfo |
15 | 15 | from homeassistant.helpers.update_coordinator import ( |
16 | 16 | CoordinatorEntity, |
@@ -65,7 +65,7 @@ async def send_command( |
65 | 65 | ) |
66 | 66 | return await getattr(self.device, function)(**payload) |
67 | 67 | except ValueError as err: |
68 | | - raise HomeAssistantError( |
| 68 | + raise ServiceValidationError( |
69 | 69 | f"Invalid payload '{payload}' for '{caller_entity_id}': {err}" |
70 | 70 | ) from err |
71 | 71 | except BleakError as err: |
@@ -94,11 +94,14 @@ async def _async_update_data(self) -> dict[str, bytes]: |
94 | 94 | in CONF_ALL_TEMPERATURES |
95 | 95 | }, |
96 | 96 | } |
97 | | - # Increase failure counter if not all values were retrieved |
98 | | - if CONF_ALL_TEMPERATURES == set(retrieved_temperatures): |
99 | | - self.failed_update_count = 0 |
100 | | - else: |
101 | | - self.failed_update_count = 1 |
| 97 | + # Reset failed update count if all values were retrieved correctly |
| 98 | + self.failed_update_count = 0 |
| 99 | + except InvalidByteValueError as ex: |
| 100 | + self.failed_update_count += 1 |
| 101 | + # allow invalid bytes once, but fail on the second invalid byte |
| 102 | + if self.failed_update_count < 1: |
| 103 | + return self.data |
| 104 | + raise UpdateFailed(f"Invalid byte value: {ex}") from ex |
102 | 105 | except Exception as ex: |
103 | 106 | self.failed_update_count += 1 |
104 | 107 | raise UpdateFailed(f"({type(ex).__name__}) {ex}") from ex |
|
0 commit comments