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

Add initial blueprint support #42469

Merged
merged 20 commits into from
Nov 2, 2020
Merged

Add initial blueprint support #42469

merged 20 commits into from
Nov 2, 2020

Conversation

balloob
Copy link
Member

@balloob balloob commented Oct 27, 2020

Blueprint support is experimental and not recommended yet for production. Config will change between releases. Plan is to announce at the Home Assistant Conference.

Proposed change

Add support for blueprints in Home Assistant. Blueprints allows users that configure their automations via YAML to create reusable automations, reducing the amount of configuration necessary. Blueprints can easily be shared with others.

This is only the very basics plus a little bit more. I have a lot more plans for this but that will be for future PRs. I have created a document with the features I want to have added next. If you want to help, hit me up on Discord. Any blueprint PR that implements something not on that list will probably not be considered at this time.

Example blueprint in config/blueprints/automation/balloob/test_event_service.yaml:

blueprint:
  name: Call service from event
  domain: automation 
  input:
    trigger_event:
    service_to_call:
trigger:
  platform: event
  event_type: !placeholder trigger_event
action:
  service: !placeholder service_to_call

And then an example automation configuration to use it:

automation:
  use_blueprint:
    path: balloob/test_event_service.yaml
    input:
      trigger_event: my_event
      service_to_call: light.turn_on

Do not post non-dev related questions on this PR please. They will be marked as spam. If you feel like expressing your emotion, use the emoji reaction button.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with an integration (automation) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@MartinHjelmare MartinHjelmare self-assigned this Oct 30, 2020
tests/components/blueprint/test_importer.py Outdated Show resolved Hide resolved
tests/components/blueprint/test_schemas.py Outdated Show resolved Hide resolved
tests/components/blueprint/test_schemas.py Outdated Show resolved Hide resolved
homeassistant/components/blueprint/importer.py Outdated Show resolved Hide resolved
homeassistant/components/blueprint/importer.py Outdated Show resolved Hide resolved
homeassistant/components/blueprint/models.py Outdated Show resolved Hide resolved
homeassistant/components/blueprint/schemas.py Outdated Show resolved Hide resolved
homeassistant/components/blueprint/websocket_api.py Outdated Show resolved Hide resolved
for domain, domain_results in zip(
domain_blueprints,
await asyncio.gather(
*[db.async_get_blueprints() for db in domain_blueprints.values()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will create one executor job per domain. Maybe that's ok?

Copy link
Member

@pvizeli pvizeli Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learn on Supervisor: jobs with doing IO on disk - Parallel is bad and make it slower (just hit the disk) / doing IO on network/pipe/memory/process - Parallel gives a real boost (just not hit our system)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that's ugly. We should do it in 1 call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not going to fix it for MVP, as we only support automation right now.

balloob and others added 2 commits November 1, 2020 21:42
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>


@dataclass
class ImportedBlueprint:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use attr and his nice slot=True feature?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataclass is built-in and pretty much the same :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add frozen=True here. Which is a similar feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For memory footprint, it would be better if we not need to extend the object at runtime.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This object will remain in memory for <1 second. From when it's imported till when it's send over the websocket API.

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

balloob and others added 2 commits November 2, 2020 13:41
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants