Rename entity-list and snapshot helpers for consistency

This commit is contained in:
2026-09-29 23:52:46 +03:00
parent b643fe55b1
commit 9e00aeb6a2
2 changed files with 11 additions and 11 deletions
+7 -7
View File
@@ -19,8 +19,8 @@ import Data.Default (def)
bedroomLights :: [Target]
bedroomLights = map EntityId ["light.bedroom_masse","light.bedroom_jemina","light.bedroom_ceiling","light.bedroom_led_switch"]
bedroomLightTargets :: [Target]
bedroomLightTargets = map EntityId ["light.bedroom_masse","light.bedroom_jemina","light.bedroom_ceiling","light.bedroom_led_switch"]
createBedroomScene :: Service
createBedroomScene = Service
@@ -28,7 +28,7 @@ createBedroomScene = Service
, serviceName= "create"
, serviceData= Just $ object
[ "scene_id" .= ("makuuhuone_lights_snapshot" :: T.Text)
, "snapshot_entities" .= [l | EntityId l <- bedroomLights]
, "snapshot_entities" .= [l | EntityId l <- bedroomLightTargets]
]
, serviceTarget= []
}
@@ -50,16 +50,16 @@ presenceLightEvents =
offEvent = arr not >>> AFRP.waitFor 300 >>> arr (AFRP.tag LightingOff)
bedroomLightsSignal :: HASS (Event Value) (Map T.Text LightSnapshot)
bedroomLightsSignal = M.fromList <$> traverse (\e -> (e,) <$> observedLight e) [e | EntityId e <- bedroomLights]
bedroomLightSnapshots :: HASS (Event Value) (Map T.Text LightSnapshot)
bedroomLightSnapshots = M.fromList <$> traverse (\e -> (e,) <$> observedLight e) [e | EntityId e <- bedroomLightTargets]
bedroomPresenceController :: HASS (Event Value) ()
bedroomPresenceController = proc x -> do
p <- presenceLightEvents >>> traceEvent -< x
snap <- (doSnapshot &&& bedroomLightsSignal) >>> AFRP.snapshot M.empty >>> traceValue -< x
snap <- (doSnapshot &&& bedroomLightSnapshots) >>> AFRP.snapshot M.empty >>> traceValue -< x
case p of
Event LightingOff -> do
callService (light bedroomLights Off) -< ()
callService (light bedroomLightTargets Off) -< ()
Event LightingOn -> do
-- callService (activateSceneWith "scene.makuuhuone_lights_snapshot" transition) -< ()
callServicesDyn (concatMap (uncurry toLight)) -< M.toList snap
+4 -4
View File
@@ -31,16 +31,16 @@ livingroomPresence = presence "binary_sensor.occupancy_olohuone_derived" >>> AFR
-- With that in mind, I'll be explicitly controlling the two lights, without any scene shenanigans
lights :: [Target]
lights = [EntityId "light.livingroom_ceiling", EntityId "light.livingroom_sofa"]
livingroomLightTargets :: [Target]
livingroomLightTargets = [EntityId "light.livingroom_ceiling", EntityId "light.livingroom_sofa"]
livingroomPresenceController :: HASS (AFRP.Event Value) ()
livingroomPresenceController = proc x -> do
ev <- lightingModeEvents . livingroomPresence -< x
traceEvent -< ev
case ev of
AFRP.Event LightingOn -> callServiceDyn (light lights) -< On def
AFRP.Event LightingOff -> callServiceDyn (light lights) -< Off
AFRP.Event LightingOn -> callServiceDyn (light livingroomLightTargets) -< On def
AFRP.Event LightingOff -> callServiceDyn (light livingroomLightTargets) -< Off
_ -> returnA -< ()
returnA -< ()