Skip to content

Commit

Permalink
Minor code adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
natekspencer committed Oct 3, 2023
1 parent 505d1cc commit eed3fee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
1 change: 0 additions & 1 deletion custom_components/pura/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
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 = "No fragrances are installed."
26 changes: 8 additions & 18 deletions custom_components/pura/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
async_get_current_platform,
)

from .const import (
ATTR_DURATION,
ATTR_INTENSITY,
ATTR_SLOT,
DOMAIN,
ERROR_AWAY_MODE,
ERROR_NO_SLOTS_INSTALLED,
)
from .const import ATTR_DURATION, ATTR_INTENSITY, ATTR_SLOT, DOMAIN, ERROR_AWAY_MODE
from .coordinator import PuraDataUpdateCoordinator
from .entity import PuraEntity, has_fragrance
from .helpers import get_device_id
Expand Down Expand Up @@ -126,20 +119,17 @@ async def async_start_timer(
) -> None:
"""Start a fragrance timer."""
device = self.get_device()
if not (installed_slots := [i for i in (1, 2) if has_fragrance(device, i)]):
raise PuraApiException(ERROR_NO_SLOTS_INSTALLED)
if not (fragrance_bays := [i for i in (1, 2) if has_fragrance(device, i)]):
raise PuraApiException("Diffuser does not have any fragrances")

if not slot:
runtime = "wearingTime"
if len(installed_slots) == 1:
slot = installed_slots[0]
if len(fragrance_bays) == 1:
slot = fragrance_bays[0]
else:
runtime = "wearingTime"
slot = 1 if device["bay1"][runtime] <= device["bay2"][runtime] else 2

if slot not in installed_slots:
raise PuraApiException(
f"Slot {slot} does not have a fragrance vial installed"
)
elif slot not in fragrance_bays:
raise PuraApiException(f"Slot {slot} does not have a fragrance installed")

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

0 comments on commit eed3fee

Please sign in to comment.