Skip to content

Commit 6a3b19e

Browse files
Merge pull request #327 from amhyder/master
Add support for executing chore now
2 parents 9b09562 + 2d8149a commit 6a3b19e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: custom_components/grocy/services.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from homeassistant.config_entries import ConfigEntry
66
from homeassistant.core import HomeAssistant, ServiceCall
77
from pygrocy2.grocy import EntityType, TransactionType
8+
from datetime import datetime
89

910
from .const import ATTR_CHORES, ATTR_TASKS, DOMAIN
1011
from .coordinator import GrocyDataUpdateCoordinator
@@ -17,6 +18,7 @@
1718
SERVICE_TRANSACTION_TYPE = "transaction_type"
1819
SERVICE_CHORE_ID = "chore_id"
1920
SERVICE_DONE_BY = "done_by"
21+
SERVICE_EXECUTION_NOW = "track_execution_now"
2022
SERVICE_SKIPPED = "skipped"
2123
SERVICE_TASK_ID = "task_id"
2224
SERVICE_ENTITY_TYPE = "entity_type"
@@ -73,6 +75,7 @@
7375
{
7476
vol.Required(SERVICE_CHORE_ID): vol.Coerce(int),
7577
vol.Optional(SERVICE_DONE_BY): vol.Coerce(int),
78+
vol.Optional(SERVICE_EXECUTION_NOW): bool,
7679
vol.Optional(SERVICE_SKIPPED): bool,
7780
}
7881
)
@@ -252,13 +255,16 @@ def wrapper():
252255

253256

254257
async def async_execute_chore_service(hass, coordinator, data):
258+
should_track_now = data.get(SERVICE_EXECUTION_NOW, True)
259+
255260
"""Execute a chore in Grocy."""
256261
chore_id = data[SERVICE_CHORE_ID]
257262
done_by = data.get(SERVICE_DONE_BY, "")
263+
tracked_time = datetime.utcnow() if should_track_now else None
258264
skipped = data.get(SERVICE_SKIPPED, False)
259265

260266
def wrapper():
261-
coordinator.grocy_api.execute_chore(chore_id, done_by, skipped=skipped)
267+
coordinator.grocy_api.execute_chore(chore_id, done_by, tracked_time, skipped=skipped)
262268

263269
await hass.async_add_executor_job(wrapper)
264270
await _async_force_update_entity(coordinator, ATTR_CHORES)

Diff for: custom_components/grocy/services.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ execute_chore:
122122
description: The id of the user who executed the chore
123123
selector:
124124
text:
125+
track_execution_now:
126+
name: Execution now
127+
example: false
128+
default: true
129+
required: false
130+
description: If the chore execution should be tracked with the time now
131+
selector:
132+
boolean:
125133
skipped:
126134
name: Skip execution
127135
description: Skip next chore schedule

0 commit comments

Comments
 (0)