Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename mqtt client to publisher in state machine #282

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/isar/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def provide_state_machine(
robot: RobotInterface,
mqtt_client: MqttClientInterface,
) -> StateMachine:
return StateMachine(queues=queues, robot=robot, mqtt_client=mqtt_client)
return StateMachine(queues=queues, robot=robot, mqtt_publisher=mqtt_client)


class UtilitiesModule(Module):
Expand Down
22 changes: 12 additions & 10 deletions src/isar/state_machine/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
self,
queues: Queues,
robot: RobotInterface,
mqtt_client: MqttClientInterface,
mqtt_publisher: MqttClientInterface,
sleep_time: float = settings.FSM_SLEEP_TIME,
stop_robot_attempts_limit: int = settings.STOP_ROBOT_ATTEMPTS_LIMIT,
transitions_log_length: int = settings.STATE_TRANSITIONS_LOG_LENGTH,
Expand All @@ -54,6 +54,8 @@ def __init__(
Queues used for API communication.
robot : RobotInterface
Instance of robot interface.
mqtt_publisher : MqttClientInterface
Instance of MQTT client interface which has a publish function
sleep_time : float
Time to sleep in between state machine iterations.
stop_robot_attempts_limit : int
Expand All @@ -66,7 +68,7 @@ def __init__(

self.queues: Queues = queues
self.robot: RobotInterface = robot
self.mqtt_client: Optional[MqttClientInterface] = mqtt_client
self.mqtt_publisher: Optional[MqttClientInterface] = mqtt_publisher

# List of states
self.stop_step_state: State = StopStep(self)
Expand Down Expand Up @@ -377,7 +379,7 @@ def send_state_status(self):
self.queues.state.update(self.current_state)

def publish_mission_status(self) -> None:
if not self.mqtt_client:
if not self.mqtt_publisher:
return
payload: str = json.dumps(
{
Expand All @@ -389,15 +391,15 @@ def publish_mission_status(self) -> None:
cls=EnhancedJSONEncoder,
)

self.mqtt_client.publish(
self.mqtt_publisher.publish(
topic=settings.TOPIC_ISAR_MISSION,
payload=payload,
retain=True,
)

def publish_task_status(self) -> None:
"""Publishes the current task status to the MQTT Broker"""
if not self.mqtt_client:
if not self.mqtt_publisher:
return
payload: str = json.dumps(
{
Expand All @@ -410,15 +412,15 @@ def publish_task_status(self) -> None:
cls=EnhancedJSONEncoder,
)

self.mqtt_client.publish(
self.mqtt_publisher.publish(
topic=settings.TOPIC_ISAR_TASK,
payload=payload,
retain=True,
)

def publish_step_status(self) -> None:
"""Publishes the current step status to the MQTT Broker"""
if not self.mqtt_client:
if not self.mqtt_publisher:
return
payload: str = json.dumps(
{
Expand All @@ -432,14 +434,14 @@ def publish_step_status(self) -> None:
cls=EnhancedJSONEncoder,
)

self.mqtt_client.publish(
self.mqtt_publisher.publish(
topic=settings.TOPIC_ISAR_STEP,
payload=payload,
retain=True,
)

def publish_state(self) -> None:
if not self.mqtt_client:
if not self.mqtt_publisher:
return
payload: str = json.dumps(
{
Expand All @@ -450,7 +452,7 @@ def publish_state(self) -> None:
cls=EnhancedJSONEncoder,
)

self.mqtt_client.publish(
self.mqtt_publisher.publish(
topic=settings.TOPIC_ISAR_STATE,
payload=payload,
retain=True,
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def state_machine(injector, robot):
return StateMachine(
queues=injector.get(Queues),
robot=robot,
mqtt_client=injector.get(MqttClientInterface),
mqtt_publisher=injector.get(MqttClientInterface),
)


Expand Down