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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions custom_components/pura/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
ATTR_DURATION: Final = "duration"

ERROR_AWAY_MODE: Final = "Away mode is currently active. Return to your space or disable away mode in order to control your diffuser."
ERROR_NO_SLOTS_INSTALLED: Final = "Pura is reporting that no fragrance vials are installed."
15 changes: 12 additions & 3 deletions custom_components/pura/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
async_get_current_platform,
)

from .const import ATTR_DURATION, ATTR_INTENSITY, ATTR_SLOT, DOMAIN, ERROR_AWAY_MODE
from .const import ATTR_DURATION, ATTR_INTENSITY, ATTR_SLOT, DOMAIN, ERROR_AWAY_MODE, ERROR_NO_SLOTS_INSTALLED
from .coordinator import PuraDataUpdateCoordinator
from .entity import PuraEntity, has_fragrance
from .helpers import get_device_id
Expand Down Expand Up @@ -118,10 +118,19 @@ async def async_start_timer(
self, *, slot: int | None = None, intensity: int, duration: timedelta
) -> None:
"""Start a fragrance timer."""
device = self.get_device()
installed_slots: list[int] = [i for i in (1,2) if has_fragrance(device, i)]
if not installed_slots:
raise PuraApiException(ERROR_NO_SLOTS_INSTALLED)
if not slot:
device = self.get_device()
runtime = "wearingTime"
slot = 1 if device["bay1"][runtime] <= device["bay2"][runtime] else 2
if len(installed_slots) == 2:
slot = 1 if device["bay1"][runtime] <= device["bay2"][runtime] else 2
else:
slot = installed_slots[0]
else:
if slot not in installed_slots:
raise PuraApiException(f'Slot {slot} does not have a fragrance vial installed')

if await self.hass.async_add_executor_job(
functools.partial(
Expand Down