diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 74768ee01fa..0513d63b893 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -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 diff --git a/homeassistant/components/tado/services.py b/homeassistant/components/tado/services.py index d931ea303e9..a855f323978 100644 --- a/homeassistant/components/tado/services.py +++ b/homeassistant/components/tado/services.py @@ -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 )