Fix the ambience mode
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
{-# 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
|
||||
|
||||
-- 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` [[switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True], [switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] False, light [EntityId "light.kitchen_dining_large"] (On Nothing)]]
|
||||
|
||||
it "turns lights off when presence is unoccupied" $ do
|
||||
services (runHASS dinnerTableController [testDinnerLightLevel 10, testDinnerPresence "off"])
|
||||
`shouldBe` [[switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True], []]
|
||||
|
||||
it "does nothing on Tick" $ do
|
||||
services (runHASS dinnerTableController [Tick])
|
||||
`shouldBe` [[switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True]]
|
||||
Reference in New Issue
Block a user