Store a custom snapshot of lights
This commit is contained in:
+2
-2
@@ -49,8 +49,8 @@ entitySpec = describe "entities" $ do
|
||||
]
|
||||
|
||||
it "bedroomPresenceController subscribes to the presence sensor" $
|
||||
entities bedroomPresenceController
|
||||
`shouldBe` S.singleton "binary_sensor.presence_sensor_bedroom_occupancy"
|
||||
S.toList (entities bedroomPresenceController)
|
||||
`shouldContain` [ "binary_sensor.presence_sensor_bedroom_occupancy" ]
|
||||
|
||||
it "humidifierController subscribes to the door sensor" $
|
||||
entities humidifierController
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module ControllerSpec where
|
||||
import Test.Hspec
|
||||
import Data.Default (def)
|
||||
import HomeAssistant.Controller (BrightnessSettings(..), formatLightSettings, LightSettings(..))
|
||||
import Data.Aeson (object, (.=))
|
||||
import HomeAssistant.Controller ()
|
||||
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "Generic controller" $
|
||||
describe "Light settings" $ do
|
||||
it "formats the default as empty" $
|
||||
formatLightSettings def `shouldBe` Nothing
|
||||
it "formats the transition" $
|
||||
formatLightSettings def{lightSettingsTransition=Just 5} `shouldBe`
|
||||
Just (object ["transition" .= (5 :: Int)])
|
||||
it "formats the temperature" $
|
||||
formatLightSettings def{lightSettingsTemperature=Just 5} `shouldBe`
|
||||
Just (object ["color_temp_kelvin" .= (5 :: Int)])
|
||||
it "formats the brightness as percentage" $
|
||||
formatLightSettings def{lightSettingsBrightness=Just (BrightnessPercentage 100)} `shouldBe`
|
||||
Just (object ["brightness_pct" .= (100 :: Int)])
|
||||
it "formats the brightness as absolute" $
|
||||
formatLightSettings def{lightSettingsBrightness=Just (Brightness 200)} `shouldBe`
|
||||
Just (object ["brightness" .= (200 :: Int)])
|
||||
it "formats multiple values" $
|
||||
formatLightSettings def{lightSettingsTransition = Just 5, lightSettingsBrightness=Just (Brightness 200)} `shouldBe`
|
||||
Just (object ["brightness" .= (200 :: Int), "transition" .= (5 :: Int)])
|
||||
+3
-2
@@ -10,6 +10,7 @@ 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
|
||||
@@ -34,7 +35,7 @@ dinnerTableSpec = describe "dinnerTableController" $ do
|
||||
|
||||
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)]]
|
||||
`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 def)]]
|
||||
|
||||
it "turns lights off when presence is unoccupied" $ do
|
||||
services (runHASS dinnerTableController [testDinnerLightLevel 10, testDinnerPresence "off"])
|
||||
@@ -42,4 +43,4 @@ dinnerTableSpec = describe "dinnerTableController" $ do
|
||||
|
||||
it "does nothing on Tick" $ do
|
||||
services (runHASS dinnerTableController [Tick])
|
||||
`shouldBe` [[switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True]]
|
||||
`shouldBe` [[switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True]]
|
||||
|
||||
@@ -12,6 +12,7 @@ import qualified KitchenSpec
|
||||
import qualified LivingroomSpec
|
||||
import qualified MetricsSpec
|
||||
import qualified RuntimeSpec
|
||||
import qualified ControllerSpec
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
@@ -26,3 +27,4 @@ main = hspec $ do
|
||||
LivingroomSpec.spec
|
||||
MetricsSpec.spec
|
||||
RuntimeSpec.spec
|
||||
ControllerSpec.spec
|
||||
|
||||
Reference in New Issue
Block a user