2018-09-26 07:49:55 +00:00
|
|
|
"""Collection of helper methods.
|
|
|
|
|
|
|
|
All containing methods are legacy helpers that should not be used by new
|
|
|
|
components. Instead call the service directly.
|
|
|
|
"""
|
|
|
|
from homeassistant.components.counter import (
|
2019-07-31 19:25:30 +00:00
|
|
|
DOMAIN,
|
|
|
|
SERVICE_DECREMENT,
|
|
|
|
SERVICE_INCREMENT,
|
|
|
|
SERVICE_RESET,
|
|
|
|
)
|
2019-12-09 10:47:35 +00:00
|
|
|
from homeassistant.const import ATTR_ENTITY_ID
|
2018-09-26 07:49:55 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.loader import bind_hass
|
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
@bind_hass
|
|
|
|
def async_increment(hass, entity_id):
|
|
|
|
"""Increment a counter."""
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.async_add_job(
|
|
|
|
hass.services.async_call(DOMAIN, SERVICE_INCREMENT, {ATTR_ENTITY_ID: entity_id})
|
|
|
|
)
|
2018-09-26 07:49:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
@bind_hass
|
|
|
|
def async_decrement(hass, entity_id):
|
|
|
|
"""Decrement a counter."""
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.async_add_job(
|
|
|
|
hass.services.async_call(DOMAIN, SERVICE_DECREMENT, {ATTR_ENTITY_ID: entity_id})
|
|
|
|
)
|
2018-09-26 07:49:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@callback
|
|
|
|
@bind_hass
|
|
|
|
def async_reset(hass, entity_id):
|
|
|
|
"""Reset a counter."""
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.async_add_job(
|
|
|
|
hass.services.async_call(DOMAIN, SERVICE_RESET, {ATTR_ENTITY_ID: entity_id})
|
|
|
|
)
|