Skip to content

Add device automation condition#26313

Merged
emontnemery merged 12 commits into
home-assistant:devfrom
emontnemery:device_automation_condition
Sep 5, 2019
Merged

Add device automation condition#26313
emontnemery merged 12 commits into
home-assistant:devfrom
emontnemery:device_automation_condition

Conversation

@emontnemery
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery commented Aug 31, 2019

Description:

Add websock command to query device for conditions.

Conditions can be provided by the integration that provided the device or the entity integrations that the device has entities with.

As an example of the latter, this PR also adds turn_on and turn_off conditions to light entities.

This PR is intended as a step towards home-assistant/architecture#178

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

Comment thread homeassistant/helpers/condition.py Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is now broken because async_from_config is a coroutine function. Is this used anywhere?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that we can remove all of those.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, removed.

Comment thread homeassistant/helpers/condition.py Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is now broken because async_and_from_config is a coroutine function. Is this used anywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Comment thread homeassistant/helpers/condition.py Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is now broken because async_or_from_config is a coroutine function. Is this used anywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Comment thread homeassistant/helpers/condition.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If this function is only used in this file, let's prefix it with _.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why would we add this to a dictionary? We should just send the list.

Suggested change
connection.send_result(msg["id"], {"conditions": conditions})
connection.send_result(msg["id"], conditions)

We should do the same for triggers (which I thought we already did)

Copy link
Copy Markdown
Contributor Author

@emontnemery emontnemery Sep 4, 2019

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this feels a bit weird, shouldn't this be is_on and is_off ?

I also wonder if we should move some generic constants to device_automation/const.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You say fixed but then we should update these constants to be CONF_IS_ON CONF_IS_OFF ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
vol.Required(CONF_TYPE): vol.In([CONF_TURN_OFF, CONF_TURN_ON]),
vol.Required(CONF_TYPE): vol.In([CONF_IS_OFF, CONF_IS_ON]),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops, now properly fixed!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This only tests that the keys are the same, not the values.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"turn_on": "{name} turned on",
"turn_on": "{name} is on",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"turn_off": "{name} turned off"
"turn_off": "{name} is off"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread homeassistant/helpers/condition.py Outdated
Comment thread homeassistant/helpers/condition.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should not be part of the condition helper, instead I think it should be part of components/device_automation/__init__.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved.

@emontnemery emontnemery force-pushed the device_automation_condition branch from 77b327d to 6cb0a8b Compare September 4, 2019 17:11
Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

This looks great, only a few minor comments left. Ok to merge after this?

@emontnemery emontnemery changed the title WIP: Device automation condition Device automation condition Sep 5, 2019
@emontnemery emontnemery changed the title Device automation condition Add device automation condition Sep 5, 2019
@emontnemery
Copy link
Copy Markdown
Contributor Author

Fixed the remaining comments.

@emontnemery emontnemery merged commit f7dc537 into home-assistant:dev Sep 5, 2019
@emontnemery emontnemery deleted the device_automation_condition branch September 6, 2019 10:02
@lock lock Bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants