Capped based on light level
This commit is contained in:
1 parent
c75fc1a7b9
commit
cceddad037
3 files changed
+38
-33
No files matched your search
@@ -1,5 +1,6 @@
|
||||
{-# LANGUAGE Arrows #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE StrictData #-}
|
||||
|
||||
module HomeAssistant.Controller.Light.Observation
|
||||
( LightObservation(..)
|
||||
@@ -8,7 +9,7 @@ module HomeAssistant.Controller.Light.Observation
|
||||
, lightTemperatureEvent
|
||||
) where
|
||||
|
||||
import AFRP (Event, hold, toEvent, (>>|))
|
||||
import AFRP (Event, hold)
|
||||
import Control.Arrow (arr, returnA)
|
||||
import Control.Category ((>>>), (.))
|
||||
import Control.Lens ((^?))
|
||||
@@ -17,30 +18,28 @@ import Data.Aeson.Lens (key, _Integral)
|
||||
import qualified Data.Text as T
|
||||
import GHC.Generics (Generic)
|
||||
import Data.Serialize (Serialize)
|
||||
import HomeAssistant.Controller.Entity (entityChangeEvent', entityBool)
|
||||
import HomeAssistant.Controller.Entity (entityBool, entityChangeEvent)
|
||||
import HomeAssistant.Controller.Effect (HASS)
|
||||
import Prelude hiding ((.))
|
||||
|
||||
lightBrightnessEvent :: T.Text -> HASS (Event Value) (Event Int)
|
||||
lightBrightnessEvent :: T.Text -> HASS (Event Value) (Event (Maybe Int))
|
||||
lightBrightnessEvent entityId =
|
||||
entityChangeEvent' entityId
|
||||
>>| arr (maybe (Left ()) Right . eventBrightness)
|
||||
>>> AFRP.toEvent
|
||||
entityChangeEvent entityId
|
||||
>>> arr (fmap eventBrightness)
|
||||
where
|
||||
eventBrightness v = v ^? key "event" . key "variables" . key "trigger" . key "to_state" . key "attributes" . key "brightness" . _Integral
|
||||
|
||||
lightTemperatureEvent :: T.Text -> HASS (Event Value) (Event Int)
|
||||
lightTemperatureEvent :: T.Text -> HASS (Event Value) (Event (Maybe Int))
|
||||
lightTemperatureEvent entityId =
|
||||
entityChangeEvent' entityId
|
||||
>>| arr (maybe (Left ()) Right . eventTemperature)
|
||||
>>> AFRP.toEvent
|
||||
entityChangeEvent entityId
|
||||
>>> arr (fmap eventTemperature)
|
||||
where
|
||||
eventTemperature v = v ^? key "event" . key "variables" . key "trigger" . key "to_state" . key "attributes" . key "color_temp_kelvin" . _Integral
|
||||
|
||||
data LightObservation = LightObservation
|
||||
{ observedOn :: Bool
|
||||
, observedBrightness :: Int
|
||||
, observedTemperature :: Int
|
||||
, observedBrightness :: Maybe Int
|
||||
, observedTemperature :: Maybe Int
|
||||
}
|
||||
deriving (Show, Generic, Eq)
|
||||
instance Serialize LightObservation
|
||||
@@ -48,6 +47,6 @@ instance Serialize LightObservation
|
||||
observedLight :: T.Text -> HASS (Event Value) LightObservation
|
||||
observedLight entityId = proc ev -> do
|
||||
e <- hold False . entityBool entityId -< ev
|
||||
b <- hold 0 . lightBrightnessEvent entityId -< ev
|
||||
t <- hold 0 . lightTemperatureEvent entityId -< ev
|
||||
b <- hold Nothing . lightBrightnessEvent entityId -< ev
|
||||
t <- hold Nothing . lightTemperatureEvent entityId -< ev
|
||||
returnA -< LightObservation e b t
|
||||
Reference in new issue
Block a user