Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes #81

Merged
merged 7 commits into from
Feb 8, 2021
Merged
12 changes: 7 additions & 5 deletions aircon/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@
from .query_handlers import QueryHandlers


async def query_status_worker(devices: [Device]):
async def query_status_device(device: Device):
_STATUS_UPDATE_INTERVAL = 600.0
_WAIT_FOR_EMPTY_QUEUE = 10.0
while True:
# In case the AC is stuck, and not fetching commands, avoid flooding
# the queue with status updates.
for device in devices:
while device.commands_queue.qsize() > 10:
await asyncio.sleep(_WAIT_FOR_EMPTY_QUEUE)
device.queue_status()
while device.commands_queue.qsize() > 10:
await asyncio.sleep(_WAIT_FOR_EMPTY_QUEUE)
device.queue_status()
await asyncio.sleep(_STATUS_UPDATE_INTERVAL)

async def query_status_worker(devices: [Device]):
await asyncio.wait([*(query_status_device(device)
for device in devices)])

def ParseArguments() -> argparse.Namespace:
"""Parse command line arguments."""
Expand Down
2 changes: 1 addition & 1 deletion aircon/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ def mqtt_publish_update(self, mac_address: str, property_name: str, value) -> No
else:
payload = str(value)
self.publish(self._mqtt_topics['pub'].format(mac_address, property_name),
payload=payload.encode('utf-8'))
payload=payload.encode('utf-8'), retain=True)
5 changes: 3 additions & 2 deletions aircon/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ async def _perform_request(self, session: aiohttp.ClientSession,
resp_data = await resp.text()
logging.error(f'[KeepAlive] Sending local_reg failed: {resp.status}, {resp_data}')
raise ConnectionError(f'Sending local_reg failed: {resp.status}, {resp_data}')
except aiohttp.client_exceptions.ClientConnectorError as e:
except (aiohttp.client_exceptions.ClientConnectorError, aiohttp.client_exceptions.ClientConnectionError) as e:
logging.error(f'Failed to connect to {config.device.ip_address}, maybe it is offline?')
raise ConnectionError(
f'Failed to connect to {e.host}:{e.port}, maybe it is offline? Details: {e.os_error}.')
f'Failed to connect to {config.device.ip_address}, maybe it is offline?')
config.last_timestamp = now
config.device.available = True
return queue_size