Simplify tado service actions (#146614)

This commit is contained in:
epenet 2025-06-12 14:01:45 +02:00 committed by GitHub
parent e19f178864
commit 74a92e2cd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 20 deletions

View File

@ -35,7 +35,7 @@ from .const import (
)
from .coordinator import TadoDataUpdateCoordinator, TadoMobileDeviceUpdateCoordinator
from .models import TadoData
from .services import setup_services
from .services import async_setup_services
PLATFORMS = [
Platform.BINARY_SENSOR,
@ -58,7 +58,7 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up Tado."""
setup_services(hass)
async_setup_services(hass)
return True

View File

@ -29,26 +29,27 @@ SCHEMA_ADD_METER_READING = vol.Schema(
)
async def _add_meter_reading(call: ServiceCall) -> None:
"""Send meter reading to Tado."""
entry_id: str = call.data[CONF_CONFIG_ENTRY]
reading: int = call.data[CONF_READING]
_LOGGER.debug("Add meter reading %s", reading)
entry = call.hass.config_entries.async_get_entry(entry_id)
if entry is None:
raise ServiceValidationError("Config entry not found")
coordinator = entry.runtime_data.coordinator
response: dict = await coordinator.set_meter_reading(call.data[CONF_READING])
if ATTR_MESSAGE in response:
raise HomeAssistantError(response[ATTR_MESSAGE])
@callback
def setup_services(hass: HomeAssistant) -> None:
def async_setup_services(hass: HomeAssistant) -> None:
"""Set up the services for the Tado integration."""
async def add_meter_reading(call: ServiceCall) -> None:
"""Send meter reading to Tado."""
entry_id: str = call.data[CONF_CONFIG_ENTRY]
reading: int = call.data[CONF_READING]
_LOGGER.debug("Add meter reading %s", reading)
entry = hass.config_entries.async_get_entry(entry_id)
if entry is None:
raise ServiceValidationError("Config entry not found")
coordinator = entry.runtime_data.coordinator
response: dict = await coordinator.set_meter_reading(call.data[CONF_READING])
if ATTR_MESSAGE in response:
raise HomeAssistantError(response[ATTR_MESSAGE])
hass.services.async_register(
DOMAIN, SERVICE_ADD_METER_READING, add_meter_reading, SCHEMA_ADD_METER_READING
DOMAIN, SERVICE_ADD_METER_READING, _add_meter_reading, SCHEMA_ADD_METER_READING
)