HUmidifier logic with some extra new primitives

This commit is contained in:
2026-08-21 15:46:31 +03:00
parent 8ea013c94a
commit 96d4fb4c8d
4 changed files with 104 additions and 18 deletions
+6 -15
View File
@@ -19,13 +19,12 @@ module HomeAssistant.Controller
, ruuviTemperatures
, ruuviPressures
, DoorState(..)
, door
, light
, lightController
, Presence(..)
, presence
, debug
, traceEvent
, traceValue
, switch
, Target(..)
) where
@@ -71,6 +70,11 @@ traceEvent = Mealy $ \nt req -> \case
Event a -> nt (Trace req a) >>= \() -> pure (Event a, traceEvent)
Tick -> pure (Tick, traceEvent)
traceValue :: Show a => HASS a a
traceValue = proc x -> do
eff Trace -< x
returnA -< x
ruuviTemperatures :: Mealy eff (Event Value) Double
ruuviTemperatures = entityRead @Double "sensor.ruuvitag_b168_temperature" >>> hold 0
@@ -95,11 +99,6 @@ presence entityId =entityBool entityId
door :: HASS (Event Value) (Event DoorState)
door = entityBool "binary_sensor.makuuhuone_ovi_contact"
>>> arr (fmap (bool Closed Open))
>>> hold Open
>>> changes
-- Turn off lights when door is closed
light :: [Target] -> Bool -> Service
@@ -119,14 +118,6 @@ switch targets b = Service
, serviceTarget=targets
}
lightController :: HASS (Event Value) (Event DoorState)
lightController = proc ev -> do
doorState <- door -< ev
case doorState of
Event Open -> callService (light [EntityId "light.bedroom_masse"] False) -< ()
Event Closed -> callService (light [EntityId "light.bedroom_masse"] True) -< ()
_ -> returnA -< ()
returnA -< doorState
entityChangeEvent :: T.Text -> Mealy eff (Event Value) (Event Value)
entityChangeEvent entityId = entityChangeEvent' entityId >>> toEvent