Support for areas
This commit is contained in:
@@ -27,6 +27,7 @@ module HomeAssistant.Controller
|
||||
, debug
|
||||
, traceEvent
|
||||
, switch
|
||||
, Target(..)
|
||||
) where
|
||||
|
||||
import AFRP (Mealy (..), eff, Event(..), hold, events, changes, filterA, (>>|), toEvent, Request)
|
||||
@@ -39,11 +40,14 @@ import Data.Aeson.Lens (key, _String)
|
||||
import qualified Data.Text.Lens as TL
|
||||
import Data.Bool (bool)
|
||||
|
||||
data Target = EntityId !T.Text | AreaId !T.Text
|
||||
deriving (Show,Eq)
|
||||
|
||||
data Service = Service
|
||||
{ serviceDomain :: T.Text
|
||||
, serviceName :: T.Text
|
||||
, serviceData :: Maybe Value
|
||||
, serviceTarget :: [T.Text]
|
||||
, serviceTarget :: [Target]
|
||||
}
|
||||
deriving (Show, Eq)
|
||||
|
||||
@@ -98,29 +102,29 @@ door = entityBool "binary_sensor.makuuhuone_ovi_contact"
|
||||
>>> changes
|
||||
|
||||
-- Turn off lights when door is closed
|
||||
light :: [T.Text] -> Bool -> Service
|
||||
light entityIds b = Service
|
||||
light :: [Target] -> Bool -> Service
|
||||
light targets b = Service
|
||||
{ serviceDomain="light"
|
||||
, serviceName= bool "turn_off" "turn_on" b
|
||||
, serviceData=Nothing
|
||||
, serviceTarget=entityIds
|
||||
, serviceTarget=targets
|
||||
}
|
||||
|
||||
-- Name conflict with AFRP
|
||||
switch :: [T.Text] -> Bool -> Service
|
||||
switch entityIds b = Service
|
||||
switch :: [Target] -> Bool -> Service
|
||||
switch targets b = Service
|
||||
{ serviceDomain="switch"
|
||||
, serviceName= bool "turn_off" "turn_on" b
|
||||
, serviceData=Nothing
|
||||
, serviceTarget=entityIds
|
||||
, serviceTarget=targets
|
||||
}
|
||||
|
||||
lightController :: HASS (Event Value) (Event DoorState)
|
||||
lightController = proc ev -> do
|
||||
doorState <- door -< ev
|
||||
case doorState of
|
||||
Event Open -> callService (light ["light.bedroom_masse"] False) -< ()
|
||||
Event Closed -> callService (light ["light.bedroom_masse"] True) -< ()
|
||||
Event Open -> callService (light [EntityId "light.bedroom_masse"] False) -< ()
|
||||
Event Closed -> callService (light [EntityId "light.bedroom_masse"] True) -< ()
|
||||
_ -> returnA -< ()
|
||||
returnA -< doorState
|
||||
|
||||
|
||||
Reference in New Issue
Block a user