diff options
Diffstat (limited to 'lib/OwnTracks/Location.hs')
| -rw-r--r-- | lib/OwnTracks/Location.hs | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/lib/OwnTracks/Location.hs b/lib/OwnTracks/Location.hs index de18596..b4bf807 100644 --- a/lib/OwnTracks/Location.hs +++ b/lib/OwnTracks/Location.hs @@ -57,10 +57,10 @@ instance FromJSON Trigger where "C" -> pure CircularRegionEnterLeavePlus "b" -> pure BeaconRegionEnterLeave "r" -> pure ReportLocationResponse - "m" -> pure ManualTrigger + "u" -> pure ManualTrigger "t" -> pure Timer "v" -> pure LocationsServices - _ -> fail "Unknown Trigger Type (not one of p, c, C, b, r, m, t, v)" + other -> fail $ show other <> "Unknown Trigger Type (not one of p, c, C, b, r, m, t, v)" parseJSON _ = fail "Trigger Type must be a string" data MonitoringMode = Quiet | Manual | Significant | Move @@ -93,7 +93,7 @@ data Location = Location -- ^ Altitude measured above sea level (iOS,Android/integer/meters/optional) , locationBattery :: Maybe Int -- ^ Device battery level (iOS,Android/integer/percent/optional) - , locationBatteryStatus :: BatteryStatus + , locationBatteryStatus :: Maybe BatteryStatus -- ^ Battery Status 0=unknown, 1=unplugged, 2=charging, 3=full (iOS, Android) , locationCourse :: Maybe Int -- ^ Course over ground (iOS/integer/degree/optional) @@ -143,38 +143,38 @@ data Location = Location instance FromJSON Location where parseJSON (Object v) = Location - <$> v .: "acc" - <*> v .: "alt" - <*> v .: "batt" - <*> (v .: "bs" <&> toEnum) - <*> v .: "cog" + <$> v .:? "acc" + <*> v .:? "alt" + <*> v .:? "batt" + <*> (v .:? "bs" <&> fmap toEnum) + <*> v .:? "cog" <*> v .: "lat" <*> v .: "lon" - <*> v .: "rad" - <*> v .: "t" - <*> v .: "tid" + <*> v .:? "rad" + <*> v .:? "t" + <*> v .:? "tid" <*> (v .: "tst" >>= parseUnixTime) - <*> v .: "vac" - <*> v .: "vel" - <*> v .: "p" - <*> v .: "poi" - <*> (v .: "image" >>= mapM fromBase64) - <*> v .: "imagename" - <*> (v .: "conn" >>= mapM parseConnection) - <*> v .: "tag" - <*> v .: "topic" - <*> v .: "inregions" - <*> v .: "inrids" - <*> (v .: "created_at" >>= mapM parseUnixTime) - <*> v .: "m" - <*> v .: "_id" - <*> v .: "motionactivities" - where parseUnixTime :: String -> Parser UTCTime - parseUnixTime = parseTimeM False defaultTimeLocale "%s" + <*> v .:? "vac" + <*> v .:? "vel" + <*> v .:? "p" + <*> v .:? "poi" + <*> (v .:? "image" >>= mapM fromBase64) + <*> v .:? "imagename" + <*> (v .:? "conn" >>= mapM parseConnection) + <*> v .:? "tag" + <*> v .:? "topic" + <*> v .:? "inregions" + <*> v .:? "inrids" + <*> (v .:? "created_at" >>= mapM parseUnixTime) + <*> v .:? "m" + <*> v .:? "_id" + <*> v .:? "motionactivities" + where parseUnixTime :: Int -> Parser UTCTime + parseUnixTime = parseTimeM False defaultTimeLocale "%s" . show parseConnection = withText "Connection" \case "o" -> pure Offline "m" -> pure Mobile - "w" -> Wifi <$> v .: "SSID" <*> v .: "BSSID" + "w" -> Wifi <$> v .:? "SSID" <*> v .:? "BSSID" fromBase64 v = case decodeBase64Untyped (encodeUtf8 v) of Right bytes -> pure bytes Left err -> fail $ "image field could not be read: " <> T.unpack err |
