Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The repairs.remove service creates domain: spook event_type: update instead of domain: spook event_type: remove. #445

Open
Petro31 opened this issue Nov 11, 2023 · 2 comments

Comments

@Petro31
Copy link

Petro31 commented Nov 11, 2023

What version of Spook are you using?

1.3.2

What version of Home Assistant are you using?

2023.11.x

The problem

The repairs.remove service no longer removes repairs after successful completion.

I have this automation, runs fine. You can update "target" to choose any test error.

- alias: Repair - Ignore Spook Repair
  id: repair_ignore_spook_repair
  trigger:
  - platform: state
    entity_id: event.repair
  variables:
    continue: >
      {{ trigger | default(none) is not none and trigger.to_state is defined and trigger.from_state is defined }}
    attrs: >
      {{ trigger.to_state.attributes | default({}) if continue else {} }}
    issue_id: >
      {{ attrs.get('issue_id') }}
    target: >
      {{ issue_id if 'timed_event_snapshot_status' in issue_id else None }}
  condition:
  - condition: template
    value_template: "{{ target is not none }}"
  action:
  - service: repairs.remove
    data:
      issue_id: "{{ target }}"

Last trace shows it running successfully

{
  "trace": {
    "last_step": "action/0",
    "run_id": "6c997d7fa46b4192c9382ae93a428aff",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-11-11T10:19:02.968075+00:00",
      "finish": "2023-11-11T10:19:02.973220+00:00"
    },
    "domain": "automation",
    "item_id": "repair_ignore_spook_repair",
    "trigger": "state of event.repair",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2023-11-11T10:19:02.970479+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.repair_ignore_spook_repair",
              "state": "on",
              "attributes": {
                "id": "repair_ignore_spook_repair",
                "last_triggered": "2023-11-11T10:08:48.716243+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Repair - Ignore Spook Repair"
              },
              "last_changed": "2023-11-11T10:08:25.041874+00:00",
              "last_updated": "2023-11-11T10:08:48.717045+00:00",
              "context": {
                "id": "01HEYXP0JBKH6TCF2PXYMQ305N",
                "parent_id": "01HEYXP0JA4KPKKNSNQ38PDVV2",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "event.repair",
              "from_state": {
                "entity_id": "event.repair",
                "state": "2023-11-11T10:08:48.714+00:00",
                "attributes": {
                  "event_types": [
                    "create",
                    "remove",
                    "update"
                  ],
                  "event_type": "create",
                  "domain": "spook",
                  "issue_id": "automation_unknown_entity_references_automation.timed_event_snapshot_status",
                  "friendly_name": "Repairs"
                },
                "last_changed": "2023-11-11T10:08:48.714362+00:00",
                "last_updated": "2023-11-11T10:08:48.714362+00:00",
                "context": {
                  "id": "01HEYXP0JA4KPKKNSNQ38PDVV2",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "event.repair",
                "state": "2023-11-11T10:19:02.966+00:00",
                "attributes": {
                  "event_types": [
                    "create",
                    "remove",
                    "update"
                  ],
                  "event_type": "update",
                  "domain": "spook",
                  "issue_id": "automation_unknown_entity_references_automation.timed_event_snapshot_status",
                  "friendly_name": "Repairs"
                },
                "last_changed": "2023-11-11T10:19:02.966549+00:00",
                "last_updated": "2023-11-11T10:19:02.966549+00:00",
                "context": {
                  "id": "01HEYY8RDPJVXCAATB7N1X3S7D",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of event.repair"
            },
            "continue": true,
            "attrs": {
              "event_types": [
                "create",
                "remove",
                "update"
              ],
              "event_type": "update",
              "domain": "spook",
              "issue_id": "automation_unknown_entity_references_automation.timed_event_snapshot_status",
              "friendly_name": "Repairs"
            },
            "issue_id": "automation_unknown_entity_references_automation.timed_event_snapshot_status",
            "target": "automation_unknown_entity_references_automation.timed_event_snapshot_status"
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2023-11-11T10:19:02.970533+00:00",
          "result": {
            "result": true,
            "entities": []
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-11-11T10:19:02.971330+00:00",
          "changed_variables": {
            "context": {
              "id": "01HEYY8RDRBTPGWMGGV36A7A20",
              "parent_id": "01HEYY8RDPJVXCAATB7N1X3S7D",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "repairs",
              "service": "remove",
              "service_data": {
                "issue_id": "automation_unknown_entity_references_automation.timed_event_snapshot_status"
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "alias": "Repair - Ignore Spook Repair",
      "id": "repair_ignore_spook_repair",
      "trigger": [
        {
          "platform": "state",
          "entity_id": "event.repair"
        }
      ],
      "variables": {
        "continue": "{{ trigger | default(none) is not none and trigger.to_state is defined and trigger.from_state is defined }}\n",
        "attrs": "{{ trigger.to_state.attributes | default({}) if continue else {} }}\n",
        "issue_id": "{{ attrs.get('issue_id') }}\n",
        "target": "{{ issue_id if 'timed_event_snapshot_status' in issue_id else None }}\n"
      },
      "condition": [
        {
          "condition": "template",
          "value_template": "{{ target is not none }}"
        }
      ],
      "action": [
        {
          "service": "repairs.remove",
          "data": {
            "issue_id": "{{ target }}"
          }
        }
      ]
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HEYY8RDRBTPGWMGGV36A7A20",
      "parent_id": "01HEYY8RDPJVXCAATB7N1X3S7D",
      "user_id": null
    }
  },
  "logbookEntries": []
}

Interestingly, the event_type in the trace shows up as update instead of remove even though the automation is calling the repairs.remove service. I believe this is the root cause of the problem.

Anything in the logs? Paste it here!

No response

@frenck
Copy link
Owner

frenck commented Nov 11, 2023

The event entity reflects what HA is firing, so this is like to be an issue (or intentional design?) upstream. Will take a look

@Petro31
Copy link
Author

Petro31 commented Nov 11, 2023

The event entity reflects what HA is firing, so this is like to be an issue (or intentional design?) upstream. Will take a look

Yeah, I've been looking at your code and I have no idea how it would create that event. Your code looks fine and properly loads the correct service from /ectoplasms/repairs/services/remove.py. As a sidebar, this is new as of 2023.11.0 or 2023.11.1. I can't remember if the automation failed on 11.0. It did fail on 11.1 and 11.2. I'm somewhat remembering that it worked on 11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants