Toggle controllers
This commit is contained in:
@@ -35,20 +35,20 @@ step nt trace (Mealy f) a = do
|
|||||||
now <- getCurrentTime
|
now <- getCurrentTime
|
||||||
f nt (Request now trace) a
|
f nt (Request now trace) a
|
||||||
|
|
||||||
data Controller = forall b. Controller T.Text (HASS (Event Value) b)
|
data Controller = forall b. Controller T.Text (HASS (Event Value) b) Bool
|
||||||
|
|
||||||
controllers :: [Controller]
|
controllers :: [Controller]
|
||||||
controllers =
|
controllers =
|
||||||
[ Controller "bedroom-presence" bedroomPresenceController
|
[ Controller "bedroom-presence" bedroomPresenceController False
|
||||||
, Controller "bedroom-button" bedroomButtonController
|
, Controller "bedroom-button" bedroomButtonController False
|
||||||
, Controller "bedroom-drawer" bedroomDrawerController
|
, Controller "bedroom-drawer" bedroomDrawerController True
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | Steps the machine for every inbound message; service calls go to the
|
-- | Steps the machine for every inbound message; service calls go to the
|
||||||
-- bus. A restart re-dups the inbound channel and starts from the machine's
|
-- bus. A restart re-dups the inbound channel and starts from the machine's
|
||||||
-- initial state; messages broadcast during the restart window are lost.
|
-- initial state; messages broadcast during the restart window are lost.
|
||||||
runController :: Bus -> Controller -> IO Void
|
runController :: Bus -> Controller -> IO Void
|
||||||
runController bus (Controller _name machine) = do
|
runController bus (Controller _name machine _enabled) = do
|
||||||
inbound <- atomically (dupTChan (busInbound bus))
|
inbound <- atomically (dupTChan (busInbound bus))
|
||||||
go inbound machine
|
go inbound machine
|
||||||
where
|
where
|
||||||
@@ -65,7 +65,7 @@ defaultMain = withSocketsDo $ do
|
|||||||
let workers =
|
let workers =
|
||||||
[ ("reader", readerAction "last-resort-redux" 8123 token bus)
|
[ ("reader", readerAction "last-resort-redux" 8123 token bus)
|
||||||
, ("writer", writerAction bus)
|
, ("writer", writerAction bus)
|
||||||
] ++ [ (name, runController bus c) | c@(Controller name _) <- controllers ]
|
] ++ [ (name, runController bus c) | c@(Controller name _ True) <- controllers ]
|
||||||
as <- mapM (\(name, act) -> async (supervised name defaultBackoff act)) workers
|
as <- mapM (\(name, act) -> async (supervised name defaultBackoff act)) workers
|
||||||
(_, v) <- waitAny as
|
(_, v) <- waitAny as
|
||||||
absurd v
|
absurd v
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ spec :: Spec
|
|||||||
spec = describe "runController" $ do
|
spec = describe "runController" $ do
|
||||||
it "feeds inbound events through the machine and forwards service calls" $ do
|
it "feeds inbound events through the machine and forwards service calls" $ do
|
||||||
bus <- newBus 0
|
bus <- newBus 0
|
||||||
_ <- async (runController bus (Controller "test" lightController))
|
_ <- async (runController bus (Controller "test" lightController True))
|
||||||
putStrLn "Before the delay"
|
putStrLn "Before the delay"
|
||||||
threadDelay 100000 -- let the controller dup its inbound channel
|
threadDelay 100000 -- let the controller dup its inbound channel
|
||||||
putStrLn "After the delay"
|
putStrLn "After the delay"
|
||||||
|
|||||||
Reference in New Issue
Block a user