From 5fa550010cd0d9293d253d9528a4029db26ced54 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sat, 2 May 2026 14:31:33 +0200 Subject: owntracks: support returning commands --- lib/OwnTracks/Command.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/OwnTracks/Command.hs') diff --git a/lib/OwnTracks/Command.hs b/lib/OwnTracks/Command.hs index 257d3e3..532a593 100644 --- a/lib/OwnTracks/Command.hs +++ b/lib/OwnTracks/Command.hs @@ -42,6 +42,7 @@ data Command = -- ^ Imports and activates new configuration values (iOS,Android) | GetWaypoints -- ^ Triggers publish of a waypoints message (iOS,Android) + deriving (Eq, Show, Generic) instance ToJSON Command where toJSON c = object ( "_type" .= String "cmd" @@ -61,3 +62,18 @@ instance ToJSON Command where SetWaypoints ws -> [ "waypoints" .= ws ] SetConfiguration c -> [ "configuration" .= c ] _ -> [] + +instance FromJSON Command where + parseJSON (Object v) = do + action :: Text <- v .: "action" + case action of + "dump" -> pure Dump + "status" -> pure GetStatus + "reportSteps" -> ReportSteps <$> v .: "from" <*> v .: "to" + "reportLocation" -> pure ReportLocation + "clearWaypoints" -> pure ClearWaypoints + "setWaypoints" -> SetWaypoints <$> v .: "waypoints" + "setConfiguration" -> SetConfiguration <$> v .: "configuration" + "waypoints" -> pure GetWaypoints + _ -> fail "unknown action in _type=command" + parseJSON _ = fail "Command should be an object" -- cgit v1.2.3