Skip to content

Commit 0ec8871

Browse files
committed
Add CONNECT_RETRIES and log failures
1 parent e51e475 commit 0ec8871

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

custom_components/eurotronic_cometblue/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Comet Blue Bluetooth integration."""
2+
23
from __future__ import annotations
34

45
from datetime import datetime
@@ -39,6 +40,7 @@
3940
]
4041
LOGGER = logging.getLogger(__name__)
4142
TIMEOUT = 20
43+
CONNECT_RETRIES = 3
4244

4345

4446
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@@ -54,7 +56,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
5456
)
5557

5658
cometblue_device = cometblue.AsyncCometBlue(
57-
device=ble_device, pin=entry.data.get(CONF_PIN), timeout=TIMEOUT, retries=1
59+
device=ble_device,
60+
pin=entry.data.get(CONF_PIN),
61+
timeout=TIMEOUT,
62+
retries=CONNECT_RETRIES,
5863
)
5964
try:
6065
async with cometblue_device:

custom_components/eurotronic_cometblue/climate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Comet Blue climate integration."""
2+
23
from __future__ import annotations
34

45
import logging

custom_components/eurotronic_cometblue/coordinator.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Provides the DataUpdateCoordinator."""
2+
23
from __future__ import annotations
34

45
from datetime import timedelta
@@ -72,8 +73,15 @@ async def send_command(
7273
while retry_count < RETRY_COUNT:
7374
try:
7475
return await getattr(self.device, function)(**payload)
75-
except (InvalidByteValueError, TimeoutError): # noqa: PERF203
76+
except (InvalidByteValueError, TimeoutError) as ex: # noqa: PERF203
7677
retry_count += 1
78+
LOGGER.info(
79+
"Retrying command '%s' to '%s' after %s (%s)",
80+
payload,
81+
caller_entity_id,
82+
type(ex).__name__,
83+
ex,
84+
)
7785
except ValueError as err:
7886
raise ServiceValidationError(
7987
f"Invalid payload '{payload}' for '{caller_entity_id}': {err}"
@@ -100,8 +108,7 @@ async def _async_update_data(self) -> dict[str, bytes]:
100108
# If one value was not retrieved correctly, keep the old value
101109
**{
102110
k: retrieved_temperatures.get(k) or self.data.get(k)
103-
for k
104-
in CONF_ALL_TEMPERATURES
111+
for k in CONF_ALL_TEMPERATURES
105112
},
106113
}
107114
# Reset failed update count if all values were retrieved correctly
@@ -110,6 +117,12 @@ async def _async_update_data(self) -> dict[str, bytes]:
110117
# allow invalid bytes until RETRY_COUNT is reached
111118
if self.failed_update_count < RETRY_COUNT and self.data:
112119
self.failed_update_count += 1
120+
LOGGER.info(
121+
"Returning old data for '%s' after %s (%s)",
122+
self.device.device.address,
123+
type(ex).__name__,
124+
ex,
125+
)
113126
return self.data
114127
raise UpdateFailed(f"Error in device response: {ex}") from ex
115128
except Exception as ex:

custom_components/eurotronic_cometblue/number.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Comet Blue number integration."""
2+
23
from __future__ import annotations
34

45
from collections.abc import Callable

custom_components/eurotronic_cometblue/sensor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Comet Blue sensor integration."""
2+
23
from __future__ import annotations
34

45
from homeassistant.components.sensor import (

custom_components/eurotronic_cometblue/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Comet Blue Bluetooth utils."""
2+
23
from __future__ import annotations
34

45
from datetime import time
@@ -36,6 +37,7 @@ def validate_half_precision(value: float) -> float:
3637
raise vol.Invalid(f"value {value} is not a float") from err
3738
return value
3839

40+
3941
def validate_cometblue_schedule(schedule: dict[str, time]) -> dict[str, time] | None:
4042
"""Validate the schedule of time ranges.
4143

0 commit comments

Comments
 (0)