diff options
| author | stuebinm | 2026-05-02 14:31:33 +0200 |
|---|---|---|
| committer | stuebinm | 2026-05-02 14:45:35 +0200 |
| commit | 5fa550010cd0d9293d253d9528a4029db26ced54 (patch) | |
| tree | 77f35fef62e4e725edeaa2a0b23879c49bd9253c /lib/OwnTracks/Command.hs | |
| parent | 4a1aa2f9ebd4624a677d99a4db77e4a564e56942 (diff) | |
owntracks: support returning commands
Diffstat (limited to 'lib/OwnTracks/Command.hs')
| -rw-r--r-- | lib/OwnTracks/Command.hs | 16 |
1 files changed, 16 insertions, 0 deletions
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" |
