Skip to content

Commit

Permalink
Merge pull request #327 from amhyder/master
Browse files Browse the repository at this point in the history
Add support for executing chore now
  • Loading branch information
isabellaalstrom authored Jan 28, 2025
2 parents 9b09562 + 2d8149a commit 6a3b19e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion custom_components/grocy/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, ServiceCall
from pygrocy2.grocy import EntityType, TransactionType
from datetime import datetime

from .const import ATTR_CHORES, ATTR_TASKS, DOMAIN
from .coordinator import GrocyDataUpdateCoordinator
Expand All @@ -17,6 +18,7 @@
SERVICE_TRANSACTION_TYPE = "transaction_type"
SERVICE_CHORE_ID = "chore_id"
SERVICE_DONE_BY = "done_by"
SERVICE_EXECUTION_NOW = "track_execution_now"
SERVICE_SKIPPED = "skipped"
SERVICE_TASK_ID = "task_id"
SERVICE_ENTITY_TYPE = "entity_type"
Expand Down Expand Up @@ -73,6 +75,7 @@
{
vol.Required(SERVICE_CHORE_ID): vol.Coerce(int),
vol.Optional(SERVICE_DONE_BY): vol.Coerce(int),
vol.Optional(SERVICE_EXECUTION_NOW): bool,
vol.Optional(SERVICE_SKIPPED): bool,
}
)
Expand Down Expand Up @@ -252,13 +255,16 @@ def wrapper():


async def async_execute_chore_service(hass, coordinator, data):
should_track_now = data.get(SERVICE_EXECUTION_NOW, True)

"""Execute a chore in Grocy."""
chore_id = data[SERVICE_CHORE_ID]
done_by = data.get(SERVICE_DONE_BY, "")
tracked_time = datetime.utcnow() if should_track_now else None
skipped = data.get(SERVICE_SKIPPED, False)

def wrapper():
coordinator.grocy_api.execute_chore(chore_id, done_by, skipped=skipped)
coordinator.grocy_api.execute_chore(chore_id, done_by, tracked_time, skipped=skipped)

await hass.async_add_executor_job(wrapper)
await _async_force_update_entity(coordinator, ATTR_CHORES)
Expand Down
8 changes: 8 additions & 0 deletions custom_components/grocy/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ execute_chore:
description: The id of the user who executed the chore
selector:
text:
track_execution_now:
name: Execution now
example: false
default: true
required: false
description: If the chore execution should be tracked with the time now
selector:
boolean:
skipped:
name: Skip execution
description: Skip next chore schedule
Expand Down

0 comments on commit 6a3b19e

Please sign in to comment.