Skip to content

Commit

Permalink
Formatting and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsreiter committed Sep 23, 2024
1 parent 1405218 commit 0fb6326
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions custom_components/inventory_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from homeassistant.helpers.entity import DeviceInfo
from .const import (
CONF_ITEM_NAME,
CONF_ITEM_UNIT,
CONF_ITEM_MAX_CONSUMPTION,
CONF_ITEM_SIZE,
CONF_ITEM_VENDOR,
DOMAIN,
Expand Down Expand Up @@ -109,6 +107,7 @@ def _generate_entity_config(self, entity_type: InventoryManagerEntityType) -> di
}

def take_dose(self, dose: InventoryManagerEntityType) -> None:
"""Consume one dose."""
if dose not in [
InventoryManagerEntityType.MORNING,
InventoryManagerEntityType.NOON,
Expand All @@ -121,13 +120,15 @@ def take_dose(self, dose: InventoryManagerEntityType) -> None:
self.take_number(amount)

def take_number(self, number: int) -> None:
"""Consume specified number."""
if number != 0:
self.set(
InventoryManagerEntityType.SUPPLY,
self.get(InventoryManagerEntityType.SUPPLY) - number,
)

def set(self, spec: InventoryManagerEntityType, val: float) -> None:
"""Set one number."""
if val < 0:
self._numbers[spec] = 0.0
else:
Expand All @@ -143,9 +144,11 @@ def set(self, spec: InventoryManagerEntityType, val: float) -> None:
_LOGGER.debug("%s cannot be updated yet", et)

def get(self, entity_type: InventoryManagerEntityType) -> float:
"""Get number."""
return self._numbers.setdefault(entity_type, 0)

def days_remaining(self) -> float:
"""Calculate days remaining."""
supply = self.get(InventoryManagerEntityType.SUPPLY)
daily = self.daily_consumption()
if daily > 0:
Expand Down

0 comments on commit 0fb6326

Please sign in to comment.