packages feed

tesla 0.5.2.1 → 0.6.0.0

raw patch · 13 files changed

+45/−45 lines, 13 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Tesla.Car.Command: (.=) :: (KeyValue kv, ToJSON v) => Key -> v -> kv
+ Tesla.Car.Command: infixr 8 .=
+ Tesla.Car.Command: instance Data.Aeson.Types.ToJSON.ToJSON Tesla.Car.Command.Time
- Tesla.Car.Command: runCmd :: (MonadIO m, Postable p) => String -> p -> Car m CommandResponse
+ Tesla.Car.Command: runCmd :: MonadIO m => String -> [Pair] -> Car m CommandResponse

Files

src/Tesla/Car/Command.hs view
@@ -15,10 +15,11 @@ module Tesla.Car.Command (   Time(..), mkTime, fromTime,   runCmd, runCmd', CommandResponse, Car,+  (.=),   -- * TH support for generating commands.   mkCommand, mkCommands, mkNamedCommands) where -import           Control.Lens+import           Control.Lens hiding ((.=)) import           Control.Monad.IO.Class (MonadIO (..)) import           Data.Aeson import           Data.Aeson.Lens        (_Bool, _String, key)@@ -27,11 +28,12 @@ import           Data.Text              (Text) import           GHC.TypeNats import           Language.Haskell.TH-import           Network.Wreq.Types     (FormValue (..), Postable)+import           Network.Wreq.Types     (FormValue (..)) import           Text.Casing            (fromSnake, toCamel)  import           Tesla.Car import           Tesla.Internal.HTTP+import Data.Aeson.Types (Pair)  -- | A CommandResponse wraps an Either such that Left represents a -- failure message and Right suggests the command was successful.@@ -53,6 +55,9 @@ instance FormValue Time where   renderFormValue (Time x) = renderFormValue (getFinite x) +instance ToJSON Time where+  toJSON (Time x) = toJSON (getFinite x)+ -- | Make a 'Time' with the given hours and minutes. mkTime :: Finite 24 -> Finite 60 -> Time mkTime h m = Time $ modulo (toInteger h * 60 + toInteger m)@@ -64,18 +69,24 @@     f :: forall m n. (KnownNat m, KnownNat n, n <= m) => Finite m -> Finite n     f = modulo . toInteger --- | Run a command with a payload.-runCmd :: (MonadIO m, Postable p) => String -> p -> Car m CommandResponse+-- | Run a command with a JSON payload.+runCmd :: MonadIO m => String -> [Pair] -> Car m CommandResponse runCmd cmd p = do   v <- currentVehicleID-  j :: Value <- jpostAuth (vehicleURL v $ "command/" <> cmd) p+  j :: Value <- jpostAuth (vehicleURL v $ "command/" <> cmd) (object p)   pure $ case j ^? key "response" . key "result" . _Bool of     Just True -> Right ()     _         -> Left $ j ^. key "response" . key "reason" . _String + -- | Run command without a payload runCmd' :: MonadIO m => String -> Car m CommandResponse-runCmd' cmd = runCmd cmd BL.empty+runCmd' cmd =  do+  v <- currentVehicleID+  j :: Value <- jpostAuth (vehicleURL v $ "command/" <> cmd) BL.empty+  pure $ case j ^? key "response" . key "result" . _Bool of+    Just True -> Right ()+    _         -> Left $ j ^. key "response" . key "reason" . _String  instance FormValue Bool where   renderFormValue True  = "true"
src/Tesla/Car/Command/Charging.hs view
@@ -8,25 +8,24 @@   ) where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..))  import           Tesla.Car.Command  -- | Set the desired charge level (percent). setLimit :: MonadIO m => Int -> Car m CommandResponse-setLimit to = runCmd "set_charge_limit" ["percent" := to ]+setLimit to = runCmd "set_charge_limit" ["percent" .= to]  -- | Set the charge current. setAmps :: MonadIO m => Int -> Car m CommandResponse-setAmps to = runCmd "set_charging_amps" ["charging_amps" := to]+setAmps to = runCmd "set_charging_amps" ["charging_amps" .= to]  -- | Disable scheduled charging. scheduledChargingOff :: MonadIO m => Car m CommandResponse-scheduledChargingOff = runCmd "set_scheduled_charging" [ "enable" := False ]+scheduledChargingOff = runCmd "set_scheduled_charging" [ "enable" .= False ]  -- | Schedule charging for the given number of minutes after midnight (local time). scheduleCharging :: MonadIO m => Time -> Car m CommandResponse-scheduleCharging mins = runCmd "set_scheduled_charging" [ "enable" := True, "time" := mins ]+scheduleCharging mins = runCmd "set_scheduled_charging" [ "enable" .= True, "time" .= mins ]  mkNamedCommands [("startCharging", "charge_start"),                  ("stopCharging", "charge_stop"),
src/Tesla/Car/Command/Climate.hs view
@@ -13,13 +13,11 @@   ) where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..))- import           Tesla.Car.Command  -- | Turn on the steering wheel heater wheelHeater :: MonadIO m => Bool -> Car m CommandResponse-wheelHeater on = runCmd "remote_steering_wheel_heater_request" ["on" := on]+wheelHeater on = runCmd "remote_steering_wheel_heater_request" ["on" .= on]  wheelHeaterOn :: MonadIO m => Car m CommandResponse wheelHeaterOn = wheelHeater True@@ -31,13 +29,13 @@ -- -- If HVAC is off, turning on bioweapon defense mode will also turn on HVAC. bioweaponMode :: MonadIO m => Bool -> Car m CommandResponse-bioweaponMode on = runCmd "set_bioweapon_mode" ["on" := on]+bioweaponMode on = runCmd "set_bioweapon_mode" ["on" .= on]  data Seat = DriverSeat | PassengerSeat | RearLeftSeat | RearCenterSeat | RearRightSeat  -- | Set heating levels for various seats. heatSeat :: MonadIO m => Seat -> Int -> Car m CommandResponse-heatSeat seat level = runCmd "remote_seat_heater_request" ["heater" := seatNum seat, "level" := level]+heatSeat seat level = runCmd "remote_seat_heater_request" ["heater" .= seatNum seat, "level" .= level]   where     seatNum :: Seat -> Int     seatNum DriverSeat     = 0@@ -48,13 +46,13 @@  -- | Set the main HVAC temperatures. setTemps :: MonadIO m => (Double, Double) -> Car m CommandResponse-setTemps (driver, passenger) = runCmd "set_temps" ["driver_temp" := driver, "passenger_temp" := passenger]+setTemps (driver, passenger) = runCmd "set_temps" ["driver_temp" .= driver, "passenger_temp" .= passenger]  maxDefrost :: MonadIO m => Bool -> Car m CommandResponse-maxDefrost on = runCmd "set_preconditioning_max" ["on" := on]+maxDefrost on = runCmd "set_preconditioning_max" ["on" .= on]  scheduledDepartureOff :: MonadIO m => Car m CommandResponse-scheduledDepartureOff = runCmd "set_scheduled_departure" [ "enable" := False ]+scheduledDepartureOff = runCmd "set_scheduled_departure" [ "enable" .= False ]  -- | When configuring scheduled departure, preconditioning and -- off-peak charging both have weekday only options.@@ -74,17 +72,17 @@ -- For this to do anything useful, you need to specify at least one of -- 'Preconditioning' and/or 'OffPeakConfig'. scheduleDeparture :: MonadIO m => Time -> Preconditioning -> Maybe OffPeakConfig -> Car m CommandResponse-scheduleDeparture t p o = runCmd "set_scheduled_departure" (["enable" := True, "departure_time" := t] <> pp <> op o)+scheduleDeparture t p o = runCmd "set_scheduled_departure" (["enable" .= True, "departure_time" .= t] <> pp <> op o)   where     pp = s "preconditioning_enabled" "preconditioning_weekdays_only" p     op Nothing  = opp (OffPeakConfig Never (Time 0))     op (Just x) = opp x-    opp OffPeakConfig{..} = ("end_off_peak_time" := _offPeakEndTime) : s "off_peak_charging_enabled" "off_peak_charging_weekdays_only" _offPeakEnabled+    opp OffPeakConfig{..} = ("end_off_peak_time" .= _offPeakEndTime) : s "off_peak_charging_enabled" "off_peak_charging_weekdays_only" _offPeakEnabled      s e w = \case-           Never        -> [e := False, w := False]-           Always       -> [e := True, w := False]-           WeekdaysOnly -> [e := True, w := True]+           Never        -> [e .= False, w .= False]+           Always       -> [e .= True, w .= False]+           WeekdaysOnly -> [e .= True, w .= True]  mkNamedCommands [("hvacOn", "auto_conditioning_start"),                  ("hvacOff", "auto_conditioning_stop"),
src/Tesla/Car/Command/Doors.hs view
@@ -7,11 +7,10 @@   ) where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..)) import           Tesla.Car.Command  atr :: MonadIO m => String -> Car m CommandResponse-atr w = runCmd "actuate_trunk" [ "which_trunk" := w ]+atr w = runCmd "actuate_trunk" [ "which_trunk" .= w ]  actuateFrontTrunk :: MonadIO m => Car m CommandResponse actuateFrontTrunk = atr "front"
src/Tesla/Car/Command/Homelink.hs view
@@ -3,9 +3,8 @@ module Tesla.Car.Command.Homelink (trigger) where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..)) import           Tesla.Car.Command  -- | Trigger nearby homelink with the given (lat,lon) trigger :: MonadIO m => (Double, Double) -> Car m CommandResponse-trigger (lat,lon) = runCmd "flash_lights" ["lat" := lat, "lon" := lon]+trigger (lat,lon) = runCmd "flash_lights" ["lat" .= lat, "lon" .= lon]
src/Tesla/Car/Command/RemoteStart.hs view
@@ -3,7 +3,6 @@ module Tesla.Car.Command.RemoteStart where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..))  import           Tesla.Car.Command @@ -11,4 +10,4 @@ -- -- This requires your account password, so, you know, be careful where you use it. remoteStart :: MonadIO m => String -> Car m CommandResponse-remoteStart pw = runCmd "remote_start_drive" ["password" := pw]+remoteStart pw = runCmd "remote_start_drive" ["password" .= pw]
src/Tesla/Car/Command/Sentry.hs view
@@ -5,9 +5,8 @@   ) where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..))  import           Tesla.Car.Command  setSentryMode :: MonadIO m => Bool -> Car m CommandResponse-setSentryMode on = runCmd "set_sentry_mode" [ "on" := on ]+setSentryMode on = runCmd "set_sentry_mode" [ "on" .= on ]
src/Tesla/Car/Command/Sharing.hs view
@@ -12,7 +12,7 @@ share :: MonadIO m => Text -> Car m CommandResponse share to = do   now <- fst . properFraction . utcTimeToPOSIXSeconds <$> liftIO getCurrentTime-  runCmd "share" $ object [+  runCmd "share" [     "type" .= ("share_ext_content_raw" :: Text),     "value" .= object [ "android.intent.extra.TEXT" .= to ],     "locale" .= ("en-US" :: Text),
src/Tesla/Car/Command/Software.hs view
@@ -6,13 +6,12 @@   ) where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..))  import           Tesla.Car.Command  -- | Schedule a software update in this many seconds. scheduleUpdate :: MonadIO m => Int -> Car m CommandResponse-scheduleUpdate secs = runCmd "schedule_software_update" ["offset_sec" := secs]+scheduleUpdate secs = runCmd "schedule_software_update" ["offset_sec" .= secs]  -- | Cancel a scheduled software update. mkCommand "cancelUpdate" "cancel_software_update"
src/Tesla/Car/Command/SpeedLimit.hs view
@@ -5,14 +5,13 @@   ) where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..)) import           Tesla.Car.Command  speedLimit :: MonadIO m => Int -> Car m CommandResponse-speedLimit to = runCmd "speed_limit_set_limit" ["limit_mph" := to ]+speedLimit to = runCmd "speed_limit_set_limit" ["limit_mph" .= to ]  speedo :: MonadIO m => String -> Int -> Car m CommandResponse-speedo c pin = runCmd c ["pin" := pin ]+speedo c pin = runCmd c ["pin" .= pin ]  activateSpeedLimit :: MonadIO m => Int -> Car m CommandResponse activateSpeedLimit = speedo "speed_limit_activate"
src/Tesla/Car/Command/Valet.hs view
@@ -6,11 +6,10 @@   ) where  import           Control.Monad.IO.Class (MonadIO (..))-import           Network.Wreq           (FormParam (..))  import           Tesla.Car.Command  setValetMode :: MonadIO m => Bool -> Int -> Car m CommandResponse-setValetMode on pin = runCmd "set_valet_mode" [ "on" := on, "password" := pin]+setValetMode on pin = runCmd "set_valet_mode" [ "on" .= on, "password" .= pin]  mkCommand "clearValetPIN" "reset_valet_pin"
src/Tesla/Car/Command/Windows.hs view
@@ -6,12 +6,11 @@  import           Control.Monad.IO.Class (MonadIO (..)) import           Data.Text              (Text)-import           Network.Wreq           (FormParam (..))  import           Tesla.Car.Command  windowControl :: MonadIO m => Text -> (Double, Double) -> Car m CommandResponse-windowControl x (lat,lon) = runCmd "window_control" [ "command" := x, "lat" := lat, "lon" := lon]+windowControl x (lat,lon) = runCmd "window_control" [ "command" .= x, "lat" .= lat, "lon" .= lon]  ventWindows :: MonadIO m => Car m CommandResponse ventWindows = windowControl "vent" (0,0)@@ -20,7 +19,7 @@ closeWindows = windowControl "close"  sc :: MonadIO m => Text -> Car m CommandResponse-sc c = runCmd "sun_roof_control" [ "state" := c ]+sc c = runCmd "sun_roof_control" [ "state" .= c ]  ventSunroof :: MonadIO m => Car m CommandResponse ventSunroof = sc "vent"
tesla.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 2bd36802a7822687aeb0c3da485dcc9474c7d806ea6e6eeeca899b09bad7af39+-- hash: 44f2c38345f7a71e96cf36e8d5f45c3c741ba014fb6122e6d9ca4b3e136d0d0f  name:           tesla-version:        0.5.2.1+version:        0.6.0.0 synopsis:       Tesla API client. description:    Please see the README on GitHub at <https://github.com/dustin/tesla#readme> category:       Web