runtime: count only trigger event frames and harden metrics tests
This commit is contained in:
@@ -9,7 +9,7 @@ import Data.Text (Text)
|
||||
import Data.Time (UTCTime (..), utc)
|
||||
import Data.UUID (fromString)
|
||||
import HomeAssistant.Controller (Service (..), Target(..))
|
||||
import HomeAssistant.Runtime.Connection (encodeService, dedupeBatch)
|
||||
import HomeAssistant.Runtime.Connection (encodeService, dedupeBatch, isTriggerEvent)
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
@@ -36,6 +36,14 @@ spec = do
|
||||
, "service_data" .= object ["brightness" .= (200 :: Int)]
|
||||
]
|
||||
|
||||
describe "isTriggerEvent" $ do
|
||||
it "is true for event frames" $
|
||||
isTriggerEvent (object ["type" .= ("event" :: Text)]) `shouldBe` True
|
||||
it "is false for result frames" $
|
||||
isTriggerEvent (object ["type" .= ("result" :: Text)]) `shouldBe` False
|
||||
it "is false when there is no type" $
|
||||
isTriggerEvent (object ["id" .= (1 :: Int)]) `shouldBe` False
|
||||
|
||||
describe "dedupeBatch" $ do
|
||||
it "collapses identical calls to one" $
|
||||
let batch = [ (req 1, lightOn [AreaId "x"])
|
||||
|
||||
Reference in New Issue
Block a user