Skip to content

Commit 8ed518b

Browse files
added get_app()
1 parent 2f9ed05 commit 8ed518b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

chirpstack_api_wrapper/client.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,41 @@ def list_tenants(self) -> dict:
167167
except grpc.RpcError as e:
168168
return self.refresh_token(e, self.list_tenants)
169169

170+
def get_app(self,app_id: str) -> dict:
171+
"""
172+
Get application.
173+
174+
Params:
175+
- app_id: unique identifier of the app.
176+
Passing in an Application object will also work.
177+
"""
178+
client = api.ApplicationServiceStub(self.channel)
179+
180+
# Define the JWT key metadata.
181+
metadata = [("authorization", "Bearer %s" % self.auth_token)]
182+
183+
#Construct request
184+
req = api.GetApplicationRequest()
185+
req.id = str(app_id)
186+
187+
try:
188+
return client.Get(req, metadata=metadata)
189+
except grpc.RpcError as e:
190+
191+
status_code = e.code()
192+
details = e.details()
193+
194+
if status_code == grpc.StatusCode.NOT_FOUND:
195+
logging.error("ChirpstackClient.get_app(): The application does not exist")
196+
logging.error(f" Details: {details}")
197+
elif status_code == grpc.StatusCode.UNAUTHENTICATED:
198+
return self.refresh_token(e, self.get_app, app_id)
199+
else:
200+
logging.error(f"ChirpstackClient.get_app(): An error occurred with status code {status_code}")
201+
logging.error(f" Details: {details}")
202+
203+
return {}
204+
170205
def get_device(self, dev_eui: str) -> dict:
171206
"""
172207
Get device.

0 commit comments

Comments
 (0)