Skip to content

Commit 74a92e2

Browse files
authored
Simplify tado service actions (home-assistant#146614)
1 parent e19f178 commit 74a92e2

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

homeassistant/components/tado/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636
from .coordinator import TadoDataUpdateCoordinator, TadoMobileDeviceUpdateCoordinator
3737
from .models import TadoData
38-
from .services import setup_services
38+
from .services import async_setup_services
3939

4040
PLATFORMS = [
4141
Platform.BINARY_SENSOR,
@@ -58,7 +58,7 @@
5858
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
5959
"""Set up Tado."""
6060

61-
setup_services(hass)
61+
async_setup_services(hass)
6262
return True
6363

6464

homeassistant/components/tado/services.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,27 @@
2929
)
3030

3131

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")
3541

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])
4144

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])
4547

46-
coordinator = entry.runtime_data.coordinator
47-
response: dict = await coordinator.set_meter_reading(call.data[CONF_READING])
4848

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."""
5152

5253
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
5455
)

0 commit comments

Comments
 (0)