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

bug fixes #81

merged 7 commits into from
Feb 8, 2021

Conversation

rotem925
Copy link
Contributor

@rotem925 rotem925 commented Feb 8, 2021

Hi @deiger
Please see my commits for more details.
As you already know, I have 8 ACs here, and AirCon was dead slow when it was running through the status update.
Tested everything and it seems to work as it should.
You may merge it if you like.
I'm pretty satisfied with the outcome.
Now when the system loads and the status updates are running, I can send a command to the AC, before that, it was long in the queue.

Copy link
Owner

@deiger deiger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, please see the comments.

await asyncio.sleep(_STATUS_UPDATE_INTERVAL)

async def query_status_worker(devices: [Device]):
await asyncio.gather(*(query_status_device(device)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't really have anything to gather here, use asyncio.wait instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -116,9 +116,14 @@ 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.ClientConnectionError as e:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do:
except (aiohttp.client_exceptions.ClientConnectionError, aiohttp.client_exceptions.ClientConnectorError) as e:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

aircon/aircon.py Outdated
for data_field in fields(self._properties):
while self.commands_queue.qsize() > 0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been a real issue?
The current implementation is pretty much a busy loop.
A cleaner option would be to just use a queue.PriorityQueue, that will contain something like:

@dataclass(order=True)
class Command:
  priority: int
  timestamp: int
  command: Dict=field(compare=False)
  updater: Callable=field(compare=False)

(The timestamp should get time.time_ns(), it's there to maintain order for equal priority commands).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the first issue I tried to solve.
When that busy loops run, you can't issue any command. And that happens every 10 minutes.
The solution I had, gave priority to other commands than the status.
PriorityQueue, I don't familiar with... It just has to give more priority to commands other than the status update.
You will still have to control the order of the commands.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so the idea is to use queue.PriorityQueue instead of queue.Queue, and set the priority to e.g. 10 for "normal" commands, and 100 for these status updates. Then any normal command will be prioritized over the status updates.
The queue orders the elements by a using __lt__, which is implemented by dataclass in field order (skipping fields with compare=False) - so just setting the correct values will do the right thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please merge this and change it? I think you're gonna handle this better and faster than me :) Meantime I try to investigate another issue I see with some of the AC which does not report the correct value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can do it. but let's revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, reverted.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've submitted 834fab2 for this, you can try it out - didn't get a chance to test it yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :) it works as expected 👍

deiger added a commit that referenced this pull request Feb 8, 2021
@deiger deiger merged commit c3bc451 into deiger:master Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants