|
29 | 29 | ) |
30 | 30 |
|
31 | 31 |
|
32 | | -@callback |
33 | | -def setup_services(hass: HomeAssistant) -> None: |
34 | | - """Set up the services for the Tado integration.""" |
| 32 | +async def _add_meter_reading(call: ServiceCall) -> None: |
| 33 | + """Send meter reading to Tado.""" |
| 34 | + entry_id: str = call.data[CONF_CONFIG_ENTRY] |
| 35 | + reading: int = call.data[CONF_READING] |
| 36 | + _LOGGER.debug("Add meter reading %s", reading) |
| 37 | + |
| 38 | + entry = call.hass.config_entries.async_get_entry(entry_id) |
| 39 | + if entry is None: |
| 40 | + raise ServiceValidationError("Config entry not found") |
35 | 41 |
|
36 | | - async def add_meter_reading(call: ServiceCall) -> None: |
37 | | - """Send meter reading to Tado.""" |
38 | | - entry_id: str = call.data[CONF_CONFIG_ENTRY] |
39 | | - reading: int = call.data[CONF_READING] |
40 | | - _LOGGER.debug("Add meter reading %s", reading) |
| 42 | + coordinator = entry.runtime_data.coordinator |
| 43 | + response: dict = await coordinator.set_meter_reading(call.data[CONF_READING]) |
41 | 44 |
|
42 | | - entry = hass.config_entries.async_get_entry(entry_id) |
43 | | - if entry is None: |
44 | | - raise ServiceValidationError("Config entry not found") |
| 45 | + if ATTR_MESSAGE in response: |
| 46 | + raise HomeAssistantError(response[ATTR_MESSAGE]) |
45 | 47 |
|
46 | | - coordinator = entry.runtime_data.coordinator |
47 | | - response: dict = await coordinator.set_meter_reading(call.data[CONF_READING]) |
48 | 48 |
|
49 | | - if ATTR_MESSAGE in response: |
50 | | - raise HomeAssistantError(response[ATTR_MESSAGE]) |
| 49 | +@callback |
| 50 | +def async_setup_services(hass: HomeAssistant) -> None: |
| 51 | + """Set up the services for the Tado integration.""" |
51 | 52 |
|
52 | 53 | hass.services.async_register( |
53 | | - DOMAIN, SERVICE_ADD_METER_READING, add_meter_reading, SCHEMA_ADD_METER_READING |
| 54 | + DOMAIN, SERVICE_ADD_METER_READING, _add_meter_reading, SCHEMA_ADD_METER_READING |
54 | 55 | ) |
0 commit comments