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

Fix start timer service when only one vial installed & add additional check if specific slot is selected #25

Merged
merged 4 commits into from
Oct 3, 2023

Conversation

RobertD502
Copy link

At the moment, if no slot is specified, the start_timer service will automatically select slot 2 if a user only has one vial installed (in particular in slot 1). A Pura device that only has a vial in slot 1 will return a bay2 wearingTime of 0. As a result, if the wearingTime for bay1 is greater than 0, slot 2 will be the automatically selected slot instead of slot 1 even though no fragrance vial is installed in bay2.

Example data returned by Pura API when only bay1 slot has a fragrance vial:

'bay2': {'msg': '', 'wearingTime': 0, 'code': '', 'min': 64, 'max': 85, 'vialId': '', 'id': 0, 'activeAt': 0, 'isSmartVial': False}, 'connected': True, 'bay1': {'msg': '', 'wearingTime': 344869, 'code': 'SVA', 'min': 64, 'max': 85, 'vialId': 'e66a6e37-7259-4c7f-94b8-17455703e008', 'id': 1694623148, 'activeAt': 0, 'isSmartVial': False}

In order to get around this, if a user hasn't selected a slot:

  1. We first check to see what slots are occupied and create a installed_slots list.
  2. If determined that both bay1 and bay2 are occupied, then we compare wearingTime
  3. If only bay1 or bay2 has a vial installed, then whichever one has a vial is determined to be the automatically selected slot.
  4. In addition, a check is performed, and exception raised in the event that the user is attempting to call the start_timer on the device that has no vials installed.

If a user selects a specific slot:
An exception is raised indicating that the selected slot doesn't have a vial installed if the slot is not found in the installed_slots list.

…ompare wearingTime if 2 vials installed

**For the `start_timer` service:**

In the event that a user wishes to have the selected slot be automatically determined:

- A list is crafted of all the slots in the device that have a vial installed.
- If the device has both slots installed, then a comparison between wearingTime is done to determine which vial to automatically select.
- If only one vial is installed then this vial is selected.
- In the event that a user doesn't have any vials installed in the device and attempts to call the start_timer service, an exception is raised to indicate no vials are installed.
@RobertD502
Copy link
Author

Fixes #22.

custom_components/pura/select.py Outdated Show resolved Hide resolved
custom_components/pura/select.py Outdated Show resolved Hide resolved
…LLED exception after installed_slots list creation
@natekspencer natekspencer merged commit 255701b into natekspencer:dev Oct 3, 2023
1 check passed
@RobertD502 RobertD502 deleted the fix_start_timer_service branch October 3, 2023 21:50
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