Repository: SebRut/pygrocy
Pull request #240 (2022-06-12 18:45:19)

Add support for skipping chores
## Description

Add support for skipping chores. The default behavior remains unchanged.

**Related issue (if applicable):**

As requested in https://github.com/custom-components/grocy/issues/224.

## Checklist
  - [x] The code change is tested and works locally.
  - [x] tests pass. **Your PR won't be merged unless tests pass**
  - [x] There is no commented out code in this PR



Patch:
diff --git a/pygrocy/grocy.py b/pygrocy/grocy.py
index 58caf5f..23ac646 100644
--- a/pygrocy/grocy.py
+++ b/pygrocy/grocy.py
@@ -123,8 +123,9 @@ class Grocy(object):
         chore_id: int,
         done_by: int = None,
         tracked_time: datetime = datetime.now(),
+        skipped: bool = False,
     ):
-        return self._api_client.execute_chore(chore_id, done_by, tracked_time)
+        return self._api_client.execute_chore(chore_id, done_by, tracked_time, skipped)
 
     def chore(self, chore_id: int) -> Chore:
         resp = self._api_client.get_chore(chore_id)
diff --git a/pygrocy/grocy_api_client.py b/pygrocy/grocy_api_client.py
index da2cd9a..314a1e5 100644
--- a/pygrocy/grocy_api_client.py
+++ b/pygrocy/grocy_api_client.py
@@ -394,10 +394,14 @@ class GrocyApiClient(object):
         chore_id: int,
         done_by: int = None,
         tracked_time: datetime = datetime.now(),
+        skipped: bool = False,
     ):
         localized_tracked_time = localize_datetime(tracked_time)
 
-        data = {"tracked_time": localized_tracked_time.isoformat()}
+        data = {
+            "tracked_time": localized_tracked_time.isoformat(),
+            "skipped": skipped,
+        }
 
         if done_by is not None:
             data["done_by"] = done_by


Test patch:
diff --git a/test/test_chores.py b/test/test_chores.py
index 030fda7..da98736 100644
--- a/test/test_chores.py
+++ b/test/test_chores.py
@@ -51,7 +51,9 @@ class TestChores:
 
     @pytest.mark.vcr
     def test_execute_chore_valid_with_data(self, grocy):
-        result = grocy.execute_chore(1, done_by=1, tracked_time=datetime.now())
+        result = grocy.execute_chore(
+            1, done_by=1, tracked_time=datetime.now(), skipped=False
+        )
         assert not isinstance(result, GrocyError)
 
     @pytest.mark.vcr
diff --git a/test/test_grocy.py b/test/test_grocy.py
index c758942..95f4b4e 100644
--- a/test/test_grocy.py
+++ b/test/test_grocy.py
@@ -301,12 +301,14 @@ class TestGrocy(TestCase):
     @responses.activate
     def test_execute_chore_valid(self):
         responses.add(responses.POST, f"{self.base_url}/chores/1/execute", status=200)
-        self.assertIsNone(self.grocy.execute_chore(1, 1, self.date_test))
+        self.assertIsNone(self.grocy.execute_chore(1, 1, self.date_test, False))
 
     @responses.activate
     def test_execute_chore_error(self):
         responses.add(responses.POST, f"{self.base_url}/chores/1/execute", status=400)
-        self.assertRaises(GrocyError, self.grocy.execute_chore, 1, 1, self.date_test)
+        self.assertRaises(
+            GrocyError, self.grocy.execute_chore, 1, 1, self.date_test, False
+        )
 
     @responses.activate
     def test_get_meal_plan(self):