Skip to content

Commit

Permalink
devices.py: Option to retry polling for thermostats with weak connection
Browse files Browse the repository at this point in the history
Sometimes thermostats with weak connection can be sucessfully polled
after a short while. This commit adds the option 'retry_rerun' for
such an instance.

In case polling retries fail at the first attempt, another attempt is
started after finishing all other sensors. The option effectively
doubles the number of retry attempts.

The option defaults to 'False' for backward compatibility.
  • Loading branch information
Cymaphore committed Jun 21, 2024
1 parent 92c2f6c commit 78912c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion etrv2mqtt/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def poll(self, mqtt: Mqtt):

if self._stay_connected == False:
self._device.disconnect()
return True
except btle.BTLEInternalError as e:
logger.error(e)
if self._device.is_connected():
Expand All @@ -55,6 +56,7 @@ def poll(self, mqtt: Mqtt):
logger.error(e)
if self._device.is_connected():
self._device.disconnect()
return False

def set_temperature(self, mqtt: Mqtt, temperature: float):
try:
Expand Down Expand Up @@ -84,8 +86,16 @@ def __init__(self, config: Config, deviceClass: Type[DeviceBase]):
self._mqtt.hass_birth_callback = self._hass_birth_callback

def _poll_devices(self):
rerun = []
for device in self._devices.values():
device.poll(self._mqtt)
if not device.poll(self._mqtt):
if self._config.retry_rerun:
rerun.append(device)
if len(rerun)>0:
logger.warning("Attempting re-run of failed sensors in 5 seconds")
time.sleep(5)
for device in rerun:
device.poll(self._mqtt)

def poll_forever(self) -> NoReturn:
if self._config.poll_schedule == "hour_minute":
Expand Down
5 changes: 5 additions & 0 deletions etrv2mqtt/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
"minimum": 0,
"default": 5
},
"retry_rerun": {
"type": "boolean",
"description": "Retry failed thermostats once again after the end of the queue",
"default": true
},
"stay_connected": {
"type": "boolean",
"description": "Set to true in order to leave BLE connection running after polling thermostat data or setting temperature. May drain battery.",
Expand Down

0 comments on commit 78912c3

Please sign in to comment.