mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Simplify tado service actions (#146614)
This commit is contained in:
parent
e19f178864
commit
74a92e2cd8
@ -35,7 +35,7 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .coordinator import TadoDataUpdateCoordinator, TadoMobileDeviceUpdateCoordinator
|
from .coordinator import TadoDataUpdateCoordinator, TadoMobileDeviceUpdateCoordinator
|
||||||
from .models import TadoData
|
from .models import TadoData
|
||||||
from .services import setup_services
|
from .services import async_setup_services
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -58,7 +58,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up Tado."""
|
"""Set up Tado."""
|
||||||
|
|
||||||
setup_services(hass)
|
async_setup_services(hass)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
@callback
|
||||||
def setup_services(hass: HomeAssistant) -> None:
|
def async_setup_services(hass: HomeAssistant) -> None:
|
||||||
"""Set up the services for the Tado integration."""
|
"""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(
|
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
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user