Rename entity-list and snapshot helpers for consistency
This commit is contained in:
@@ -19,8 +19,8 @@ import Data.Default (def)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bedroomLights :: [Target]
|
bedroomLightTargets :: [Target]
|
||||||
bedroomLights = map EntityId ["light.bedroom_masse","light.bedroom_jemina","light.bedroom_ceiling","light.bedroom_led_switch"]
|
bedroomLightTargets = map EntityId ["light.bedroom_masse","light.bedroom_jemina","light.bedroom_ceiling","light.bedroom_led_switch"]
|
||||||
|
|
||||||
createBedroomScene :: Service
|
createBedroomScene :: Service
|
||||||
createBedroomScene = Service
|
createBedroomScene = Service
|
||||||
@@ -28,7 +28,7 @@ createBedroomScene = Service
|
|||||||
, serviceName= "create"
|
, serviceName= "create"
|
||||||
, serviceData= Just $ object
|
, serviceData= Just $ object
|
||||||
[ "scene_id" .= ("makuuhuone_lights_snapshot" :: T.Text)
|
[ "scene_id" .= ("makuuhuone_lights_snapshot" :: T.Text)
|
||||||
, "snapshot_entities" .= [l | EntityId l <- bedroomLights]
|
, "snapshot_entities" .= [l | EntityId l <- bedroomLightTargets]
|
||||||
]
|
]
|
||||||
, serviceTarget= []
|
, serviceTarget= []
|
||||||
}
|
}
|
||||||
@@ -50,16 +50,16 @@ presenceLightEvents =
|
|||||||
offEvent = arr not >>> AFRP.waitFor 300 >>> arr (AFRP.tag LightingOff)
|
offEvent = arr not >>> AFRP.waitFor 300 >>> arr (AFRP.tag LightingOff)
|
||||||
|
|
||||||
|
|
||||||
bedroomLightsSignal :: HASS (Event Value) (Map T.Text LightSnapshot)
|
bedroomLightSnapshots :: HASS (Event Value) (Map T.Text LightSnapshot)
|
||||||
bedroomLightsSignal = M.fromList <$> traverse (\e -> (e,) <$> observedLight e) [e | EntityId e <- bedroomLights]
|
bedroomLightSnapshots = M.fromList <$> traverse (\e -> (e,) <$> observedLight e) [e | EntityId e <- bedroomLightTargets]
|
||||||
|
|
||||||
bedroomPresenceController :: HASS (Event Value) ()
|
bedroomPresenceController :: HASS (Event Value) ()
|
||||||
bedroomPresenceController = proc x -> do
|
bedroomPresenceController = proc x -> do
|
||||||
p <- presenceLightEvents >>> traceEvent -< x
|
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
|
case p of
|
||||||
Event LightingOff -> do
|
Event LightingOff -> do
|
||||||
callService (light bedroomLights Off) -< ()
|
callService (light bedroomLightTargets Off) -< ()
|
||||||
Event LightingOn -> do
|
Event LightingOn -> do
|
||||||
-- callService (activateSceneWith "scene.makuuhuone_lights_snapshot" transition) -< ()
|
-- callService (activateSceneWith "scene.makuuhuone_lights_snapshot" transition) -< ()
|
||||||
callServicesDyn (concatMap (uncurry toLight)) -< M.toList snap
|
callServicesDyn (concatMap (uncurry toLight)) -< M.toList snap
|
||||||
|
|||||||
@@ -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
|
-- With that in mind, I'll be explicitly controlling the two lights, without any scene shenanigans
|
||||||
|
|
||||||
|
|
||||||
lights :: [Target]
|
livingroomLightTargets :: [Target]
|
||||||
lights = [EntityId "light.livingroom_ceiling", EntityId "light.livingroom_sofa"]
|
livingroomLightTargets = [EntityId "light.livingroom_ceiling", EntityId "light.livingroom_sofa"]
|
||||||
|
|
||||||
livingroomPresenceController :: HASS (AFRP.Event Value) ()
|
livingroomPresenceController :: HASS (AFRP.Event Value) ()
|
||||||
livingroomPresenceController = proc x -> do
|
livingroomPresenceController = proc x -> do
|
||||||
ev <- lightingModeEvents . livingroomPresence -< x
|
ev <- lightingModeEvents . livingroomPresence -< x
|
||||||
traceEvent -< ev
|
traceEvent -< ev
|
||||||
case ev of
|
case ev of
|
||||||
AFRP.Event LightingOn -> callServiceDyn (light lights) -< On def
|
AFRP.Event LightingOn -> callServiceDyn (light livingroomLightTargets) -< On def
|
||||||
AFRP.Event LightingOff -> callServiceDyn (light lights) -< Off
|
AFRP.Event LightingOff -> callServiceDyn (light livingroomLightTargets) -< Off
|
||||||
_ -> returnA -< ()
|
_ -> returnA -< ()
|
||||||
returnA -< ()
|
returnA -< ()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user