34
34
from robot_interface .models .mission .task import TASKS
35
35
from robot_interface .robot_interface import RobotInterface
36
36
from robot_interface .telemetry .mqtt_client import MqttClientInterface
37
+ from robot_interface .telemetry .payloads import (
38
+ RobotStatusPayload ,
39
+ MissionPayload ,
40
+ TaskPayload ,
41
+ )
37
42
from robot_interface .utilities .json_service import EnhancedJSONEncoder
38
43
39
44
@@ -482,24 +487,22 @@ def publish_mission_status(self) -> None:
482
487
if self .current_mission :
483
488
if self .current_mission .error_message :
484
489
error_message = self .current_mission .error_message
485
- payload : str = json .dumps (
486
- {
487
- "isar_id" : settings .ISAR_ID ,
488
- "robot_name" : settings .ROBOT_NAME ,
489
- "mission_id" : self .current_mission .id if self .current_mission else None ,
490
- "status" : self .current_mission .status if self .current_mission else None ,
491
- "error_reason" : error_message .error_reason if error_message else None ,
492
- "error_description" : (
493
- error_message .error_description if error_message else None
494
- ),
495
- "timestamp" : datetime .now (timezone .utc ),
496
- },
497
- cls = EnhancedJSONEncoder ,
490
+
491
+ payload : MissionPayload = MissionPayload (
492
+ isar_id = settings .ISAR_ID ,
493
+ robot_name = settings .ROBOT_NAME ,
494
+ mission_id = self .current_mission .id if self .current_mission else None ,
495
+ status = self .current_mission .status if self .current_mission else None ,
496
+ error_reason = error_message .error_reason if error_message else None ,
497
+ error_description = (
498
+ error_message .error_description if error_message else None
499
+ ),
500
+ timestamp = datetime .now (timezone .utc ),
498
501
)
499
502
500
503
self .mqtt_publisher .publish (
501
504
topic = settings .TOPIC_ISAR_MISSION ,
502
- payload = payload ,
505
+ payload = json . dumps ( payload , cls = EnhancedJSONEncoder ) ,
503
506
qos = 1 ,
504
507
retain = True ,
505
508
)
@@ -514,46 +517,41 @@ def publish_task_status(self, task: TASKS) -> None:
514
517
if task .error_message :
515
518
error_message = task .error_message
516
519
517
- payload : str = json .dumps (
518
- {
519
- "isar_id" : settings .ISAR_ID ,
520
- "robot_name" : settings .ROBOT_NAME ,
521
- "mission_id" : self .current_mission .id if self .current_mission else None ,
522
- "task_id" : task .id if task else None ,
523
- "status" : task .status if task else None ,
524
- "task_type" : task .type ,
525
- "error_reason" : error_message .error_reason if error_message else None ,
526
- "error_description" : (
527
- error_message .error_description if error_message else None
528
- ),
529
- "timestamp" : datetime .now (timezone .utc ),
530
- },
531
- cls = EnhancedJSONEncoder ,
520
+ payload : TaskPayload = TaskPayload (
521
+ isar_id = settings .ISAR_ID ,
522
+ robot_name = settings .ROBOT_NAME ,
523
+ mission_id = self .current_mission .id if self .current_mission else None ,
524
+ task_id = task .id if task else None ,
525
+ status = task .status if task else None ,
526
+ task_type = task .type if task else None ,
527
+ error_reason = error_message .error_reason if error_message else None ,
528
+ error_description = (
529
+ error_message .error_description if error_message else None
530
+ ),
531
+ timestamp = datetime .now (timezone .utc ),
532
532
)
533
533
534
534
self .mqtt_publisher .publish (
535
535
topic = settings .TOPIC_ISAR_TASK ,
536
- payload = payload ,
536
+ payload = json . dumps ( payload , cls = EnhancedJSONEncoder ) ,
537
537
qos = 1 ,
538
538
retain = True ,
539
539
)
540
540
541
541
def publish_status (self ) -> None :
542
542
if not self .mqtt_publisher :
543
543
return
544
- payload : str = json .dumps (
545
- {
546
- "isar_id" : settings .ISAR_ID ,
547
- "robot_name" : settings .ROBOT_NAME ,
548
- "status" : self ._current_status (),
549
- "timestamp" : datetime .now (timezone .utc ),
550
- },
551
- cls = EnhancedJSONEncoder ,
544
+
545
+ payload : RobotStatusPayload = RobotStatusPayload (
546
+ isar_id = settings .ISAR_ID ,
547
+ robot_name = settings .ROBOT_NAME ,
548
+ status = self ._current_status (),
549
+ timestamp = datetime .now (timezone .utc ),
552
550
)
553
551
554
552
self .mqtt_publisher .publish (
555
553
topic = settings .TOPIC_ISAR_STATUS ,
556
- payload = payload ,
554
+ payload = json . dumps ( payload , cls = EnhancedJSONEncoder ) ,
557
555
qos = 1 ,
558
556
retain = True ,
559
557
)
0 commit comments