mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Use service helper to extract tado config entry (#162812)
This commit is contained in:
@@ -5,8 +5,8 @@ import logging
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import selector
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import selector, service
|
||||
|
||||
from .const import (
|
||||
ATTR_MESSAGE,
|
||||
@@ -15,6 +15,7 @@ from .const import (
|
||||
DOMAIN,
|
||||
SERVICE_ADD_METER_READING,
|
||||
)
|
||||
from .coordinator import TadoConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
SCHEMA_ADD_METER_READING = vol.Schema(
|
||||
@@ -31,13 +32,12 @@ 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")
|
||||
entry: TadoConfigEntry = service.async_get_config_entry(
|
||||
call.hass, DOMAIN, call.data[CONF_CONFIG_ENTRY]
|
||||
)
|
||||
|
||||
coordinator = entry.runtime_data.coordinator
|
||||
response: dict = await coordinator.set_meter_reading(call.data[CONF_READING])
|
||||
|
||||
Reference in New Issue
Block a user