Add target exclusions to service calls

Services can now carry excluded targets, encoded as target.exclude in
the WebSocket payload. The children's bedroom lights-off calls skip
lights labelled 'decoration'.
This commit is contained in:
MasseR committed 2026-11-14 19:36:46 +02:00
1 parent 383143024a
commit 9c89504399
15 files changed
+115 -86

No files matched your search

+16 -3
View File
@@ -27,7 +27,7 @@ spec :: Spec
spec = do
describe "encodeService" $ do
it "encodes a call_service message" $
encodeService 7 (Service "light" "turn_on" Nothing [EntityId "light.bedroom_masse"])
encodeService 7 (Service "light" "turn_on" Nothing [EntityId "light.bedroom_masse"] [])
`shouldBe` object
[ "id" .= (7 :: Int)
, "type" .= ("call_service" :: Text)
@@ -37,7 +37,7 @@ spec = do
]
it "includes service_data when present" $
encodeService 8 (Service "light" "turn_on" (Just (object ["brightness" .= (200 :: Int)])) [EntityId "light.bedroom_masse"])
encodeService 8 (Service "light" "turn_on" (Just (object ["brightness" .= (200 :: Int)])) [EntityId "light.bedroom_masse"] [])
`shouldBe` object
[ "id" .= (8 :: Int)
, "type" .= ("call_service" :: Text)
@@ -47,6 +47,19 @@ spec = do
, "service_data" .= object ["brightness" .= (200 :: Int)]
]
it "encodes target exclusions" $
encodeService 9 (Service "light" "turn_off" Nothing [AreaId "lasten_makuuhuone"] [LabelId "decoration"])
`shouldBe` object
[ "id" .= (9 :: Int)
, "type" .= ("call_service" :: Text)
, "domain" .= ("light" :: Text)
, "service" .= ("turn_off" :: Text)
, "target" .= object
[ "area_id" .= ("lasten_makuuhuone" :: Text)
, "exclude" .= object ["label_id" .= ("decoration" :: Text)]
]
]
describe "isTriggerEvent" $ do
it "is true for event frames" $
isTriggerEvent (object ["type" .= ("event" :: Text)]) `shouldBe` True
@@ -80,5 +93,5 @@ req n = Request (UTCTime (toEnum 0) (fromIntegral (0 :: Int))) utc
uuid = "00000000-0000-0000-0000-" <> pad n
lightOn :: [Target] -> Service
lightOn = Service "light" "turn_on" Nothing
lightOn targets = Service "light" "turn_on" Nothing targets []