Skip to content

Add priority and cycles to LaMetric#14414

Merged
pvizeli merged 3 commits into
home-assistant:devfrom
PhilRW:lametric
May 13, 2018
Merged

Add priority and cycles to LaMetric#14414
pvizeli merged 3 commits into
home-assistant:devfrom
PhilRW:lametric

Conversation

@PhilRW
Copy link
Copy Markdown
Contributor

@PhilRW PhilRW commented May 12, 2018

Description:

Priority can be "info", "warning" (default), or "critical" and cycles is the number of times the message is displayed. If cycles is set to 0 we get a persistent notification that has to be dismissed manually.

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5358

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

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

Priority can be "info", "warning" (default), or "critical" and
cycles is the number of times the message is displayed. If cycles
is set to 0 we get a persistent notification that has to be dismissed
manually.
PhilRW added a commit to PhilRW/home-assistant.github.io that referenced this pull request May 12, 2018
This documents the [change in the code](home-assistant/core#14414)
PhilRW added a commit to PhilRW/home-assistant.github.io that referenced this pull request May 12, 2018
PhilRW added a commit to PhilRW/home-assistant.github.io that referenced this pull request May 12, 2018
Copy link
Copy Markdown
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.

Two small changes needed. Looks good otherwise.

priority = data['priority']
else:
_LOGGER.warning("Priority '%s' invalid, using default "
"'%s'" % (data['priority'], priority))
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.

Don't put additional quotes around the priority variables:
https://developers.home-assistant.io/docs/en/development_guidelines.html#log-messages

Pass the priority variables as parameters:

_LOGGER.warning("Priority %s blabla %s", data['priority'], priority)

vol.Optional(CONF_ICON, default="i555"): cv.string,
vol.Optional(CONF_LIFETIME, default=10): cv.positive_int,
vol.Optional(CONF_CYCLES, default=1): cv.positive_int,
vol.Optional(CONF_PRIORITY, default="warning"): cv.string,
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.

AVAILABLE_PRIORITIES = ["info", "warning", "critical"]
...
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
...
    vol.Optional(CONF_PRIORITY, default="warning"):
        vol.In(AVAILABLE_PRIORITIES),
})

else:
_LOGGER.warning("Priority '%s' invalid, using default "
"'%s'" % (data['priority'], priority))
_LOGGER.warning("Priority %s invalid, using default %s" %
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.

Don't use the percent/modulo sign. Just add the variables after comma.

_LOGGER.warning("Priority %s invalid, using default %s", data['priority'], priority)

https://docs.python.org/3/library/logging.html#logging.Logger.debug

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.

Whoops. I've moved on to .format() so I rarely use %s otherwise...

Copy link
Copy Markdown
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.

Great! Can be merged when build passes.

@pvizeli pvizeli merged commit 8ae3caa into home-assistant:dev May 13, 2018
PhilRW added a commit to PhilRW/home-assistant.github.io that referenced this pull request May 14, 2018
PhilRW added a commit to PhilRW/home-assistant.github.io that referenced this pull request May 14, 2018
MartinHjelmare pushed a commit to home-assistant/home-assistant.io that referenced this pull request May 14, 2018
Oro pushed a commit to Oro/home-assistant.github.io that referenced this pull request May 20, 2018
@balloob balloob mentioned this pull request May 28, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* Add priority and cycles to LaMetric

Priority can be "info", "warning" (default), or "critical" and
cycles is the number of times the message is displayed. If cycles
is set to 0 we get a persistent notification that has to be dismissed
manually.

* Fix for schema and style

* Fix for style
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants