smarttyre_api
Smart Tyre API Client This module provides a client for interacting with the SmartTyre API.
1"""Smart Tyre API Client 2This module provides a client for interacting with the SmartTyre API. 3""" 4 5import json 6import secrets 7import time 8 9import requests 10 11from sign_util import SignUtil 12 13 14class SmartTyreAPI: 15 """ 16 A class to interact with the Smart Tyre API. 17 """ 18 19 def __init__(self, base_url, client_id, client_secret, sign_key): 20 """ 21 Initializes the SmartTyreAPI with the necessary credentials. 22 23 Args: 24 base_url (str): The base URL of the Smart Tyre API. 25 client_id (str): The client ID for authentication. 26 client_secret (str): The client secret for authentication. 27 sign_key (str): The signing key used to generate the signature. 28 """ 29 self.base_url = base_url 30 self.client_id = client_id 31 self.client_secret = client_secret 32 self.sign_key = sign_key 33 34 def _new_header(self, need_access_token=True): 35 if need_access_token: 36 access_token = self.get_access_token() 37 38 return { 39 "clientId": self.client_id, 40 "timestamp": str(int(time.time() * 1000)), 41 "nonce": secrets.token_hex(16), 42 "accessToken": access_token, 43 } 44 45 return { 46 "clientId": self.client_id, 47 "timestamp": str(int(time.time() * 1000)), 48 "nonce": secrets.token_hex(16), 49 } 50 51 def _new_signature(self, headers, body, params, paths): 52 return SignUtil.sign( 53 headers=headers, 54 body=body, 55 params=params, 56 paths=paths, 57 sign_key=self.sign_key, 58 ) 59 60 def _new_get_request(self, endpoint, params): 61 url = f"{self.base_url}{endpoint}" 62 headers = self._new_header() 63 headers["sign"] = self._new_signature(headers, "", params, []) 64 headers["Content-Type"] = "application/json" 65 headers["Accept"] = "application/json" 66 67 response = requests.get(url, headers=headers, params=params, timeout=20) 68 if response.status_code == 200: 69 return response.json().get("data") 70 return None 71 72 def _new_post_request( 73 self, endpoint, body, need_access_token=True, returns_data=True 74 ): 75 url = f"{self.base_url}{endpoint}" 76 headers = self._new_header(need_access_token) 77 headers["sign"] = self._new_signature(headers, body, {}, []) 78 headers["Content-Type"] = "application/json" 79 headers["Accept"] = "application/json" 80 response = requests.post(url, headers=headers, data=body, timeout=20) 81 if response.status_code == 200 and returns_data: 82 return response.json().get("data") 83 if response.status_code == 200: 84 return response.json().get("msg") 85 return None 86 87 def get_access_token(self): 88 """ 89 Obtains an access token from the Smart Tyre API. 90 91 Args: 92 base_url (str): The base URL of the Smart Tyre API. 93 client_id (str): The client ID for authentication. 94 client_secret (str): The client secret for authentication. 95 sign_key (str): The signing key used to generate the signature. 96 97 Returns: 98 The access token received from the API if available or None if the request fails. 99 """ 100 endpoint = "/smartyre/openapi/auth/oauth20/authorize" 101 102 body = { 103 "clientId": self.client_id, 104 "clientSecret": self.client_secret, 105 "grantType": "client_credentials", 106 } 107 108 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 109 110 response = self._new_post_request( 111 endpoint=endpoint, 112 body=body_str, 113 need_access_token=False, 114 ) 115 116 return response.get("accessToken") if response else None 117 118 # Vehicle Management 119 120 def add_vehicle(self, vehicle_info): 121 """ 122 Creates a new vehicle in the Smart Tyre system. 123 Args: 124 vehicle_info (dict): The information of the vehicle to be created. 125 126 The dictionary should contain: 127 128 - isTractor (int): 0 for non-tractor, 1 for tractor, 2 for trailer 129 - licensePlateNumber (str): The license plate number of the vehicle 130 - emptyWeight (str): The empty weight of the vehicle 131 - fullWeight (str): The full weight of the vehicle 132 - axleTypeId (str): The ID of the axle type 133 - modelId (str): The ID of the vehicle model 134 - orgId (str): The ID of the organization 135 - tboxId (str): The ID of the TBox. Optional 136 - vehicleChassisNumber (str): The chassis number of the vehicle. Optional 137 138 Example: 139 ```python 140 new_vehicle = { 141 "isTractor": 0, 142 "licensePlateNumber": "ABC123", 143 "emptyWeight": "1000", 144 "fullWeight": "2000", 145 "axleTypeId": "2", 146 "modelId": "31", 147 "orgId": "218" 148 } 149 ``` 150 151 Note: The vehicle_info dictionary must follow the API requirements. 152 Check the API documentation for optional fields. 153 154 Returns: 155 The response from the API if available or None if the request fails. 156 """ 157 endpoint = "/smartyre/openapi/vehicle/insert" 158 159 body_str = json.dumps(vehicle_info, separators=(",", ":"), ensure_ascii=False) 160 161 return self._new_post_request( 162 endpoint=endpoint, 163 body=body_str, 164 returns_data=False, 165 ) 166 167 def update_vehicle(self, vehicle_info): 168 """ 169 Updates an existing vehicle in the Smart Tyre system. 170 Args: 171 vehicle_info (dict): The information of the vehicle to be updated. 172 173 The dictionary should contain: 174 175 - id (str): The ID of the vehicle to be updated 176 - isTractor (int): 0 for non-tractor, 1 for tractor, 2 for trailer 177 - licensePlateNumber (str): The license plate number of the vehicle 178 - emptyWeight (str): The empty weight of the vehicle 179 - fullWeight (str): The full weight of the vehicle 180 - axleTypeId (str): The ID of the axle type 181 - modelId (str): The ID of the vehicle model 182 - orgId (str): The ID of the organization 183 - tboxId (str): The ID of the TBox. Optional 184 - vehicleChassisNumber (str): The chassis number of the vehicle. Optional 185 186 187 Example: 188 ```python 189 updated_vehicle = { 190 "id": "7609", 191 "isTractor": 0, 192 "licensePlateNumber": "XYZ789", 193 "emptyWeight": "1200", 194 "fullWeight": "2200", 195 "axleTypeId": "2", 196 "modelId": "31", 197 "orgId": "218", 198 } 199 ``` 200 Note: The vehicle_info dictionary must follow the API requirements. 201 Check the API documentation for optional fields. 202 203 Returns: 204 The response from the API if available or None if the request fails. 205 """ 206 endpoint = "/smartyre/openapi/vehicle/update" 207 208 body_str = json.dumps(vehicle_info, separators=(",", ":"), ensure_ascii=False) 209 210 return self._new_post_request( 211 endpoint=endpoint, 212 body=body_str, 213 returns_data=False, 214 ) 215 216 def get_vehicle_list(self, params=None): 217 """ 218 Obtains the list of vehicles from the Smart Tyre API. 219 Args: 220 params (dict): Optional parameters for filtering the vehicle list. 221 Example: {"page": "1", "pageSize": "10"} 222 Note: The params dictionary must follow the API requirements. 223 Returns: 224 The list of vehicles if available or None if the request fails. 225 """ 226 endpoint = "/smartyre/openapi/vehicle/list" 227 228 return self._new_get_request(endpoint, params=params) 229 230 def get_vehicle_info(self, vehicle_id): 231 """ 232 Obtains detailed information about a specific vehicle. 233 Args: 234 vehicle_id (str): The ID of the vehicle. 235 Returns: 236 The detailed information about the vehicle if available or None if the request fails. 237 """ 238 if not vehicle_id: 239 return None 240 241 endpoint = "/smartyre/openapi/vehicle/detail" 242 243 params = { 244 "vehicleId": [str(vehicle_id)], 245 } 246 247 return self._new_get_request(endpoint, params=params) 248 249 # Tire Management 250 251 def add_tire(self, tire_info): 252 """ 253 Adds a new tire to the Smart Tyre system. 254 Args: 255 tire_info (dict): The information of the tire to be added. 256 257 The dictionary should contain: 258 - tyreCode (str): The identification code of the tire 259 - tyreBrandId (str): The ID of the tire brand 260 - tyreSizeId (str): The ID of the tire size 261 - tyrePattern (str): The pattern of the tire 262 - initialTreadDepth (str): The initial tread depth of the tire 263 - orgId (str): The ID of the organization. Optional 264 - sensorId (str): The ID of the sensor. Optional 265 - totalDistance (str): The total distance of the tire (km). Optional 266 - loadIndex (str): The load index of the tire. Optional 267 - speedLevel (str): The speed level of the tire. Optional 268 - newTreadDepth (str): The new tread depth of the tire. Optional 269 270 Example: 271 ```python 272 new_tire = { 273 "tyreCode": "ABC123", 274 "tyreBrandId": "1", 275 "tyreSizeId": "121", 276 "tyrePattern": "Pattern A", 277 "initialTreadDepth": "10" 278 } 279 ``` 280 281 Note: The tire_info dictionary must follow the API requirements. 282 Check the API documentation for optional fields. 283 Returns: 284 The response from the API if available or None if the request fails. 285 """ 286 endpoint = "/smartyre/openapi/tyre/insert" 287 288 body_str = json.dumps(tire_info, separators=(",", ":"), ensure_ascii=False) 289 290 return self._new_post_request( 291 endpoint=endpoint, 292 body=body_str, 293 returns_data=False, 294 ) 295 296 def update_tire(self, tire_info): 297 """ 298 Updates an existing tire in the Smart Tyre system. 299 Args: 300 tire_info (dict): The information of the tire to be updated. 301 302 The dictionary should contain: 303 - id (str): The ID of the tire to be updated 304 - tyreCode (str): The identification code of the tire, this cannot be changed 305 - tyreBrandId (str): The ID of the tire brand 306 - tyreSizeId (str): The ID of the tire size 307 - tyrePattern (str): The pattern of the tire 308 - initialTreadDepth (str): The initial tread depth of the tire 309 - orgId (str): The ID of the organization. Optional 310 - sensorId (str): The ID of the sensor. Optional 311 - totalDistance (str): The total distance of the tire (km). Optional 312 - loadIndex (str): The load index of the tire. Optional 313 - speedLevel (str): The speed level of the tire. Optional 314 - newTreadDepth (str): The new tread depth of the tire. Optional 315 Example: 316 ```python 317 updated_tire = { 318 "id": "47414", 319 "tyreCode": "ABC123", 320 "tyreBrandId": "8", 321 "tyreSizeId": "121", 322 "tyrePattern": "Pattern B", 323 "initialTreadDepth": "12" 324 } 325 ``` 326 Note: The tire_info dictionary must follow the API requirements. 327 Check the API documentation for optional fields. 328 329 Returns: 330 The response from the API if available or None if the request fails. 331 """ 332 endpoint = "/smartyre/openapi/tyre/update" 333 334 body_str = json.dumps(tire_info, separators=(",", ":"), ensure_ascii=False) 335 return self._new_post_request( 336 endpoint=endpoint, 337 body=body_str, 338 returns_data=False, 339 ) 340 341 def get_tires_info_by_vehicle(self, vehicle_id): 342 """ 343 Obtains tire information for a specific vehicle. 344 Args: 345 vehicle_id (str): The ID of the vehicle. 346 Returns: 347 The tire information if available or None if the request fails. 348 """ 349 350 if not vehicle_id: 351 return None 352 353 endpoint = "/smartyre/openapi/vehicle/tyre/data" 354 355 body_str = json.dumps({"vehicleId": vehicle_id}, separators=(",", ":")) 356 357 return self._new_post_request( 358 endpoint=endpoint, 359 body=body_str, 360 ) 361 362 def get_tire_list(self, params=None): 363 """ 364 Obtains the list of tires from the Smart Tyre API. 365 Args: 366 params (dict): Optional parameters for filtering the tire list. 367 Example: {"page": "1", "pageSize": "10"} 368 Note: The params dictionary must follow the API requirements. 369 Returns: 370 The list of tires if available or None if the request fails. 371 """ 372 373 endpoint = "/smartyre/openapi/tyre/list" 374 375 return self._new_get_request(endpoint, params=params) 376 377 def get_tire_info(self, tire_id): 378 """ 379 Obtains detailed information about a specific tire. 380 Args: 381 tire_id (str): The ID of the tire. 382 Returns: 383 The detailed information about the tire if available or None if the request fails. 384 """ 385 endpoint = "/smartyre/openapi/tyre/detail" 386 params = { 387 "id": [str(tire_id)], 388 } 389 return self._new_get_request(endpoint, params=params) 390 391 def bind_tire_to_vehicle(self, vehicle_id, tire_code, axle_index, wheel_index): 392 """ 393 Binds a tire to a vehicle in the Smart Tyre system. 394 Args: 395 vehicle_id (str): The ID of the vehicle. 396 tire_code (str): The ID of the tire. 397 axle_index (int): The index of the axle. 398 wheel_index (int): The index of the wheel. 399 Returns: 400 The response from the API if available or None if the request fails. 401 """ 402 endpoint = "/smartyre/openapi/vehicle/tyre/bind" 403 404 body = { 405 "vehicleId": vehicle_id, 406 "tyreCode": tire_code, 407 "axleIndex": axle_index, 408 "wheelIndex": wheel_index, 409 } 410 411 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 412 413 return self._new_post_request( 414 endpoint=endpoint, 415 body=body_str, 416 returns_data=False, 417 ) 418 419 def unbind_tire_from_vehicle(self, vehicle_id, tire_id): 420 """ 421 Unbinds a tire from a vehicle in the Smart Tyre system. 422 Args: 423 vehicle_id (str): The ID of the vehicle. 424 tire_id (str): The ID of the tire. 425 Returns: 426 The response from the API if available or None if the request fails. 427 """ 428 429 endpoint = "/smartyre/openapi/vehicle/tyre/unbind" 430 body = { 431 "vehicleId": vehicle_id, 432 "tyreCode": tire_id, 433 } 434 435 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 436 return self._new_post_request( 437 endpoint=endpoint, body=body_str, returns_data=False 438 ) 439 440 # Tbox Management 441 442 def add_tbox(self, tbox_info): 443 """ 444 Adds a new TBox to the Smart Tyre system. 445 Args: 446 tbox_info (dict): The information of the TBox to be added. 447 448 The dictionary should contain: 449 - tboxCode (str): The identification code of the TBox. 450 Must be 12 characters from 0-9 and A-F. 451 - version (str): The version of the TBox. Optional 452 - orgId (str): The ID of the organization. Optional 453 - ioTCardNumber (str): The IoT card number of the TBox. Optional 454 - carrier (str): The carrier of the TBox. Optional 455 - remark (str): Additional remarks about the TBox. Optional 456 457 Note: The tbox_info dictionary must follow the API requirements. 458 Check the API documentation for optional fields. 459 Returns: 460 The response from the API if available or None if the request fails. 461 """ 462 endpoint = "/smartyre/openapi/tbox/insert" 463 464 body_str = json.dumps(tbox_info, separators=(",", ":"), ensure_ascii=False) 465 466 return self._new_post_request( 467 endpoint=endpoint, 468 body=body_str, 469 returns_data=False, 470 ) 471 472 def update_tbox(self, tbox_info): 473 """ 474 Updates an existing TBox in the Smart Tyre system. 475 Args: 476 tbox_info (dict): The information of the TBox to be updated. 477 478 The dictionary should contain: 479 - id (str): The ID of the TBox to be updated. 480 - tboxCode (str): The identification code of the Tbox to be updated. 481 Cannot be changed. 482 - version (str): The version of the TBox. Optional 483 - orgId (str): The ID of the organization. Optional 484 - ioTCardNumber (str): The IoT card number of the TBox. Optional 485 - carrier (str): The carrier of the TBox. Optional 486 - remark (str): Additional remarks about the TBox. Optional 487 488 Note: The tbox_info dictionary must follow the API requirements. 489 Check the API documentation for optional fields. 490 491 Returns: 492 The response from the API if available or None if the request fails. 493 """ 494 endpoint = "/smartyre/openapi/tbox/update" 495 496 body_str = json.dumps(tbox_info, separators=(",", ":"), ensure_ascii=False) 497 498 return self._new_post_request( 499 endpoint=endpoint, 500 body=body_str, 501 returns_data=False, 502 ) 503 504 def get_tboxes_list(self, params=None): 505 """ 506 Obtains the list of TBoxes from the Smart Tyre API. 507 508 Args: 509 params (dict): Optional parameters for filtering the TBox list. 510 Example: {"page": "1", "pageSize": "10"} 511 Note: The params dictionary must follow the API requirements. 512 Returns: 513 The list of TBoxes if available or None if the request fails. 514 """ 515 endpoint = "/smartyre/openapi/tbox/list" 516 517 return self._new_get_request(endpoint, params=params) 518 519 def get_tbox_info(self, tbox_id): 520 """ 521 Obtains information about a specific TBox. 522 Args: 523 tbox_id (str): The ID of the TBox. 524 Returns: 525 The detailed information about the TBox if available or None if the request fails. 526 """ 527 endpoint = "/smartyre/openapi/tbox/detail" 528 params = { 529 "id": [str(tbox_id)], 530 } 531 return self._new_get_request(endpoint, params=params) 532 533 # Sensor Management 534 535 def add_sensor(self, sensor_info): 536 """ 537 Adds a new sensor to the Smart Tyre system. 538 Args: 539 sensor_info (dict): The information of the sensor to be added. 540 541 The dictionary should contain: 542 - sensorCode (str): The identification code of the sensor. 543 Must be 12 characters from 0-9 and A-F. 544 - version (str): The version of the sensor. Optional 545 - orgId (str): The ID of the organization. Optional 546 - remark (str): Additional remarks about the sensor. Optional 547 548 Note: The sensor_info dictionary must follow the API requirements. 549 Check the API documentation for optional fields. 550 Returns: 551 The response from the API if available or None if the request fails. 552 """ 553 endpoint = "/smartyre/openapi/sensor/insert" 554 555 body_str = json.dumps(sensor_info, separators=(",", ":"), ensure_ascii=False) 556 557 return self._new_post_request( 558 endpoint=endpoint, 559 body=body_str, 560 returns_data=False, 561 ) 562 563 def update_sensor(self, sensor_info): 564 """ 565 Updates an existing sensor in the Smart Tyre system. 566 Args: 567 sensor_info (dict): The information of the sensor to be updated. 568 569 The dictionary should contain: 570 - id (str): The ID of the sensor to be updated. 571 - sensorCode (str): The identification code of the sensor. 572 Must be 12 characters from 0-9 and A-F. 573 - version (str): The version of the sensor. Optional 574 - orgId (str): The ID of the organization. Optional 575 - remark (str): Additional remarks about the sensor. Optional 576 577 Note: The sensor_info dictionary must follow the API requirements. 578 Check the API documentation for optional fields. 579 Returns: 580 The response from the API if available or None if the request fails. 581 """ 582 endpoint = "/smartyre/openapi/sensor/update" 583 584 body_str = json.dumps(sensor_info, separators=(",", ":"), ensure_ascii=False) 585 586 return self._new_post_request( 587 endpoint=endpoint, 588 body=body_str, 589 returns_data=False, 590 ) 591 592 def get_sensor_list(self, params=None): 593 """ 594 Obtains the list of sensors from the Smart Tyre API. 595 Args: 596 params (dict): Optional parameters for filtering the sensor list. 597 Example: {"page": "1", "pageSize": "10"} 598 Note: The params dictionary must follow the API requirements. 599 Returns: 600 The list of sensors if available or None if the request fails. 601 """ 602 endpoint = "/smartyre/openapi/sensor/list" 603 604 return self._new_get_request(endpoint, params=params) 605 606 def get_sensor_info(self, sensor_id): 607 """ 608 Obtains information about a specific sensor. 609 Args: 610 sensor_id (str): The ID of the sensor. 611 Returns: 612 The detailed information about the sensor if available or None if the request fails. 613 """ 614 endpoint = "/smartyre/openapi/sensor/detail" 615 params = { 616 "id": [str(sensor_id)], 617 } 618 return self._new_get_request(endpoint, params=params) 619 620 def bind_sensor_to_tire(self, tire_code, vehicle_id, axle_index, wheel_index, sensor_code): 621 """ 622 Binds a sensor to a tire in the Smart Tyre system. 623 Args: 624 tire_code (str): The ID of the tire. 625 vehicle_id (str): The ID of the vehicle. 626 axle_index (int): The index of the axle. 627 wheel_index (int): The index of the wheel. 628 sensor_code (str): The ID of the sensor. 629 Returns: 630 The response from the API if available or None if the request fails. 631 """ 632 endpoint = "/smartyre/openapi/tyre/sensor/bind" 633 634 body = { 635 "tyreCode": tire_code, 636 "vehicleId": vehicle_id, 637 "axleIndex": axle_index, 638 "wheelIndex": wheel_index, 639 "sensorCode": sensor_code, 640 } 641 642 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 643 644 return self._new_post_request( 645 endpoint=endpoint, 646 body=body_str, 647 returns_data=False, 648 ) 649 650 def unbind_sensor_from_tire(self, tire_code, vehicle_id, axle_index, wheel_index, sensor_code): 651 """ 652 Unbinds a sensor from a tire in the Smart Tyre system. 653 Args: 654 tire_code (str): The ID of the tire. 655 vehicle_id (str): The ID of the vehicle. 656 axle_index (int): The index of the axle. 657 wheel_index (int): The index of the wheel. 658 sensor_code (str): The ID of the sensor. 659 Returns: 660 The response from the API if available or None if the request fails. 661 """ 662 endpoint = "/smartyre/openapi/tyre/sensor/unbind" 663 664 body = { 665 "tyreCode": tire_code, 666 "vehicleId": vehicle_id, 667 "axleIndex": axle_index, 668 "wheelIndex": wheel_index, 669 "sensorCode": sensor_code, 670 } 671 672 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 673 674 return self._new_post_request( 675 endpoint=endpoint, 676 body=body_str, 677 returns_data=False, 678 ) 679 680 # Reference Data Management 681 def get_tire_brands(self): 682 """ 683 Obtains the list of tire brands from the Smart Tyre API. 684 Returns: 685 The list of tire brands if available or None if the request fails. 686 """ 687 endpoint = "/smartyre/openapi/tyre/brand/all" 688 689 return self._new_get_request(endpoint, params={}) 690 691 def get_tire_sizes(self): 692 """ 693 Obtains the list of tire sizes from the Smart Tyre API. 694 Returns: 695 The list of tire sizes if available or None if the request fails. 696 """ 697 endpoint = "/smartyre/openapi/tyre/size/all" 698 699 return self._new_get_request(endpoint, params={}) 700 701 def get_vehicle_models(self): 702 """ 703 Obtains the list of vehicle models from the Smart Tyre API. 704 Returns: 705 The list of vehicle models if available or None if the request fails. 706 """ 707 endpoint = "/smartyre/openapi/vehicle/model/all" 708 709 return self._new_get_request(endpoint, params={}) 710 711 def get_axle_types(self): 712 """ 713 Obtains the list of axle types from the Smart Tyre API. 714 Returns: 715 The list of axle types if available or None if the request fails. 716 """ 717 endpoint = "/smartyre/openapi/vehicle/axle/all" 718 719 return self._new_get_request(endpoint, params={})
15class SmartTyreAPI: 16 """ 17 A class to interact with the Smart Tyre API. 18 """ 19 20 def __init__(self, base_url, client_id, client_secret, sign_key): 21 """ 22 Initializes the SmartTyreAPI with the necessary credentials. 23 24 Args: 25 base_url (str): The base URL of the Smart Tyre API. 26 client_id (str): The client ID for authentication. 27 client_secret (str): The client secret for authentication. 28 sign_key (str): The signing key used to generate the signature. 29 """ 30 self.base_url = base_url 31 self.client_id = client_id 32 self.client_secret = client_secret 33 self.sign_key = sign_key 34 35 def _new_header(self, need_access_token=True): 36 if need_access_token: 37 access_token = self.get_access_token() 38 39 return { 40 "clientId": self.client_id, 41 "timestamp": str(int(time.time() * 1000)), 42 "nonce": secrets.token_hex(16), 43 "accessToken": access_token, 44 } 45 46 return { 47 "clientId": self.client_id, 48 "timestamp": str(int(time.time() * 1000)), 49 "nonce": secrets.token_hex(16), 50 } 51 52 def _new_signature(self, headers, body, params, paths): 53 return SignUtil.sign( 54 headers=headers, 55 body=body, 56 params=params, 57 paths=paths, 58 sign_key=self.sign_key, 59 ) 60 61 def _new_get_request(self, endpoint, params): 62 url = f"{self.base_url}{endpoint}" 63 headers = self._new_header() 64 headers["sign"] = self._new_signature(headers, "", params, []) 65 headers["Content-Type"] = "application/json" 66 headers["Accept"] = "application/json" 67 68 response = requests.get(url, headers=headers, params=params, timeout=20) 69 if response.status_code == 200: 70 return response.json().get("data") 71 return None 72 73 def _new_post_request( 74 self, endpoint, body, need_access_token=True, returns_data=True 75 ): 76 url = f"{self.base_url}{endpoint}" 77 headers = self._new_header(need_access_token) 78 headers["sign"] = self._new_signature(headers, body, {}, []) 79 headers["Content-Type"] = "application/json" 80 headers["Accept"] = "application/json" 81 response = requests.post(url, headers=headers, data=body, timeout=20) 82 if response.status_code == 200 and returns_data: 83 return response.json().get("data") 84 if response.status_code == 200: 85 return response.json().get("msg") 86 return None 87 88 def get_access_token(self): 89 """ 90 Obtains an access token from the Smart Tyre API. 91 92 Args: 93 base_url (str): The base URL of the Smart Tyre API. 94 client_id (str): The client ID for authentication. 95 client_secret (str): The client secret for authentication. 96 sign_key (str): The signing key used to generate the signature. 97 98 Returns: 99 The access token received from the API if available or None if the request fails. 100 """ 101 endpoint = "/smartyre/openapi/auth/oauth20/authorize" 102 103 body = { 104 "clientId": self.client_id, 105 "clientSecret": self.client_secret, 106 "grantType": "client_credentials", 107 } 108 109 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 110 111 response = self._new_post_request( 112 endpoint=endpoint, 113 body=body_str, 114 need_access_token=False, 115 ) 116 117 return response.get("accessToken") if response else None 118 119 # Vehicle Management 120 121 def add_vehicle(self, vehicle_info): 122 """ 123 Creates a new vehicle in the Smart Tyre system. 124 Args: 125 vehicle_info (dict): The information of the vehicle to be created. 126 127 The dictionary should contain: 128 129 - isTractor (int): 0 for non-tractor, 1 for tractor, 2 for trailer 130 - licensePlateNumber (str): The license plate number of the vehicle 131 - emptyWeight (str): The empty weight of the vehicle 132 - fullWeight (str): The full weight of the vehicle 133 - axleTypeId (str): The ID of the axle type 134 - modelId (str): The ID of the vehicle model 135 - orgId (str): The ID of the organization 136 - tboxId (str): The ID of the TBox. Optional 137 - vehicleChassisNumber (str): The chassis number of the vehicle. Optional 138 139 Example: 140 ```python 141 new_vehicle = { 142 "isTractor": 0, 143 "licensePlateNumber": "ABC123", 144 "emptyWeight": "1000", 145 "fullWeight": "2000", 146 "axleTypeId": "2", 147 "modelId": "31", 148 "orgId": "218" 149 } 150 ``` 151 152 Note: The vehicle_info dictionary must follow the API requirements. 153 Check the API documentation for optional fields. 154 155 Returns: 156 The response from the API if available or None if the request fails. 157 """ 158 endpoint = "/smartyre/openapi/vehicle/insert" 159 160 body_str = json.dumps(vehicle_info, separators=(",", ":"), ensure_ascii=False) 161 162 return self._new_post_request( 163 endpoint=endpoint, 164 body=body_str, 165 returns_data=False, 166 ) 167 168 def update_vehicle(self, vehicle_info): 169 """ 170 Updates an existing vehicle in the Smart Tyre system. 171 Args: 172 vehicle_info (dict): The information of the vehicle to be updated. 173 174 The dictionary should contain: 175 176 - id (str): The ID of the vehicle to be updated 177 - isTractor (int): 0 for non-tractor, 1 for tractor, 2 for trailer 178 - licensePlateNumber (str): The license plate number of the vehicle 179 - emptyWeight (str): The empty weight of the vehicle 180 - fullWeight (str): The full weight of the vehicle 181 - axleTypeId (str): The ID of the axle type 182 - modelId (str): The ID of the vehicle model 183 - orgId (str): The ID of the organization 184 - tboxId (str): The ID of the TBox. Optional 185 - vehicleChassisNumber (str): The chassis number of the vehicle. Optional 186 187 188 Example: 189 ```python 190 updated_vehicle = { 191 "id": "7609", 192 "isTractor": 0, 193 "licensePlateNumber": "XYZ789", 194 "emptyWeight": "1200", 195 "fullWeight": "2200", 196 "axleTypeId": "2", 197 "modelId": "31", 198 "orgId": "218", 199 } 200 ``` 201 Note: The vehicle_info dictionary must follow the API requirements. 202 Check the API documentation for optional fields. 203 204 Returns: 205 The response from the API if available or None if the request fails. 206 """ 207 endpoint = "/smartyre/openapi/vehicle/update" 208 209 body_str = json.dumps(vehicle_info, separators=(",", ":"), ensure_ascii=False) 210 211 return self._new_post_request( 212 endpoint=endpoint, 213 body=body_str, 214 returns_data=False, 215 ) 216 217 def get_vehicle_list(self, params=None): 218 """ 219 Obtains the list of vehicles from the Smart Tyre API. 220 Args: 221 params (dict): Optional parameters for filtering the vehicle list. 222 Example: {"page": "1", "pageSize": "10"} 223 Note: The params dictionary must follow the API requirements. 224 Returns: 225 The list of vehicles if available or None if the request fails. 226 """ 227 endpoint = "/smartyre/openapi/vehicle/list" 228 229 return self._new_get_request(endpoint, params=params) 230 231 def get_vehicle_info(self, vehicle_id): 232 """ 233 Obtains detailed information about a specific vehicle. 234 Args: 235 vehicle_id (str): The ID of the vehicle. 236 Returns: 237 The detailed information about the vehicle if available or None if the request fails. 238 """ 239 if not vehicle_id: 240 return None 241 242 endpoint = "/smartyre/openapi/vehicle/detail" 243 244 params = { 245 "vehicleId": [str(vehicle_id)], 246 } 247 248 return self._new_get_request(endpoint, params=params) 249 250 # Tire Management 251 252 def add_tire(self, tire_info): 253 """ 254 Adds a new tire to the Smart Tyre system. 255 Args: 256 tire_info (dict): The information of the tire to be added. 257 258 The dictionary should contain: 259 - tyreCode (str): The identification code of the tire 260 - tyreBrandId (str): The ID of the tire brand 261 - tyreSizeId (str): The ID of the tire size 262 - tyrePattern (str): The pattern of the tire 263 - initialTreadDepth (str): The initial tread depth of the tire 264 - orgId (str): The ID of the organization. Optional 265 - sensorId (str): The ID of the sensor. Optional 266 - totalDistance (str): The total distance of the tire (km). Optional 267 - loadIndex (str): The load index of the tire. Optional 268 - speedLevel (str): The speed level of the tire. Optional 269 - newTreadDepth (str): The new tread depth of the tire. Optional 270 271 Example: 272 ```python 273 new_tire = { 274 "tyreCode": "ABC123", 275 "tyreBrandId": "1", 276 "tyreSizeId": "121", 277 "tyrePattern": "Pattern A", 278 "initialTreadDepth": "10" 279 } 280 ``` 281 282 Note: The tire_info dictionary must follow the API requirements. 283 Check the API documentation for optional fields. 284 Returns: 285 The response from the API if available or None if the request fails. 286 """ 287 endpoint = "/smartyre/openapi/tyre/insert" 288 289 body_str = json.dumps(tire_info, separators=(",", ":"), ensure_ascii=False) 290 291 return self._new_post_request( 292 endpoint=endpoint, 293 body=body_str, 294 returns_data=False, 295 ) 296 297 def update_tire(self, tire_info): 298 """ 299 Updates an existing tire in the Smart Tyre system. 300 Args: 301 tire_info (dict): The information of the tire to be updated. 302 303 The dictionary should contain: 304 - id (str): The ID of the tire to be updated 305 - tyreCode (str): The identification code of the tire, this cannot be changed 306 - tyreBrandId (str): The ID of the tire brand 307 - tyreSizeId (str): The ID of the tire size 308 - tyrePattern (str): The pattern of the tire 309 - initialTreadDepth (str): The initial tread depth of the tire 310 - orgId (str): The ID of the organization. Optional 311 - sensorId (str): The ID of the sensor. Optional 312 - totalDistance (str): The total distance of the tire (km). Optional 313 - loadIndex (str): The load index of the tire. Optional 314 - speedLevel (str): The speed level of the tire. Optional 315 - newTreadDepth (str): The new tread depth of the tire. Optional 316 Example: 317 ```python 318 updated_tire = { 319 "id": "47414", 320 "tyreCode": "ABC123", 321 "tyreBrandId": "8", 322 "tyreSizeId": "121", 323 "tyrePattern": "Pattern B", 324 "initialTreadDepth": "12" 325 } 326 ``` 327 Note: The tire_info dictionary must follow the API requirements. 328 Check the API documentation for optional fields. 329 330 Returns: 331 The response from the API if available or None if the request fails. 332 """ 333 endpoint = "/smartyre/openapi/tyre/update" 334 335 body_str = json.dumps(tire_info, separators=(",", ":"), ensure_ascii=False) 336 return self._new_post_request( 337 endpoint=endpoint, 338 body=body_str, 339 returns_data=False, 340 ) 341 342 def get_tires_info_by_vehicle(self, vehicle_id): 343 """ 344 Obtains tire information for a specific vehicle. 345 Args: 346 vehicle_id (str): The ID of the vehicle. 347 Returns: 348 The tire information if available or None if the request fails. 349 """ 350 351 if not vehicle_id: 352 return None 353 354 endpoint = "/smartyre/openapi/vehicle/tyre/data" 355 356 body_str = json.dumps({"vehicleId": vehicle_id}, separators=(",", ":")) 357 358 return self._new_post_request( 359 endpoint=endpoint, 360 body=body_str, 361 ) 362 363 def get_tire_list(self, params=None): 364 """ 365 Obtains the list of tires from the Smart Tyre API. 366 Args: 367 params (dict): Optional parameters for filtering the tire list. 368 Example: {"page": "1", "pageSize": "10"} 369 Note: The params dictionary must follow the API requirements. 370 Returns: 371 The list of tires if available or None if the request fails. 372 """ 373 374 endpoint = "/smartyre/openapi/tyre/list" 375 376 return self._new_get_request(endpoint, params=params) 377 378 def get_tire_info(self, tire_id): 379 """ 380 Obtains detailed information about a specific tire. 381 Args: 382 tire_id (str): The ID of the tire. 383 Returns: 384 The detailed information about the tire if available or None if the request fails. 385 """ 386 endpoint = "/smartyre/openapi/tyre/detail" 387 params = { 388 "id": [str(tire_id)], 389 } 390 return self._new_get_request(endpoint, params=params) 391 392 def bind_tire_to_vehicle(self, vehicle_id, tire_code, axle_index, wheel_index): 393 """ 394 Binds a tire to a vehicle in the Smart Tyre system. 395 Args: 396 vehicle_id (str): The ID of the vehicle. 397 tire_code (str): The ID of the tire. 398 axle_index (int): The index of the axle. 399 wheel_index (int): The index of the wheel. 400 Returns: 401 The response from the API if available or None if the request fails. 402 """ 403 endpoint = "/smartyre/openapi/vehicle/tyre/bind" 404 405 body = { 406 "vehicleId": vehicle_id, 407 "tyreCode": tire_code, 408 "axleIndex": axle_index, 409 "wheelIndex": wheel_index, 410 } 411 412 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 413 414 return self._new_post_request( 415 endpoint=endpoint, 416 body=body_str, 417 returns_data=False, 418 ) 419 420 def unbind_tire_from_vehicle(self, vehicle_id, tire_id): 421 """ 422 Unbinds a tire from a vehicle in the Smart Tyre system. 423 Args: 424 vehicle_id (str): The ID of the vehicle. 425 tire_id (str): The ID of the tire. 426 Returns: 427 The response from the API if available or None if the request fails. 428 """ 429 430 endpoint = "/smartyre/openapi/vehicle/tyre/unbind" 431 body = { 432 "vehicleId": vehicle_id, 433 "tyreCode": tire_id, 434 } 435 436 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 437 return self._new_post_request( 438 endpoint=endpoint, body=body_str, returns_data=False 439 ) 440 441 # Tbox Management 442 443 def add_tbox(self, tbox_info): 444 """ 445 Adds a new TBox to the Smart Tyre system. 446 Args: 447 tbox_info (dict): The information of the TBox to be added. 448 449 The dictionary should contain: 450 - tboxCode (str): The identification code of the TBox. 451 Must be 12 characters from 0-9 and A-F. 452 - version (str): The version of the TBox. Optional 453 - orgId (str): The ID of the organization. Optional 454 - ioTCardNumber (str): The IoT card number of the TBox. Optional 455 - carrier (str): The carrier of the TBox. Optional 456 - remark (str): Additional remarks about the TBox. Optional 457 458 Note: The tbox_info dictionary must follow the API requirements. 459 Check the API documentation for optional fields. 460 Returns: 461 The response from the API if available or None if the request fails. 462 """ 463 endpoint = "/smartyre/openapi/tbox/insert" 464 465 body_str = json.dumps(tbox_info, separators=(",", ":"), ensure_ascii=False) 466 467 return self._new_post_request( 468 endpoint=endpoint, 469 body=body_str, 470 returns_data=False, 471 ) 472 473 def update_tbox(self, tbox_info): 474 """ 475 Updates an existing TBox in the Smart Tyre system. 476 Args: 477 tbox_info (dict): The information of the TBox to be updated. 478 479 The dictionary should contain: 480 - id (str): The ID of the TBox to be updated. 481 - tboxCode (str): The identification code of the Tbox to be updated. 482 Cannot be changed. 483 - version (str): The version of the TBox. Optional 484 - orgId (str): The ID of the organization. Optional 485 - ioTCardNumber (str): The IoT card number of the TBox. Optional 486 - carrier (str): The carrier of the TBox. Optional 487 - remark (str): Additional remarks about the TBox. Optional 488 489 Note: The tbox_info dictionary must follow the API requirements. 490 Check the API documentation for optional fields. 491 492 Returns: 493 The response from the API if available or None if the request fails. 494 """ 495 endpoint = "/smartyre/openapi/tbox/update" 496 497 body_str = json.dumps(tbox_info, separators=(",", ":"), ensure_ascii=False) 498 499 return self._new_post_request( 500 endpoint=endpoint, 501 body=body_str, 502 returns_data=False, 503 ) 504 505 def get_tboxes_list(self, params=None): 506 """ 507 Obtains the list of TBoxes from the Smart Tyre API. 508 509 Args: 510 params (dict): Optional parameters for filtering the TBox list. 511 Example: {"page": "1", "pageSize": "10"} 512 Note: The params dictionary must follow the API requirements. 513 Returns: 514 The list of TBoxes if available or None if the request fails. 515 """ 516 endpoint = "/smartyre/openapi/tbox/list" 517 518 return self._new_get_request(endpoint, params=params) 519 520 def get_tbox_info(self, tbox_id): 521 """ 522 Obtains information about a specific TBox. 523 Args: 524 tbox_id (str): The ID of the TBox. 525 Returns: 526 The detailed information about the TBox if available or None if the request fails. 527 """ 528 endpoint = "/smartyre/openapi/tbox/detail" 529 params = { 530 "id": [str(tbox_id)], 531 } 532 return self._new_get_request(endpoint, params=params) 533 534 # Sensor Management 535 536 def add_sensor(self, sensor_info): 537 """ 538 Adds a new sensor to the Smart Tyre system. 539 Args: 540 sensor_info (dict): The information of the sensor to be added. 541 542 The dictionary should contain: 543 - sensorCode (str): The identification code of the sensor. 544 Must be 12 characters from 0-9 and A-F. 545 - version (str): The version of the sensor. Optional 546 - orgId (str): The ID of the organization. Optional 547 - remark (str): Additional remarks about the sensor. Optional 548 549 Note: The sensor_info dictionary must follow the API requirements. 550 Check the API documentation for optional fields. 551 Returns: 552 The response from the API if available or None if the request fails. 553 """ 554 endpoint = "/smartyre/openapi/sensor/insert" 555 556 body_str = json.dumps(sensor_info, separators=(",", ":"), ensure_ascii=False) 557 558 return self._new_post_request( 559 endpoint=endpoint, 560 body=body_str, 561 returns_data=False, 562 ) 563 564 def update_sensor(self, sensor_info): 565 """ 566 Updates an existing sensor in the Smart Tyre system. 567 Args: 568 sensor_info (dict): The information of the sensor to be updated. 569 570 The dictionary should contain: 571 - id (str): The ID of the sensor to be updated. 572 - sensorCode (str): The identification code of the sensor. 573 Must be 12 characters from 0-9 and A-F. 574 - version (str): The version of the sensor. Optional 575 - orgId (str): The ID of the organization. Optional 576 - remark (str): Additional remarks about the sensor. Optional 577 578 Note: The sensor_info dictionary must follow the API requirements. 579 Check the API documentation for optional fields. 580 Returns: 581 The response from the API if available or None if the request fails. 582 """ 583 endpoint = "/smartyre/openapi/sensor/update" 584 585 body_str = json.dumps(sensor_info, separators=(",", ":"), ensure_ascii=False) 586 587 return self._new_post_request( 588 endpoint=endpoint, 589 body=body_str, 590 returns_data=False, 591 ) 592 593 def get_sensor_list(self, params=None): 594 """ 595 Obtains the list of sensors from the Smart Tyre API. 596 Args: 597 params (dict): Optional parameters for filtering the sensor list. 598 Example: {"page": "1", "pageSize": "10"} 599 Note: The params dictionary must follow the API requirements. 600 Returns: 601 The list of sensors if available or None if the request fails. 602 """ 603 endpoint = "/smartyre/openapi/sensor/list" 604 605 return self._new_get_request(endpoint, params=params) 606 607 def get_sensor_info(self, sensor_id): 608 """ 609 Obtains information about a specific sensor. 610 Args: 611 sensor_id (str): The ID of the sensor. 612 Returns: 613 The detailed information about the sensor if available or None if the request fails. 614 """ 615 endpoint = "/smartyre/openapi/sensor/detail" 616 params = { 617 "id": [str(sensor_id)], 618 } 619 return self._new_get_request(endpoint, params=params) 620 621 def bind_sensor_to_tire(self, tire_code, vehicle_id, axle_index, wheel_index, sensor_code): 622 """ 623 Binds a sensor to a tire in the Smart Tyre system. 624 Args: 625 tire_code (str): The ID of the tire. 626 vehicle_id (str): The ID of the vehicle. 627 axle_index (int): The index of the axle. 628 wheel_index (int): The index of the wheel. 629 sensor_code (str): The ID of the sensor. 630 Returns: 631 The response from the API if available or None if the request fails. 632 """ 633 endpoint = "/smartyre/openapi/tyre/sensor/bind" 634 635 body = { 636 "tyreCode": tire_code, 637 "vehicleId": vehicle_id, 638 "axleIndex": axle_index, 639 "wheelIndex": wheel_index, 640 "sensorCode": sensor_code, 641 } 642 643 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 644 645 return self._new_post_request( 646 endpoint=endpoint, 647 body=body_str, 648 returns_data=False, 649 ) 650 651 def unbind_sensor_from_tire(self, tire_code, vehicle_id, axle_index, wheel_index, sensor_code): 652 """ 653 Unbinds a sensor from a tire in the Smart Tyre system. 654 Args: 655 tire_code (str): The ID of the tire. 656 vehicle_id (str): The ID of the vehicle. 657 axle_index (int): The index of the axle. 658 wheel_index (int): The index of the wheel. 659 sensor_code (str): The ID of the sensor. 660 Returns: 661 The response from the API if available or None if the request fails. 662 """ 663 endpoint = "/smartyre/openapi/tyre/sensor/unbind" 664 665 body = { 666 "tyreCode": tire_code, 667 "vehicleId": vehicle_id, 668 "axleIndex": axle_index, 669 "wheelIndex": wheel_index, 670 "sensorCode": sensor_code, 671 } 672 673 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 674 675 return self._new_post_request( 676 endpoint=endpoint, 677 body=body_str, 678 returns_data=False, 679 ) 680 681 # Reference Data Management 682 def get_tire_brands(self): 683 """ 684 Obtains the list of tire brands from the Smart Tyre API. 685 Returns: 686 The list of tire brands if available or None if the request fails. 687 """ 688 endpoint = "/smartyre/openapi/tyre/brand/all" 689 690 return self._new_get_request(endpoint, params={}) 691 692 def get_tire_sizes(self): 693 """ 694 Obtains the list of tire sizes from the Smart Tyre API. 695 Returns: 696 The list of tire sizes if available or None if the request fails. 697 """ 698 endpoint = "/smartyre/openapi/tyre/size/all" 699 700 return self._new_get_request(endpoint, params={}) 701 702 def get_vehicle_models(self): 703 """ 704 Obtains the list of vehicle models from the Smart Tyre API. 705 Returns: 706 The list of vehicle models if available or None if the request fails. 707 """ 708 endpoint = "/smartyre/openapi/vehicle/model/all" 709 710 return self._new_get_request(endpoint, params={}) 711 712 def get_axle_types(self): 713 """ 714 Obtains the list of axle types from the Smart Tyre API. 715 Returns: 716 The list of axle types if available or None if the request fails. 717 """ 718 endpoint = "/smartyre/openapi/vehicle/axle/all" 719 720 return self._new_get_request(endpoint, params={})
A class to interact with the Smart Tyre API.
20 def __init__(self, base_url, client_id, client_secret, sign_key): 21 """ 22 Initializes the SmartTyreAPI with the necessary credentials. 23 24 Args: 25 base_url (str): The base URL of the Smart Tyre API. 26 client_id (str): The client ID for authentication. 27 client_secret (str): The client secret for authentication. 28 sign_key (str): The signing key used to generate the signature. 29 """ 30 self.base_url = base_url 31 self.client_id = client_id 32 self.client_secret = client_secret 33 self.sign_key = sign_key
Initializes the SmartTyreAPI with the necessary credentials.
Arguments:
- base_url (str): The base URL of the Smart Tyre API.
- client_id (str): The client ID for authentication.
- client_secret (str): The client secret for authentication.
- sign_key (str): The signing key used to generate the signature.
88 def get_access_token(self): 89 """ 90 Obtains an access token from the Smart Tyre API. 91 92 Args: 93 base_url (str): The base URL of the Smart Tyre API. 94 client_id (str): The client ID for authentication. 95 client_secret (str): The client secret for authentication. 96 sign_key (str): The signing key used to generate the signature. 97 98 Returns: 99 The access token received from the API if available or None if the request fails. 100 """ 101 endpoint = "/smartyre/openapi/auth/oauth20/authorize" 102 103 body = { 104 "clientId": self.client_id, 105 "clientSecret": self.client_secret, 106 "grantType": "client_credentials", 107 } 108 109 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 110 111 response = self._new_post_request( 112 endpoint=endpoint, 113 body=body_str, 114 need_access_token=False, 115 ) 116 117 return response.get("accessToken") if response else None
Obtains an access token from the Smart Tyre API.
Arguments:
- base_url (str): The base URL of the Smart Tyre API.
- client_id (str): The client ID for authentication.
- client_secret (str): The client secret for authentication.
- sign_key (str): The signing key used to generate the signature.
Returns:
The access token received from the API if available or None if the request fails.
121 def add_vehicle(self, vehicle_info): 122 """ 123 Creates a new vehicle in the Smart Tyre system. 124 Args: 125 vehicle_info (dict): The information of the vehicle to be created. 126 127 The dictionary should contain: 128 129 - isTractor (int): 0 for non-tractor, 1 for tractor, 2 for trailer 130 - licensePlateNumber (str): The license plate number of the vehicle 131 - emptyWeight (str): The empty weight of the vehicle 132 - fullWeight (str): The full weight of the vehicle 133 - axleTypeId (str): The ID of the axle type 134 - modelId (str): The ID of the vehicle model 135 - orgId (str): The ID of the organization 136 - tboxId (str): The ID of the TBox. Optional 137 - vehicleChassisNumber (str): The chassis number of the vehicle. Optional 138 139 Example: 140 ```python 141 new_vehicle = { 142 "isTractor": 0, 143 "licensePlateNumber": "ABC123", 144 "emptyWeight": "1000", 145 "fullWeight": "2000", 146 "axleTypeId": "2", 147 "modelId": "31", 148 "orgId": "218" 149 } 150 ``` 151 152 Note: The vehicle_info dictionary must follow the API requirements. 153 Check the API documentation for optional fields. 154 155 Returns: 156 The response from the API if available or None if the request fails. 157 """ 158 endpoint = "/smartyre/openapi/vehicle/insert" 159 160 body_str = json.dumps(vehicle_info, separators=(",", ":"), ensure_ascii=False) 161 162 return self._new_post_request( 163 endpoint=endpoint, 164 body=body_str, 165 returns_data=False, 166 )
Creates a new vehicle in the Smart Tyre system.
Arguments:
vehicle_info (dict): The information of the vehicle to be created.
The dictionary should contain:
- isTractor (int): 0 for non-tractor, 1 for tractor, 2 for trailer
- licensePlateNumber (str): The license plate number of the vehicle
- emptyWeight (str): The empty weight of the vehicle
- fullWeight (str): The full weight of the vehicle
- axleTypeId (str): The ID of the axle type
- modelId (str): The ID of the vehicle model
- orgId (str): The ID of the organization
- tboxId (str): The ID of the TBox. Optional
- vehicleChassisNumber (str): The chassis number of the vehicle. Optional
Example:
new_vehicle = { "isTractor": 0, "licensePlateNumber": "ABC123", "emptyWeight": "1000", "fullWeight": "2000", "axleTypeId": "2", "modelId": "31", "orgId": "218" }
Note: The vehicle_info dictionary must follow the API requirements. Check the API documentation for optional fields.
Returns:
The response from the API if available or None if the request fails.
168 def update_vehicle(self, vehicle_info): 169 """ 170 Updates an existing vehicle in the Smart Tyre system. 171 Args: 172 vehicle_info (dict): The information of the vehicle to be updated. 173 174 The dictionary should contain: 175 176 - id (str): The ID of the vehicle to be updated 177 - isTractor (int): 0 for non-tractor, 1 for tractor, 2 for trailer 178 - licensePlateNumber (str): The license plate number of the vehicle 179 - emptyWeight (str): The empty weight of the vehicle 180 - fullWeight (str): The full weight of the vehicle 181 - axleTypeId (str): The ID of the axle type 182 - modelId (str): The ID of the vehicle model 183 - orgId (str): The ID of the organization 184 - tboxId (str): The ID of the TBox. Optional 185 - vehicleChassisNumber (str): The chassis number of the vehicle. Optional 186 187 188 Example: 189 ```python 190 updated_vehicle = { 191 "id": "7609", 192 "isTractor": 0, 193 "licensePlateNumber": "XYZ789", 194 "emptyWeight": "1200", 195 "fullWeight": "2200", 196 "axleTypeId": "2", 197 "modelId": "31", 198 "orgId": "218", 199 } 200 ``` 201 Note: The vehicle_info dictionary must follow the API requirements. 202 Check the API documentation for optional fields. 203 204 Returns: 205 The response from the API if available or None if the request fails. 206 """ 207 endpoint = "/smartyre/openapi/vehicle/update" 208 209 body_str = json.dumps(vehicle_info, separators=(",", ":"), ensure_ascii=False) 210 211 return self._new_post_request( 212 endpoint=endpoint, 213 body=body_str, 214 returns_data=False, 215 )
Updates an existing vehicle in the Smart Tyre system.
Arguments:
vehicle_info (dict): The information of the vehicle to be updated.
The dictionary should contain:
- id (str): The ID of the vehicle to be updated
- isTractor (int): 0 for non-tractor, 1 for tractor, 2 for trailer
- licensePlateNumber (str): The license plate number of the vehicle
- emptyWeight (str): The empty weight of the vehicle
- fullWeight (str): The full weight of the vehicle
- axleTypeId (str): The ID of the axle type
- modelId (str): The ID of the vehicle model
- orgId (str): The ID of the organization
- tboxId (str): The ID of the TBox. Optional
- vehicleChassisNumber (str): The chassis number of the vehicle. Optional
Example:
updated_vehicle = { "id": "7609", "isTractor": 0, "licensePlateNumber": "XYZ789", "emptyWeight": "1200", "fullWeight": "2200", "axleTypeId": "2", "modelId": "31", "orgId": "218", }
Note: The vehicle_info dictionary must follow the API requirements. Check the API documentation for optional fields.
Returns:
The response from the API if available or None if the request fails.
217 def get_vehicle_list(self, params=None): 218 """ 219 Obtains the list of vehicles from the Smart Tyre API. 220 Args: 221 params (dict): Optional parameters for filtering the vehicle list. 222 Example: {"page": "1", "pageSize": "10"} 223 Note: The params dictionary must follow the API requirements. 224 Returns: 225 The list of vehicles if available or None if the request fails. 226 """ 227 endpoint = "/smartyre/openapi/vehicle/list" 228 229 return self._new_get_request(endpoint, params=params)
Obtains the list of vehicles from the Smart Tyre API.
Arguments:
- params (dict): Optional parameters for filtering the vehicle list. Example: {"page": "1", "pageSize": "10"}
Note: The params dictionary must follow the API requirements.
Returns:
The list of vehicles if available or None if the request fails.
231 def get_vehicle_info(self, vehicle_id): 232 """ 233 Obtains detailed information about a specific vehicle. 234 Args: 235 vehicle_id (str): The ID of the vehicle. 236 Returns: 237 The detailed information about the vehicle if available or None if the request fails. 238 """ 239 if not vehicle_id: 240 return None 241 242 endpoint = "/smartyre/openapi/vehicle/detail" 243 244 params = { 245 "vehicleId": [str(vehicle_id)], 246 } 247 248 return self._new_get_request(endpoint, params=params)
Obtains detailed information about a specific vehicle.
Arguments:
- vehicle_id (str): The ID of the vehicle.
Returns:
The detailed information about the vehicle if available or None if the request fails.
252 def add_tire(self, tire_info): 253 """ 254 Adds a new tire to the Smart Tyre system. 255 Args: 256 tire_info (dict): The information of the tire to be added. 257 258 The dictionary should contain: 259 - tyreCode (str): The identification code of the tire 260 - tyreBrandId (str): The ID of the tire brand 261 - tyreSizeId (str): The ID of the tire size 262 - tyrePattern (str): The pattern of the tire 263 - initialTreadDepth (str): The initial tread depth of the tire 264 - orgId (str): The ID of the organization. Optional 265 - sensorId (str): The ID of the sensor. Optional 266 - totalDistance (str): The total distance of the tire (km). Optional 267 - loadIndex (str): The load index of the tire. Optional 268 - speedLevel (str): The speed level of the tire. Optional 269 - newTreadDepth (str): The new tread depth of the tire. Optional 270 271 Example: 272 ```python 273 new_tire = { 274 "tyreCode": "ABC123", 275 "tyreBrandId": "1", 276 "tyreSizeId": "121", 277 "tyrePattern": "Pattern A", 278 "initialTreadDepth": "10" 279 } 280 ``` 281 282 Note: The tire_info dictionary must follow the API requirements. 283 Check the API documentation for optional fields. 284 Returns: 285 The response from the API if available or None if the request fails. 286 """ 287 endpoint = "/smartyre/openapi/tyre/insert" 288 289 body_str = json.dumps(tire_info, separators=(",", ":"), ensure_ascii=False) 290 291 return self._new_post_request( 292 endpoint=endpoint, 293 body=body_str, 294 returns_data=False, 295 )
Adds a new tire to the Smart Tyre system.
Arguments:
tire_info (dict): The information of the tire to be added.
The dictionary should contain:
- tyreCode (str): The identification code of the tire
- tyreBrandId (str): The ID of the tire brand
- tyreSizeId (str): The ID of the tire size
- tyrePattern (str): The pattern of the tire
- initialTreadDepth (str): The initial tread depth of the tire
- orgId (str): The ID of the organization. Optional
- sensorId (str): The ID of the sensor. Optional
- totalDistance (str): The total distance of the tire (km). Optional
- loadIndex (str): The load index of the tire. Optional
- speedLevel (str): The speed level of the tire. Optional
- newTreadDepth (str): The new tread depth of the tire. Optional
Example:
new_tire = { "tyreCode": "ABC123", "tyreBrandId": "1", "tyreSizeId": "121", "tyrePattern": "Pattern A", "initialTreadDepth": "10" }
Note: The tire_info dictionary must follow the API requirements. Check the API documentation for optional fields.
Returns:
The response from the API if available or None if the request fails.
297 def update_tire(self, tire_info): 298 """ 299 Updates an existing tire in the Smart Tyre system. 300 Args: 301 tire_info (dict): The information of the tire to be updated. 302 303 The dictionary should contain: 304 - id (str): The ID of the tire to be updated 305 - tyreCode (str): The identification code of the tire, this cannot be changed 306 - tyreBrandId (str): The ID of the tire brand 307 - tyreSizeId (str): The ID of the tire size 308 - tyrePattern (str): The pattern of the tire 309 - initialTreadDepth (str): The initial tread depth of the tire 310 - orgId (str): The ID of the organization. Optional 311 - sensorId (str): The ID of the sensor. Optional 312 - totalDistance (str): The total distance of the tire (km). Optional 313 - loadIndex (str): The load index of the tire. Optional 314 - speedLevel (str): The speed level of the tire. Optional 315 - newTreadDepth (str): The new tread depth of the tire. Optional 316 Example: 317 ```python 318 updated_tire = { 319 "id": "47414", 320 "tyreCode": "ABC123", 321 "tyreBrandId": "8", 322 "tyreSizeId": "121", 323 "tyrePattern": "Pattern B", 324 "initialTreadDepth": "12" 325 } 326 ``` 327 Note: The tire_info dictionary must follow the API requirements. 328 Check the API documentation for optional fields. 329 330 Returns: 331 The response from the API if available or None if the request fails. 332 """ 333 endpoint = "/smartyre/openapi/tyre/update" 334 335 body_str = json.dumps(tire_info, separators=(",", ":"), ensure_ascii=False) 336 return self._new_post_request( 337 endpoint=endpoint, 338 body=body_str, 339 returns_data=False, 340 )
Updates an existing tire in the Smart Tyre system.
Arguments:
tire_info (dict): The information of the tire to be updated.
The dictionary should contain:
- id (str): The ID of the tire to be updated
- tyreCode (str): The identification code of the tire, this cannot be changed
- tyreBrandId (str): The ID of the tire brand
- tyreSizeId (str): The ID of the tire size
- tyrePattern (str): The pattern of the tire
- initialTreadDepth (str): The initial tread depth of the tire
- orgId (str): The ID of the organization. Optional
- sensorId (str): The ID of the sensor. Optional
- totalDistance (str): The total distance of the tire (km). Optional
- loadIndex (str): The load index of the tire. Optional
- speedLevel (str): The speed level of the tire. Optional
- newTreadDepth (str): The new tread depth of the tire. Optional
Example:
updated_tire = { "id": "47414", "tyreCode": "ABC123", "tyreBrandId": "8", "tyreSizeId": "121", "tyrePattern": "Pattern B", "initialTreadDepth": "12" }
Note: The tire_info dictionary must follow the API requirements. Check the API documentation for optional fields.
Returns:
The response from the API if available or None if the request fails.
342 def get_tires_info_by_vehicle(self, vehicle_id): 343 """ 344 Obtains tire information for a specific vehicle. 345 Args: 346 vehicle_id (str): The ID of the vehicle. 347 Returns: 348 The tire information if available or None if the request fails. 349 """ 350 351 if not vehicle_id: 352 return None 353 354 endpoint = "/smartyre/openapi/vehicle/tyre/data" 355 356 body_str = json.dumps({"vehicleId": vehicle_id}, separators=(",", ":")) 357 358 return self._new_post_request( 359 endpoint=endpoint, 360 body=body_str, 361 )
Obtains tire information for a specific vehicle.
Arguments:
- vehicle_id (str): The ID of the vehicle.
Returns:
The tire information if available or None if the request fails.
363 def get_tire_list(self, params=None): 364 """ 365 Obtains the list of tires from the Smart Tyre API. 366 Args: 367 params (dict): Optional parameters for filtering the tire list. 368 Example: {"page": "1", "pageSize": "10"} 369 Note: The params dictionary must follow the API requirements. 370 Returns: 371 The list of tires if available or None if the request fails. 372 """ 373 374 endpoint = "/smartyre/openapi/tyre/list" 375 376 return self._new_get_request(endpoint, params=params)
Obtains the list of tires from the Smart Tyre API.
Arguments:
- params (dict): Optional parameters for filtering the tire list. Example: {"page": "1", "pageSize": "10"}
Note: The params dictionary must follow the API requirements.
Returns:
The list of tires if available or None if the request fails.
378 def get_tire_info(self, tire_id): 379 """ 380 Obtains detailed information about a specific tire. 381 Args: 382 tire_id (str): The ID of the tire. 383 Returns: 384 The detailed information about the tire if available or None if the request fails. 385 """ 386 endpoint = "/smartyre/openapi/tyre/detail" 387 params = { 388 "id": [str(tire_id)], 389 } 390 return self._new_get_request(endpoint, params=params)
Obtains detailed information about a specific tire.
Arguments:
- tire_id (str): The ID of the tire.
Returns:
The detailed information about the tire if available or None if the request fails.
392 def bind_tire_to_vehicle(self, vehicle_id, tire_code, axle_index, wheel_index): 393 """ 394 Binds a tire to a vehicle in the Smart Tyre system. 395 Args: 396 vehicle_id (str): The ID of the vehicle. 397 tire_code (str): The ID of the tire. 398 axle_index (int): The index of the axle. 399 wheel_index (int): The index of the wheel. 400 Returns: 401 The response from the API if available or None if the request fails. 402 """ 403 endpoint = "/smartyre/openapi/vehicle/tyre/bind" 404 405 body = { 406 "vehicleId": vehicle_id, 407 "tyreCode": tire_code, 408 "axleIndex": axle_index, 409 "wheelIndex": wheel_index, 410 } 411 412 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 413 414 return self._new_post_request( 415 endpoint=endpoint, 416 body=body_str, 417 returns_data=False, 418 )
Binds a tire to a vehicle in the Smart Tyre system.
Arguments:
- vehicle_id (str): The ID of the vehicle.
- tire_code (str): The ID of the tire.
- axle_index (int): The index of the axle.
- wheel_index (int): The index of the wheel.
Returns:
The response from the API if available or None if the request fails.
420 def unbind_tire_from_vehicle(self, vehicle_id, tire_id): 421 """ 422 Unbinds a tire from a vehicle in the Smart Tyre system. 423 Args: 424 vehicle_id (str): The ID of the vehicle. 425 tire_id (str): The ID of the tire. 426 Returns: 427 The response from the API if available or None if the request fails. 428 """ 429 430 endpoint = "/smartyre/openapi/vehicle/tyre/unbind" 431 body = { 432 "vehicleId": vehicle_id, 433 "tyreCode": tire_id, 434 } 435 436 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 437 return self._new_post_request( 438 endpoint=endpoint, body=body_str, returns_data=False 439 )
Unbinds a tire from a vehicle in the Smart Tyre system.
Arguments:
- vehicle_id (str): The ID of the vehicle.
- tire_id (str): The ID of the tire.
Returns:
The response from the API if available or None if the request fails.
443 def add_tbox(self, tbox_info): 444 """ 445 Adds a new TBox to the Smart Tyre system. 446 Args: 447 tbox_info (dict): The information of the TBox to be added. 448 449 The dictionary should contain: 450 - tboxCode (str): The identification code of the TBox. 451 Must be 12 characters from 0-9 and A-F. 452 - version (str): The version of the TBox. Optional 453 - orgId (str): The ID of the organization. Optional 454 - ioTCardNumber (str): The IoT card number of the TBox. Optional 455 - carrier (str): The carrier of the TBox. Optional 456 - remark (str): Additional remarks about the TBox. Optional 457 458 Note: The tbox_info dictionary must follow the API requirements. 459 Check the API documentation for optional fields. 460 Returns: 461 The response from the API if available or None if the request fails. 462 """ 463 endpoint = "/smartyre/openapi/tbox/insert" 464 465 body_str = json.dumps(tbox_info, separators=(",", ":"), ensure_ascii=False) 466 467 return self._new_post_request( 468 endpoint=endpoint, 469 body=body_str, 470 returns_data=False, 471 )
Adds a new TBox to the Smart Tyre system.
Arguments:
tbox_info (dict): The information of the TBox to be added.
The dictionary should contain:
- tboxCode (str): The identification code of the TBox. Must be 12 characters from 0-9 and A-F.
- version (str): The version of the TBox. Optional
- orgId (str): The ID of the organization. Optional
- ioTCardNumber (str): The IoT card number of the TBox. Optional
- carrier (str): The carrier of the TBox. Optional
- remark (str): Additional remarks about the TBox. Optional
Note: The tbox_info dictionary must follow the API requirements. Check the API documentation for optional fields.
Returns:
The response from the API if available or None if the request fails.
473 def update_tbox(self, tbox_info): 474 """ 475 Updates an existing TBox in the Smart Tyre system. 476 Args: 477 tbox_info (dict): The information of the TBox to be updated. 478 479 The dictionary should contain: 480 - id (str): The ID of the TBox to be updated. 481 - tboxCode (str): The identification code of the Tbox to be updated. 482 Cannot be changed. 483 - version (str): The version of the TBox. Optional 484 - orgId (str): The ID of the organization. Optional 485 - ioTCardNumber (str): The IoT card number of the TBox. Optional 486 - carrier (str): The carrier of the TBox. Optional 487 - remark (str): Additional remarks about the TBox. Optional 488 489 Note: The tbox_info dictionary must follow the API requirements. 490 Check the API documentation for optional fields. 491 492 Returns: 493 The response from the API if available or None if the request fails. 494 """ 495 endpoint = "/smartyre/openapi/tbox/update" 496 497 body_str = json.dumps(tbox_info, separators=(",", ":"), ensure_ascii=False) 498 499 return self._new_post_request( 500 endpoint=endpoint, 501 body=body_str, 502 returns_data=False, 503 )
Updates an existing TBox in the Smart Tyre system.
Arguments:
tbox_info (dict): The information of the TBox to be updated.
The dictionary should contain:
- id (str): The ID of the TBox to be updated.
- tboxCode (str): The identification code of the Tbox to be updated. Cannot be changed.
- version (str): The version of the TBox. Optional
- orgId (str): The ID of the organization. Optional
- ioTCardNumber (str): The IoT card number of the TBox. Optional
- carrier (str): The carrier of the TBox. Optional
- remark (str): Additional remarks about the TBox. Optional
Note: The tbox_info dictionary must follow the API requirements. Check the API documentation for optional fields.
Returns:
The response from the API if available or None if the request fails.
505 def get_tboxes_list(self, params=None): 506 """ 507 Obtains the list of TBoxes from the Smart Tyre API. 508 509 Args: 510 params (dict): Optional parameters for filtering the TBox list. 511 Example: {"page": "1", "pageSize": "10"} 512 Note: The params dictionary must follow the API requirements. 513 Returns: 514 The list of TBoxes if available or None if the request fails. 515 """ 516 endpoint = "/smartyre/openapi/tbox/list" 517 518 return self._new_get_request(endpoint, params=params)
Obtains the list of TBoxes from the Smart Tyre API.
Arguments:
- params (dict): Optional parameters for filtering the TBox list. Example: {"page": "1", "pageSize": "10"}
Note: The params dictionary must follow the API requirements.
Returns:
The list of TBoxes if available or None if the request fails.
520 def get_tbox_info(self, tbox_id): 521 """ 522 Obtains information about a specific TBox. 523 Args: 524 tbox_id (str): The ID of the TBox. 525 Returns: 526 The detailed information about the TBox if available or None if the request fails. 527 """ 528 endpoint = "/smartyre/openapi/tbox/detail" 529 params = { 530 "id": [str(tbox_id)], 531 } 532 return self._new_get_request(endpoint, params=params)
Obtains information about a specific TBox.
Arguments:
- tbox_id (str): The ID of the TBox.
Returns:
The detailed information about the TBox if available or None if the request fails.
536 def add_sensor(self, sensor_info): 537 """ 538 Adds a new sensor to the Smart Tyre system. 539 Args: 540 sensor_info (dict): The information of the sensor to be added. 541 542 The dictionary should contain: 543 - sensorCode (str): The identification code of the sensor. 544 Must be 12 characters from 0-9 and A-F. 545 - version (str): The version of the sensor. Optional 546 - orgId (str): The ID of the organization. Optional 547 - remark (str): Additional remarks about the sensor. Optional 548 549 Note: The sensor_info dictionary must follow the API requirements. 550 Check the API documentation for optional fields. 551 Returns: 552 The response from the API if available or None if the request fails. 553 """ 554 endpoint = "/smartyre/openapi/sensor/insert" 555 556 body_str = json.dumps(sensor_info, separators=(",", ":"), ensure_ascii=False) 557 558 return self._new_post_request( 559 endpoint=endpoint, 560 body=body_str, 561 returns_data=False, 562 )
Adds a new sensor to the Smart Tyre system.
Arguments:
sensor_info (dict): The information of the sensor to be added.
The dictionary should contain:
- sensorCode (str): The identification code of the sensor. Must be 12 characters from 0-9 and A-F.
- version (str): The version of the sensor. Optional
- orgId (str): The ID of the organization. Optional
- remark (str): Additional remarks about the sensor. Optional
Note: The sensor_info dictionary must follow the API requirements. Check the API documentation for optional fields.
Returns:
The response from the API if available or None if the request fails.
564 def update_sensor(self, sensor_info): 565 """ 566 Updates an existing sensor in the Smart Tyre system. 567 Args: 568 sensor_info (dict): The information of the sensor to be updated. 569 570 The dictionary should contain: 571 - id (str): The ID of the sensor to be updated. 572 - sensorCode (str): The identification code of the sensor. 573 Must be 12 characters from 0-9 and A-F. 574 - version (str): The version of the sensor. Optional 575 - orgId (str): The ID of the organization. Optional 576 - remark (str): Additional remarks about the sensor. Optional 577 578 Note: The sensor_info dictionary must follow the API requirements. 579 Check the API documentation for optional fields. 580 Returns: 581 The response from the API if available or None if the request fails. 582 """ 583 endpoint = "/smartyre/openapi/sensor/update" 584 585 body_str = json.dumps(sensor_info, separators=(",", ":"), ensure_ascii=False) 586 587 return self._new_post_request( 588 endpoint=endpoint, 589 body=body_str, 590 returns_data=False, 591 )
Updates an existing sensor in the Smart Tyre system.
Arguments:
sensor_info (dict): The information of the sensor to be updated.
The dictionary should contain:
- id (str): The ID of the sensor to be updated.
- sensorCode (str): The identification code of the sensor. Must be 12 characters from 0-9 and A-F.
- version (str): The version of the sensor. Optional
- orgId (str): The ID of the organization. Optional
- remark (str): Additional remarks about the sensor. Optional
Note: The sensor_info dictionary must follow the API requirements. Check the API documentation for optional fields.
Returns:
The response from the API if available or None if the request fails.
593 def get_sensor_list(self, params=None): 594 """ 595 Obtains the list of sensors from the Smart Tyre API. 596 Args: 597 params (dict): Optional parameters for filtering the sensor list. 598 Example: {"page": "1", "pageSize": "10"} 599 Note: The params dictionary must follow the API requirements. 600 Returns: 601 The list of sensors if available or None if the request fails. 602 """ 603 endpoint = "/smartyre/openapi/sensor/list" 604 605 return self._new_get_request(endpoint, params=params)
Obtains the list of sensors from the Smart Tyre API.
Arguments:
- params (dict): Optional parameters for filtering the sensor list. Example: {"page": "1", "pageSize": "10"}
Note: The params dictionary must follow the API requirements.
Returns:
The list of sensors if available or None if the request fails.
607 def get_sensor_info(self, sensor_id): 608 """ 609 Obtains information about a specific sensor. 610 Args: 611 sensor_id (str): The ID of the sensor. 612 Returns: 613 The detailed information about the sensor if available or None if the request fails. 614 """ 615 endpoint = "/smartyre/openapi/sensor/detail" 616 params = { 617 "id": [str(sensor_id)], 618 } 619 return self._new_get_request(endpoint, params=params)
Obtains information about a specific sensor.
Arguments:
- sensor_id (str): The ID of the sensor.
Returns:
The detailed information about the sensor if available or None if the request fails.
621 def bind_sensor_to_tire(self, tire_code, vehicle_id, axle_index, wheel_index, sensor_code): 622 """ 623 Binds a sensor to a tire in the Smart Tyre system. 624 Args: 625 tire_code (str): The ID of the tire. 626 vehicle_id (str): The ID of the vehicle. 627 axle_index (int): The index of the axle. 628 wheel_index (int): The index of the wheel. 629 sensor_code (str): The ID of the sensor. 630 Returns: 631 The response from the API if available or None if the request fails. 632 """ 633 endpoint = "/smartyre/openapi/tyre/sensor/bind" 634 635 body = { 636 "tyreCode": tire_code, 637 "vehicleId": vehicle_id, 638 "axleIndex": axle_index, 639 "wheelIndex": wheel_index, 640 "sensorCode": sensor_code, 641 } 642 643 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 644 645 return self._new_post_request( 646 endpoint=endpoint, 647 body=body_str, 648 returns_data=False, 649 )
Binds a sensor to a tire in the Smart Tyre system.
Arguments:
- tire_code (str): The ID of the tire.
- vehicle_id (str): The ID of the vehicle.
- axle_index (int): The index of the axle.
- wheel_index (int): The index of the wheel.
- sensor_code (str): The ID of the sensor.
Returns:
The response from the API if available or None if the request fails.
651 def unbind_sensor_from_tire(self, tire_code, vehicle_id, axle_index, wheel_index, sensor_code): 652 """ 653 Unbinds a sensor from a tire in the Smart Tyre system. 654 Args: 655 tire_code (str): The ID of the tire. 656 vehicle_id (str): The ID of the vehicle. 657 axle_index (int): The index of the axle. 658 wheel_index (int): The index of the wheel. 659 sensor_code (str): The ID of the sensor. 660 Returns: 661 The response from the API if available or None if the request fails. 662 """ 663 endpoint = "/smartyre/openapi/tyre/sensor/unbind" 664 665 body = { 666 "tyreCode": tire_code, 667 "vehicleId": vehicle_id, 668 "axleIndex": axle_index, 669 "wheelIndex": wheel_index, 670 "sensorCode": sensor_code, 671 } 672 673 body_str = json.dumps(body, separators=(",", ":"), ensure_ascii=False) 674 675 return self._new_post_request( 676 endpoint=endpoint, 677 body=body_str, 678 returns_data=False, 679 )
Unbinds a sensor from a tire in the Smart Tyre system.
Arguments:
- tire_code (str): The ID of the tire.
- vehicle_id (str): The ID of the vehicle.
- axle_index (int): The index of the axle.
- wheel_index (int): The index of the wheel.
- sensor_code (str): The ID of the sensor.
Returns:
The response from the API if available or None if the request fails.
682 def get_tire_brands(self): 683 """ 684 Obtains the list of tire brands from the Smart Tyre API. 685 Returns: 686 The list of tire brands if available or None if the request fails. 687 """ 688 endpoint = "/smartyre/openapi/tyre/brand/all" 689 690 return self._new_get_request(endpoint, params={})
Obtains the list of tire brands from the Smart Tyre API.
Returns:
The list of tire brands if available or None if the request fails.
692 def get_tire_sizes(self): 693 """ 694 Obtains the list of tire sizes from the Smart Tyre API. 695 Returns: 696 The list of tire sizes if available or None if the request fails. 697 """ 698 endpoint = "/smartyre/openapi/tyre/size/all" 699 700 return self._new_get_request(endpoint, params={})
Obtains the list of tire sizes from the Smart Tyre API.
Returns:
The list of tire sizes if available or None if the request fails.
702 def get_vehicle_models(self): 703 """ 704 Obtains the list of vehicle models from the Smart Tyre API. 705 Returns: 706 The list of vehicle models if available or None if the request fails. 707 """ 708 endpoint = "/smartyre/openapi/vehicle/model/all" 709 710 return self._new_get_request(endpoint, params={})
Obtains the list of vehicle models from the Smart Tyre API.
Returns:
The list of vehicle models if available or None if the request fails.
712 def get_axle_types(self): 713 """ 714 Obtains the list of axle types from the Smart Tyre API. 715 Returns: 716 The list of axle types if available or None if the request fails. 717 """ 718 endpoint = "/smartyre/openapi/vehicle/axle/all" 719 720 return self._new_get_request(endpoint, params={})
Obtains the list of axle types from the Smart Tyre API.
Returns:
The list of axle types if available or None if the request fails.