Add requestHandler field to Request
This commit is contained in:
@@ -106,6 +106,7 @@ data Request = Request
|
|||||||
{ requestTime :: !UTCTime
|
{ requestTime :: !UTCTime
|
||||||
, requestTimeZone :: !TimeZone
|
, requestTimeZone :: !TimeZone
|
||||||
, requestTraceId :: !UUID
|
, requestTraceId :: !UUID
|
||||||
|
, requestHandler :: !T.Text
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ import HomeAssistant.Runtime.Supervisor (supervised)
|
|||||||
import HomeAssistant.Controller.Hallway (hallwayLightsController)
|
import HomeAssistant.Controller.Hallway (hallwayLightsController)
|
||||||
import qualified HttpServer
|
import qualified HttpServer
|
||||||
|
|
||||||
step :: (MonadIO m) => FilePath -> UUID -> Auto m a b -> a -> m (b, Auto m a b)
|
step :: (MonadIO m) => FilePath -> T.Text -> UUID -> Auto m a b -> a -> m (b, Auto m a b)
|
||||||
step path trace st a = do
|
step path name trace st a = do
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
tz <- liftIO getCurrentTimeZone
|
tz <- liftIO getCurrentTimeZone
|
||||||
let req = Request now tz trace
|
let req = Request now tz trace name
|
||||||
stepAutoSerializing path st req a
|
stepAutoSerializing path st req a
|
||||||
|
|
||||||
data Controller = forall b. Controller Bool T.Text (HASS (Event Value) b)
|
data Controller = forall b. Controller Bool T.Text (HASS (Event Value) b)
|
||||||
@@ -83,7 +83,7 @@ runController rootDir bus (Controller _enabled name machine ) = liftIO $ do
|
|||||||
go path inbound f = do
|
go path inbound f = do
|
||||||
msg <- atomically (readTChan inbound)
|
msg <- atomically (readTChan inbound)
|
||||||
uuid <- UUID.V4.nextRandom
|
uuid <- UUID.V4.nextRandom
|
||||||
(_, next) <- step path uuid f msg
|
(_, next) <- step path name uuid f msg
|
||||||
go path inbound next
|
go path inbound next
|
||||||
|
|
||||||
lookupPort :: IO Int
|
lookupPort :: IO Int
|
||||||
|
|||||||
+2
-2
@@ -21,7 +21,7 @@ import Test.Hspec
|
|||||||
import Test.Hspec.Hedgehog
|
import Test.Hspec.Hedgehog
|
||||||
|
|
||||||
fakeRequest :: Request
|
fakeRequest :: Request
|
||||||
fakeRequest = Request (sec 0) utc nil
|
fakeRequest = Request (sec 0) utc nil "test"
|
||||||
|
|
||||||
sec :: Integer -> UTCTime
|
sec :: Integer -> UTCTime
|
||||||
sec n = UTCTime (toEnum 0) (fromIntegral n)
|
sec n = UTCTime (toEnum 0) (fromIntegral n)
|
||||||
@@ -42,7 +42,7 @@ runTimed m = go (runMealy m id)
|
|||||||
where
|
where
|
||||||
go _ [] = []
|
go _ [] = []
|
||||||
go w ((s, a) : as) =
|
go w ((s, a) : as) =
|
||||||
case runIdentity (stepAuto w (Request (sec s) utc nil) a) of
|
case runIdentity (stepAuto w (Request (sec s) utc nil "test") a) of
|
||||||
(b, w') -> b : go w' as
|
(b, w') -> b : go w' as
|
||||||
|
|
||||||
-- | A minimal State monad for observing effectful arrows (e.g. whenA gating).
|
-- | A minimal State monad for observing effectful arrows (e.g. whenA gating).
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ spec = describe "Bus" $ do
|
|||||||
r2 `shouldBe` (Event (Number 1), Event (Number 2))
|
r2 `shouldBe` (Event (Number 1), Event (Number 2))
|
||||||
|
|
||||||
it "channelHassEval writes CallService to the outbound channel" $ withTestBus $ \bus -> do
|
it "channelHassEval writes CallService to the outbound channel" $ withTestBus $ \bus -> do
|
||||||
let req = Request (UTCTime (toEnum 0) 0) utc nil
|
let req = Request (UTCTime (toEnum 0) 0) utc nil "test"
|
||||||
svc = Service "light" "turn_on" Nothing [EntityId "light.bedroom_masse"]
|
svc = Service "light" "turn_on" Nothing [EntityId "light.bedroom_masse"]
|
||||||
runKatipContextT (busLogEnv bus) () (Namespace ["test"]) $
|
runKatipContextT (busLogEnv bus) () (Namespace ["test"]) $
|
||||||
channelHassEval bus (CallService req svc)
|
channelHassEval bus (CallService req svc)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ spec = do
|
|||||||
|
|
||||||
req :: Int -> Request
|
req :: Int -> Request
|
||||||
req n = Request (UTCTime (toEnum 0) (fromIntegral (0 :: Int))) utc
|
req n = Request (UTCTime (toEnum 0) (fromIntegral (0 :: Int))) utc
|
||||||
(fromJust (fromString uuid))
|
(fromJust (fromString uuid)) "test"
|
||||||
where
|
where
|
||||||
pad i = replicate (12 - length (show i)) '0' <> show i
|
pad i = replicate (12 - length (show i)) '0' <> show i
|
||||||
uuid = "00000000-0000-0000-0000-" <> pad n
|
uuid = "00000000-0000-0000-0000-" <> pad n
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ import AFRP (Mealy (..), Request (..), stepAuto)
|
|||||||
import HomeAssistant.Controller (HASSEff (..), Service)
|
import HomeAssistant.Controller (HASSEff (..), Service)
|
||||||
|
|
||||||
fakeRequest :: Request
|
fakeRequest :: Request
|
||||||
fakeRequest = Request (sec 0) utc nil
|
fakeRequest = Request (sec 0) utc nil "test"
|
||||||
|
|
||||||
sec :: Integer -> UTCTime
|
sec :: Integer -> UTCTime
|
||||||
sec n = UTCTime (toEnum 0) (fromIntegral n)
|
sec n = UTCTime (toEnum 0) (fromIntegral n)
|
||||||
|
|||||||
Reference in New Issue
Block a user