|
1 | 1 | import time |
2 | | -import agrirouter as ar |
3 | 2 | from agrirouter.api.enums import CapabilityType |
| 3 | +from agrirouter.api.env import Qa |
| 4 | +from agrirouter.service.parameter.authorization import AuthUrlParameter |
| 5 | +from agrirouter.service.parameter.onboarding import OnboardParameters |
| 6 | +from agrirouter.service.authorization import AuthorizationService |
4 | 7 | from agrirouter.service.dto.response.messaging import OnboardResponse |
5 | 8 | from agrirouter.service.messaging.common import MqttMessagingService, HttpMessagingService |
6 | 9 | from agrirouter.service.messaging.message_sending import ListEndpointsService, CapabilitiesService, SubscriptionService, \ |
7 | 10 | QueryHeaderService |
8 | 11 | from agrirouter.service.parameter.messaging import QueryHeaderParameters, ListEndpointsParameters, \ |
9 | 12 | CapabilitiesParameters, SubscriptionParameters |
| 13 | +from agrirouter.service.onboarding import SecuredOnboardingService |
10 | 14 | from agrirouter.api.enums import Gateways |
11 | 15 | from agrirouter.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription |
12 | 16 | from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification |
|
83 | 87 | def example_auth(): |
84 | 88 | print("Authorization...\n") |
85 | 89 |
|
86 | | - auth_params = ar.AuthUrlParameter(application_id=application_id, response_type="onboard") |
87 | | - auth_client = ar.Authorization("QA", public_key=public_key, private_key=private_key) |
| 90 | + auth_params = AuthUrlParameter(application_id=application_id, response_type="onboard") |
| 91 | + auth_client = AuthorizationService(Qa(), public_key=public_key, private_key=private_key) |
88 | 92 | auth_url = auth_client.get_auth_request_url( |
89 | 93 | auth_params) # use this url to authorize the user as described at https://docs.my-agrirouter.com/agrirouter-interface-documentation/latest/integration/authorization.html#perform-authorization |
90 | 94 | print(f"auth_url={auth_url}") |
@@ -116,11 +120,11 @@ def example_onboarding(gateway_id): |
116 | 120 |
|
117 | 121 | print("Onboarding...\n") |
118 | 122 |
|
119 | | - id_ = "urn:myapp:snr00003234" # just unique |
| 123 | + id_ = "urn:myapp:snr000032dd34" # just unique |
120 | 124 | time_zone = "+03:00" |
121 | 125 |
|
122 | | - onboarding_client = ar.SecuredOnboardingService("QA", public_key=public_key, private_key=private_key) |
123 | | - onboarding_parameters = ar.OnboardParameters(id_=id_, application_id=application_id, |
| 126 | + onboarding_client = SecuredOnboardingService(Qa(), public_key=public_key, private_key=private_key) |
| 127 | + onboarding_parameters = OnboardParameters(id_=id_, application_id=application_id, |
124 | 128 | certification_version_id=certification_version_id, |
125 | 129 | gateway_id=gateway_id, time_zone=time_zone, |
126 | 130 | reg_code=auth_data.get_decoded_token().regcode) |
@@ -154,7 +158,7 @@ def example_list_endpoints_mqtt(onboarding_response_data, foo): |
154 | 158 | list_endpoint_service = ListEndpointsService(messaging_service) |
155 | 159 |
|
156 | 160 | messaging_result = list_endpoint_service.send(list_endpoint_parameters) |
157 | | - print("Sent message: ", messaging_result) |
| 161 | + print("Sent message: ", messaging_result.messages_ids) |
158 | 162 |
|
159 | 163 | # Is needed for waiting of messaging responses from outbox |
160 | 164 | while True: |
@@ -294,6 +298,7 @@ def example_query_header_message_mqtt(onboarding_response_data, on_msg_callback) |
294 | 298 |
|
295 | 299 | # Is needed for waiting of messaging responses from outbox |
296 | 300 | while True: |
| 301 | + messaging_service.client.loop() |
297 | 302 | time.sleep(1) |
298 | 303 |
|
299 | 304 |
|
|
0 commit comments