def save_task(self): save_json(self.hass.config.path(PERSISTENCE + "_" + self._name), [item.to_map() for item in self._tasks]) asyncio.run_coroutine_threadsafe( entity_component.async_update_entity(self.hass, self.entity_id), self.hass.loop)
def handle_complete_task(call): task_id = call.data["task_id"] done_time_str = call.data.get("done_time", None) done_time = datetime.now() if done_time_str is not None: done_time = iso8601.parse_date(done_time_str) grocy.complete_task(task_id, done_time) asyncio.run_coroutine_threadsafe( entity_component.async_update_entity(hass, "sensor.grocy_tasks"), hass.loop)
def handle_execute_chore(call): chore_id = call.data["chore_id"] done_by = call.data.get("done_by", None) tracked_time_str = call.data.get("tracked_time", None) tracked_time = datetime.now() if tracked_time_str is not None: tracked_time = iso8601.parse_date(tracked_time_str) grocy.execute_chore(chore_id, done_by, tracked_time) asyncio.run_coroutine_threadsafe( entity_component.async_update_entity(hass, "sensor.grocy_chores"), hass.loop)
async def async_complete_task_service(hass, coordinator, data): """Complete a task in Grocy.""" task_id = data[SERVICE_TASK_ID] def wrapper(): coordinator.api.complete_task(task_id) await hass.async_add_executor_job(wrapper) asyncio.run_coroutine_threadsafe( entity_component.async_update_entity(hass, "sensor.grocy_tasks"), hass.loop)
async def async_complete_task_service(hass, coordinator, data): """Complete a task in Grocy.""" task_id = data[SERVICE_TASK_ID] done_time_str = data.get(SERVICE_DONE_TIME, None) done_time = datetime.now() if done_time_str is not None and done_time_str != "": done_time = iso8601.parse_date(done_time_str) coordinator.api.complete_task(task_id, done_time) asyncio.run_coroutine_threadsafe( entity_component.async_update_entity(hass, "sensor.grocy_tasks"), hass.loop )
async def async_execute_chore_service(hass, coordinator, data): """Execute a chore in Grocy.""" chore_id = data[SERVICE_CHORE_ID] done_by = data.get(SERVICE_DONE_BY, "") def wrapper(): coordinator.api.execute_chore(chore_id, done_by) await hass.async_add_executor_job(wrapper) asyncio.run_coroutine_threadsafe( entity_component.async_update_entity(hass, "sensor.grocy_chores"), hass.loop)
async def async_execute_chore_service(hass, coordinator, data): """Execute a chore in Grocy.""" chore_id = data[SERVICE_CHORE_ID] done_by = data.get(SERVICE_DONE_BY, "") tracked_time_str = data.get(SERVICE_TRACKED_TIME, "") tracked_time = datetime.now() if tracked_time_str is not None and tracked_time_str != "": tracked_time = iso8601.parse_date(tracked_time_str) coordinator.api.execute_chore(chore_id, done_by, tracked_time) asyncio.run_coroutine_threadsafe( entity_component.async_update_entity(hass, "sensor.grocy_chores"), hass.loop )