FlowFuse / device-agent

An agent to run FlowFuse managed instances of Node-RED on devices
Apache License 2.0
15 stars 8 forks source link

Add support for device actions #239

Closed Steve-Mcl closed 6 months ago

Steve-Mcl commented 7 months ago

Ready to review, but please do not merge until both this and https://github.com/FlowFuse/flowfuse/pull/3548 are approved (in case of change requests from either side)

Description

Outline

Adds support for suspend, start and restart MQTT command actions (via the platform device comms)

Demo of FF side

slack_NJFblfEk72

Sample output from device agent when the actions are executed:

image

Details

Tests added

  Agent
    actions
      ✔ suspends Node-RED
      ✔ reloads target state as suspended
      ✔ reloads target state as running
      ✔ restarts Node-RED
      ✔ starts Node-RED after suspend
    getState
      ✔ returns state when suspended

  MQTT Comms
    ✔ suspend action calls agent.suspendNR and checks in (573ms)
    ✔ start action calls agent.startNR and checks in (567ms)
    ✔ restart action calls agent.restartNR and checks in (576ms)
    ✔ Invalid action responds with error (568ms)

  State validation
    ✔ isValidState should return true for valid states
    ✔ isValidState should return false for invalid states
    ✔ isTargetState should return true for valid target states
    ✔ isTargetState should return false for invalid target states
    ✔ isTransitionState should return true for valid transition states
    ✔ isTransitionState should return false for invalid transition states

Related Issue(s)

https://github.com/FlowFuse/flowfuse/issues/3292

Checklist

Labels

hardillb commented 6 months ago

Not merging as pair PR not merged into forge app

knolleary commented 6 months ago

No structural changes being made in the forge app around how it will send commands to the device agent. We are only shipping the restart command initially as there are unresolved questions on the semantics of suspend (and thus start is also unnecessary).

@Steve-Mcl I think we're okay to merge this as-is?

Steve-Mcl commented 6 months ago

No structural changes being made in the forge app around how it will send commands to the device agent. We are only shipping the restart command initially as there are unresolved questions on the semantics of suspend (and thus start is also unnecessary).

@Steve-Mcl I think we're okay to merge this as-is?

Yeah. Ben and I have tested against local and staging.