|
5 | 5 | from homeassistant.config_entries import ConfigEntry
|
6 | 6 | from homeassistant.core import HomeAssistant, ServiceCall
|
7 | 7 | from pygrocy2.grocy import EntityType, TransactionType
|
| 8 | +from datetime import datetime |
8 | 9 |
|
9 | 10 | from .const import ATTR_CHORES, ATTR_TASKS, DOMAIN
|
10 | 11 | from .coordinator import GrocyDataUpdateCoordinator
|
|
17 | 18 | SERVICE_TRANSACTION_TYPE = "transaction_type"
|
18 | 19 | SERVICE_CHORE_ID = "chore_id"
|
19 | 20 | SERVICE_DONE_BY = "done_by"
|
| 21 | +SERVICE_EXECUTION_NOW = "track_execution_now" |
20 | 22 | SERVICE_SKIPPED = "skipped"
|
21 | 23 | SERVICE_TASK_ID = "task_id"
|
22 | 24 | SERVICE_ENTITY_TYPE = "entity_type"
|
|
73 | 75 | {
|
74 | 76 | vol.Required(SERVICE_CHORE_ID): vol.Coerce(int),
|
75 | 77 | vol.Optional(SERVICE_DONE_BY): vol.Coerce(int),
|
| 78 | + vol.Optional(SERVICE_EXECUTION_NOW): bool, |
76 | 79 | vol.Optional(SERVICE_SKIPPED): bool,
|
77 | 80 | }
|
78 | 81 | )
|
@@ -252,13 +255,16 @@ def wrapper():
|
252 | 255 |
|
253 | 256 |
|
254 | 257 | async def async_execute_chore_service(hass, coordinator, data):
|
| 258 | + should_track_now = data.get(SERVICE_EXECUTION_NOW, True) |
| 259 | + |
255 | 260 | """Execute a chore in Grocy."""
|
256 | 261 | chore_id = data[SERVICE_CHORE_ID]
|
257 | 262 | done_by = data.get(SERVICE_DONE_BY, "")
|
| 263 | + tracked_time = datetime.utcnow() if should_track_now else None |
258 | 264 | skipped = data.get(SERVICE_SKIPPED, False)
|
259 | 265 |
|
260 | 266 | 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) |
262 | 268 |
|
263 | 269 | await hass.async_add_executor_job(wrapper)
|
264 | 270 | await _async_force_update_entity(coordinator, ATTR_CHORES)
|
|
0 commit comments