Store a custom snapshot of lights

This commit is contained in:
2026-09-29 22:51:37 +03:00
parent fcaccfdeb0
commit fefeae6301
15 changed files with 173 additions and 24 deletions
+29
View File
@@ -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)])