Update tests

This commit is contained in:
2026-08-21 11:55:27 +03:00
parent efcee8b90a
commit 5954c68682
5 changed files with 31 additions and 16 deletions
+13 -3
View File
@@ -97,6 +97,16 @@ encodeService callId Service{..} = object $
, "type" .= ("call_service" :: T.Text)
, "domain" .= serviceDomain
, "service" .= serviceName
, "target" .= object [ "entity_id" .= [e | EntityId e <- serviceTarget]
, "area_id" .= [a | AreaId a <- serviceTarget]]
] <> maybe [] (\d -> ["data" .= d]) serviceData
, "target" .= targetObject serviceTarget
] <> maybe [] (\d -> ["service_data" .= d]) serviceData
-- | A single target encodes as a scalar; multiple encode as a list. Empty
-- lists are omitted so Home Assistant receives only populated keys.
targetObject :: [Target] -> Value
targetObject targets = object $ entityPart <> areaPart
where
entityPart = emit "entity_id" [e | EntityId e <- targets]
areaPart = emit "area_id" [a | AreaId a <- targets]
emit _ [] = []
emit k [x] = [k .= x]
emit k many = [k .= many]