47 lines
2.0 KiB
Haskell
47 lines
2.0 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module KitchenSpec (spec) where
|
|
|
|
import AFRP (Event (..), entities)
|
|
import qualified Data.Set as S
|
|
import qualified Data.Text as T
|
|
import Data.Aeson (Value)
|
|
import HomeAssistant.Controller
|
|
import HomeAssistant.Controller.Kitchen
|
|
import Support
|
|
import Test.Hspec
|
|
import Data.Default (def)
|
|
|
|
-- Helper functions for creating test events
|
|
testDinnerLightLevel :: Int -> Event Value
|
|
testDinnerLightLevel level = Event (stateEvent "sensor.sijainti_keittio_light_level" (T.pack $ show level))
|
|
|
|
testDinnerPresence :: T.Text -> Event Value
|
|
testDinnerPresence state = Event (stateEvent "binary_sensor.sijainti_keittio_occupancy" state)
|
|
|
|
spec :: Spec
|
|
spec = describe "Kitchen" $ do
|
|
dinnerTableSpec
|
|
|
|
dinnerTableSpec :: Spec
|
|
dinnerTableSpec = describe "dinnerTableController" $ do
|
|
it "subscribes to the light level sensor" $ do
|
|
entities dinnerTableController
|
|
`shouldBe` S.fromList ["sensor.sijainti_keittio_light_level", "binary_sensor.sijainti_keittio_occupancy"]
|
|
|
|
it "subscribes to the presence sensor" $ do
|
|
entities dinnerTableController
|
|
`shouldBe` S.fromList ["sensor.sijainti_keittio_light_level", "binary_sensor.sijainti_keittio_occupancy"]
|
|
|
|
it "turns lights on when presence is occupied and light level is low" $ do
|
|
services (runHASS dinnerTableController [testDinnerLightLevel 10, testDinnerPresence "on"])
|
|
`shouldBe` [[switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True], [switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] False, light [EntityId "light.kitchen_dining_large"] (On def)]]
|
|
|
|
it "turns lights off when presence is unoccupied" $ do
|
|
services (runHASS dinnerTableController [testDinnerLightLevel 10, testDinnerPresence "off"])
|
|
`shouldBe` [[switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True], []]
|
|
|
|
it "does nothing on Tick" $ do
|
|
services (runHASS dinnerTableController [Tick])
|
|
`shouldBe` [[switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True]]
|