1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-18 06:20:17 +01:00
Files
core/tests/components/counter/common.py
T
2026-04-16 15:38:59 +02:00

39 lines
1.0 KiB
Python

"""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 (
DOMAIN,
SERVICE_DECREMENT,
SERVICE_INCREMENT,
SERVICE_RESET,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant, callback
@callback
def async_increment(hass: HomeAssistant, entity_id: str) -> None:
"""Increment a counter."""
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_INCREMENT, {ATTR_ENTITY_ID: entity_id})
)
@callback
def async_decrement(hass: HomeAssistant, entity_id: str) -> None:
"""Decrement a counter."""
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_DECREMENT, {ATTR_ENTITY_ID: entity_id})
)
@callback
def async_reset(hass: HomeAssistant, entity_id: str) -> None:
"""Reset a counter."""
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_RESET, {ATTR_ENTITY_ID: entity_id})
)