|
12 | 12 | AddRoleRequest, |
13 | 13 | APIKeyWithAuthorizations, |
14 | 14 | AppServiceStub, |
| 15 | + AuthenticatorInfo, |
15 | 16 | Authorization, |
16 | 17 | AuthorizedPermissions, |
17 | 18 | ChangeRoleRequest, |
|
49 | 50 | DeleteRobotRequest, |
50 | 51 | ) |
51 | 52 | from viam.proto.app import Fragment as FragmentPB |
| 53 | +from viam.proto.app import FragmentHistoryEntry as FragmentHistoryEntryPB |
52 | 54 | from viam.proto.app import FragmentVisibility as FragmentVisibilityPB |
53 | 55 | from viam.proto.app import ( |
| 56 | + GetFragmentHistoryRequest, |
| 57 | + GetFragmentHistoryResponse, |
54 | 58 | GetFragmentRequest, |
55 | 59 | GetFragmentResponse, |
56 | 60 | GetLocationRequest, |
@@ -383,6 +387,44 @@ def proto(self) -> FragmentPB: |
383 | 387 | ) |
384 | 388 |
|
385 | 389 |
|
| 390 | +class FragmentHistoryEntry: |
| 391 | + """A class that mirrors the `FragmentHistoryEntry` proto message. |
| 392 | +
|
| 393 | + Use this class to make the attributes of a `viam.proto.app.FragmentHistoryEntry` more accessible and easier to read/interpret. |
| 394 | + """ |
| 395 | + |
| 396 | + @classmethod |
| 397 | + def from_proto(cls, fragment_history_entry: FragmentHistoryEntryPB) -> Self: |
| 398 | + """Create a `FragmentHistoryEntry` from the .proto defined `FragmentHistoryEntry`. |
| 399 | +
|
| 400 | + Args: |
| 401 | + fragment_history_entry (viam.proto.app.FragmentHistoryEntry): The object to copy from. |
| 402 | +
|
| 403 | + Returns: |
| 404 | + FragmentHistoryEntry: The `FragmentHistoryEntry`. |
| 405 | + """ |
| 406 | + self = cls() |
| 407 | + self.fragment = fragment_history_entry.fragment |
| 408 | + self.edited_on = fragment_history_entry.edited_on.ToDatetime() |
| 409 | + self.old = Fragment.from_proto(fragment_history_entry.old) |
| 410 | + self.edited_by = fragment_history_entry.edited_by |
| 411 | + return self |
| 412 | + |
| 413 | + fragment: str |
| 414 | + edited_on: datetime |
| 415 | + old: Fragment |
| 416 | + edited_by: AuthenticatorInfo |
| 417 | + |
| 418 | + @property |
| 419 | + def proto(self) -> FragmentHistoryEntryPB: |
| 420 | + return FragmentHistoryEntryPB( |
| 421 | + fragment=self.fragment, |
| 422 | + edited_on=datetime_to_timestamp(self.edited_on), |
| 423 | + edited_by=self.edited_by, |
| 424 | + old=self.old.proto if self.old else None, |
| 425 | + ) |
| 426 | + |
| 427 | + |
386 | 428 | class RobotPartHistoryEntry: |
387 | 429 | """A class that mirrors the `RobotPartHistoryEntry` proto message. |
388 | 430 |
|
@@ -1781,6 +1823,38 @@ async def delete_fragment(self, fragment_id: str) -> None: |
1781 | 1823 | request = DeleteFragmentRequest(id=fragment_id) |
1782 | 1824 | await self._app_client.DeleteFragment(request, metadata=self._metadata) |
1783 | 1825 |
|
| 1826 | + async def get_fragment_history( |
| 1827 | + self, id: str, page_token: Optional[str] = "", page_limit: Optional[int] = 10 |
| 1828 | + ) -> List[FragmentHistoryEntry]: |
| 1829 | + """Get fragment history. |
| 1830 | +
|
| 1831 | + :: |
| 1832 | +
|
| 1833 | + fragment_history = await cloud.get_fragment_history( |
| 1834 | + id = "12a12ab1-1234-5678-abcd-abcd01234567", |
| 1835 | + page_token = "pg-token", |
| 1836 | + page_limit = 10 |
| 1837 | + ) |
| 1838 | +
|
| 1839 | + Args: |
| 1840 | + id (str): ID of the fragment to fetch history for. |
| 1841 | + page_token (Optional[str]): the page token for the fragment history collection |
| 1842 | + page_limit (Optional[int]): the number of fragment history documents to return in the result. |
| 1843 | + The default page limit is 10. |
| 1844 | +
|
| 1845 | + Raises: |
| 1846 | + GRPCError: if an invalid fragment id, page token or page limit is passed. |
| 1847 | +
|
| 1848 | + Returns: |
| 1849 | + viam.app.app_client.FragmentHistoryResponse: The fragment history document(s). |
| 1850 | +
|
| 1851 | + For more information, see `Fleet Management API <https://docs.viam.com/appendix/apis/fleet/>`_. |
| 1852 | + """ |
| 1853 | + |
| 1854 | + request = GetFragmentHistoryRequest(id=id, page_token=page_token, page_limit=page_limit) |
| 1855 | + response: GetFragmentHistoryResponse = await self._app_client.GetFragmentHistory(request, metadata=self._metadata) |
| 1856 | + return [FragmentHistoryEntry.from_proto(fragment_history) for fragment_history in response.history] |
| 1857 | + |
1784 | 1858 | async def add_role( |
1785 | 1859 | self, |
1786 | 1860 | org_id: str, |
|
0 commit comments