Try a separate holdKnown primitive

This commit is contained in:
MasseR committed 2026-10-12 11:11:37 +03:00
1 parent 8a4a5aef33
commit 55855db55b
2 files changed
+10 -3

No files matched your search

+4 -3
View File
@@ -19,6 +19,7 @@ import Data.Aeson.Types (ToJSON (..))
import Data.Aeson.Lens (key, _String)
import Control.Lens ((^?), to)
import Data.Text (Text)
import Control.Monad (join)
-- Let's see building some reasonable interface for utctime
dow :: Day -> (WeekOfYear, Int)
@@ -131,8 +132,8 @@ data HumidifierAction
instance Serialize HumidifierAction
-- what is the humidifer doing right now?
humidifierEntityAction :: HASS (Event Value) (Event (Maybe HumidifierAction))
humidifierEntityAction = entityChangeEvent "humidifier.lapset_ilmankostutin"
humidifierOperatingState :: HASS (Event Value) (Event (Maybe HumidifierAction))
humidifierOperatingState = entityChangeEvent "humidifier.lapset_ilmankostutin"
>>> arr (fmap entityAction)
where
entityAction v = v ^? key "event" . key "variables" . key "trigger" . key "to_state" . key "attributes" . key "action" . _String . to humidifierAction
@@ -149,7 +150,7 @@ instance ToJSON Percentage where
childrenAirFilterController :: HASS (Event Value) ()
childrenAirFilterController = proc ev -> do
level <- pm25 >>> pm25Level >>> AFRP.changes >>> traceEvent -< ev
humidifier <- humidifierEntityAction >>> AFRP.hold Nothing -< ev
humidifier <- humidifierOperatingState >>> AFRP.holdKnown >>> arr join -< ev
case level of
Event PM25High ->
AFRP.whenA (== Just Idle) (callService (fanOnTo (Percentage 80))) -< humidifier