diff --git a/src/HomeAssistant/Controller.hs b/src/HomeAssistant/Controller.hs index d76781a..16634e0 100644 --- a/src/HomeAssistant/Controller.hs +++ b/src/HomeAssistant/Controller.hs @@ -27,7 +27,7 @@ module HomeAssistant.Controller , debug , traceEvent , traceValue - , switch + , switchService , Target(..) , lightBrightnessEvent , lightTemperatureEvent @@ -199,9 +199,8 @@ light targets Off = Service , serviceTarget=targets } --- Name conflict with AFRP -switch :: [Target] -> Bool -> Service -switch targets b = Service +switchService :: [Target] -> Bool -> Service +switchService targets b = Service { serviceDomain="switch" , serviceName= bool "turn_off" "turn_on" b , serviceData=Nothing diff --git a/src/HomeAssistant/Controller/Bedroom.hs b/src/HomeAssistant/Controller/Bedroom.hs index a0ebda2..88e4017 100644 --- a/src/HomeAssistant/Controller/Bedroom.hs +++ b/src/HomeAssistant/Controller/Bedroom.hs @@ -132,8 +132,8 @@ bedroomDrawerController :: HASS (Event Value) () bedroomDrawerController = proc x -> do st <- drawer >>> traceEvent -< x case st of - Event Open -> callService (switch [entity] True) -< () - Event Closed -> callService (switch [entity] False) -< () + Event Open -> callService (switchService [entity] True) -< () + Event Closed -> callService (switchService [entity] False) -< () _ -> returnA -< () where entity = EntityId "switch.bedroom_drawer_light_masse" diff --git a/src/HomeAssistant/Controller/Kitchen.hs b/src/HomeAssistant/Controller/Kitchen.hs index 27ec651..ac738f4 100644 --- a/src/HomeAssistant/Controller/Kitchen.hs +++ b/src/HomeAssistant/Controller/Kitchen.hs @@ -74,7 +74,7 @@ dinnerTableController = proc x -> do sleep -< True _ -> returnA -< () where - sleep = callServiceDyn (switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"]) + sleep = callServiceDyn (switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"]) kitchenMotionController :: HASS (Event Value) () kitchenMotionController = kitchenCeilingController <> dinnerTableController diff --git a/test/BedroomSpec.hs b/test/BedroomSpec.hs index e9a9126..8a6e741 100644 --- a/test/BedroomSpec.hs +++ b/test/BedroomSpec.hs @@ -62,18 +62,18 @@ drawerSpec = describe "bedroomDrawerController" $ do it "turns the drawer light on when the drawer opens" $ services (runHASS bedroomDrawerController [drawerState "on"]) - `shouldBe` [[switch [entity] True]] + `shouldBe` [[switchService [entity] True]] it "turns the drawer light off when the drawer closes" $ services (runHASS bedroomDrawerController [drawerState "off"]) - `shouldBe` [[switch [entity] False]] + `shouldBe` [[switchService [entity] False]] it "toggles the light as the drawer opens and closes" $ services (runHASS bedroomDrawerController [ drawerState "on", drawerState "off", drawerState "on" ]) - `shouldBe` [ [switch [entity] True] - , [switch [entity] False] - , [switch [entity] True] + `shouldBe` [ [switchService [entity] True] + , [switchService [entity] False] + , [switchService [entity] True] ] it "ignores state events for other entities" $ diff --git a/test/KitchenSpec.hs b/test/KitchenSpec.hs index c6e4333..ab615c1 100644 --- a/test/KitchenSpec.hs +++ b/test/KitchenSpec.hs @@ -35,12 +35,12 @@ dinnerTableSpec = describe "dinnerTableController" $ do it "turns lights on when presence is occupied and light level is low" $ do services (runHASS dinnerTableController [testDinnerLightLevel 10, testDinnerPresence "on"]) - `shouldBe` [[switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True], [switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] False, light [EntityId "light.kitchen_dining_large"] (On def)]] + `shouldBe` [[switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True], [switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] False, light [EntityId "light.kitchen_dining_large"] (On def)]] it "turns lights off when presence is unoccupied" $ do services (runHASS dinnerTableController [testDinnerLightLevel 10, testDinnerPresence "off"]) - `shouldBe` [[switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True], []] + `shouldBe` [[switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True], []] it "does nothing on Tick" $ do services (runHASS dinnerTableController [Tick]) - `shouldBe` [[switch [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True]] + `shouldBe` [[switchService [EntityId "switch.adaptive_lighting_ruokapoydan_valot_sleep_mode"] True]]