Skip to content

Commit

Permalink
feat(issues): Validate entity_id placement within the correct propert…
Browse files Browse the repository at this point in the history
…y for the action node
  • Loading branch information
zachowj committed Sep 6, 2024
1 parent 00e084e commit eef3717
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common/services/IssueService/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"service": {
"issue": {
"device_not_found": "Device __device_id__ not found",
"entity_id_target_data": "Entity ID '__entity_id__' should be in the data property, not the target property, for the selected action",
"entity_not_found": "Entity __entity_id__ not found",
"failed_to_hide": "Failed to hide issue __issue_id__",
"invalid_action": "Action __action__ not found",
Expand Down
26 changes: 26 additions & 0 deletions src/nodes/action/issue-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ export default function issueCheck(config: ActionNodeProperties): Issue[] {
message,
identity: config.action,
});
} else {
// TODO: Remove in version 1.0 - Should no longer be needed
// check if target.entity_id should be in data.entity_id
if (services[domain]?.[service]?.fields?.entity_id !== undefined) {
let data: Record<string, unknown> = {};
try {
data = JSON.parse(config.data || '{}');
} catch (e) {
// fail silently
}
if (config.entityId?.length && !data.entity_id) {
const ids = config.entityId.join(', ');
issues.push({
type: IssueType.EntityId,
message: RED._(
'home-assistant.service.issue.entity_id_target_data',
{
entity_id: ids,
},
),
identity: ids,
});
}
}
}
}

Expand All @@ -89,6 +113,8 @@ export default function issueCheck(config: ActionNodeProperties): Issue[] {
config[target.idsProperty],
);
for (const id of invalidIds) {
// Skip the 'all' entity id if the target is entityId
// https://www.home-assistant.io/docs/scripts/perform-actions/#the-basics
if (id === 'all' && target.idsProperty === 'entityId') {
continue;
}
Expand Down

0 comments on commit eef3717

Please sign in to comment.