Skip to content

Commit

Permalink
Rename 'connectionattempts' to 'retries' and modify code in eq3cli, e…
Browse files Browse the repository at this point in the history
…q3btsmart and connection accordingly.
  • Loading branch information
gmoelter committed Feb 21, 2022
1 parent be61fe4 commit 603b391
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions eq3bt/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
class BTLEConnection(btle.DefaultDelegate):
"""Representation of a BTLE Connection."""

def __init__(self, mac, iface, connection_attempts):
def __init__(self, mac, iface, retries):
"""Initialize the connection."""
btle.DefaultDelegate.__init__(self)

self._conn = None
self._mac = mac
self._iface = iface
self._callbacks = {}
self._connection_attempts = connection_attempts
self._max_conn_attempts = retries+1

This comment has been minimized.

Copy link
@rytilahti

rytilahti Feb 21, 2022

Owner

I'd keep using the retries everywhere in the code to be consistent.


def __enter__(self):
"""
Expand All @@ -35,13 +35,13 @@ def __enter__(self):
self._conn.withDelegate(self)
_LOGGER.debug("Trying to connect to %s", self._mac)

for attempt in range(self._connection_attempts):
for conn_attempt in range(1, self._max_conn_attempts+1):
try:
self._conn.connect(self._mac, iface=self._iface)
break
except btle.BTLEException as ex:
_LOGGER.warning("%s: Connection attempt #%s(%s) failed", self._mac, attempt+1, self._connection_attempts)
if attempt+1 == self._connection_attempts:
_LOGGER.warning("%s: Connection attempt #%s(%s) failed", self._mac, conn_attempt, self._max_conn_attempts)
if conn_attempt == self._max_conn_attempts:
raise

_LOGGER.debug("Connected to %s", self._mac)
Expand Down
4 changes: 2 additions & 2 deletions eq3bt/eq3btsmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TemperatureException(Exception):
class Thermostat:
"""Representation of a EQ3 Bluetooth Smart thermostat."""

def __init__(self, _mac, _iface=None, connection_cls=BTLEConnection, connection_attempts=2):
def __init__(self, _mac, _iface=None, connection_cls=BTLEConnection, retries=1):
"""Initialize the thermostat."""

self._target_temperature = Mode.Unknown
Expand All @@ -94,7 +94,7 @@ def __init__(self, _mac, _iface=None, connection_cls=BTLEConnection, connection_
self._firmware_version = None
self._device_serial = None

self._conn = connection_cls(_mac, _iface, connection_attempts)
self._conn = connection_cls(_mac, _iface, retries)
self._conn.set_callback(PROP_NTFY_HANDLE, self.handle_notification)
self._conn_error = False

Expand Down
6 changes: 3 additions & 3 deletions eq3bt/eq3cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ def validate_mac(ctx, param, mac):
@click.group(invoke_without_command=True)
@click.option('--mac', envvar="EQ3_MAC", required=True, callback=validate_mac)
@click.option('--interface', default=None)
@click.option('--connectionattempts', default=2)
@click.option('--retries', default=1)
@click.option('--debug/--normal', default=False)
@click.pass_context
def cli(ctx, mac, interface, connectionattempts, debug):
def cli(ctx, mac, interface, retries, debug):
""" Tool to query and modify the state of EQ3 BT smart thermostat. """
if debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)

thermostat = Thermostat(mac, interface, connection_attempts=connectionattempts)
thermostat = Thermostat(mac, interface, retries=retries)
thermostat.update()
ctx.obj = thermostat

Expand Down

0 comments on commit 603b391

Please sign in to comment.