mirror of
https://github.com/home-assistant/core.git
synced 2026-08-28 02:24:46 -05:00
Use async_get_device_and_config_entry service helper in octoprint (#180143)
This commit is contained in:
@@ -5,11 +5,9 @@ from typing import cast
|
||||
from pyoctoprintapi import OctoprintClient
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_DEVICE_ID, CONF_PORT, CONF_PROFILE_NAME
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
|
||||
from .const import CONF_BAUDRATE, DOMAIN, SERVICE_CONNECT
|
||||
from .coordinator import OctoprintConfigEntry
|
||||
@@ -28,21 +26,10 @@ def async_get_client_for_service_call(
|
||||
hass: HomeAssistant, call: ServiceCall
|
||||
) -> OctoprintClient:
|
||||
"""Get the client related to a service call (by device ID)."""
|
||||
device_id = call.data[CONF_DEVICE_ID]
|
||||
|
||||
_, config_entry = dr.async_get_device_and_config_entry_for_domain(
|
||||
hass, device_id, domain=DOMAIN
|
||||
)
|
||||
if config_entry is not None and config_entry.state is ConfigEntryState.LOADED:
|
||||
return cast(OctoprintConfigEntry, config_entry).runtime_data.octoprint
|
||||
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="missing_client",
|
||||
translation_placeholders={
|
||||
"device_id": device_id,
|
||||
},
|
||||
_, config_entry = service.async_get_device_and_config_entry(
|
||||
hass, DOMAIN, call.data[CONF_DEVICE_ID]
|
||||
)
|
||||
return cast(OctoprintConfigEntry, config_entry).runtime_data.octoprint
|
||||
|
||||
|
||||
@callback
|
||||
|
||||
@@ -81,9 +81,6 @@
|
||||
"exceptions": {
|
||||
"error_setting_temperature": {
|
||||
"message": "Error setting target {tool} temperature"
|
||||
},
|
||||
"missing_client": {
|
||||
"message": "No client for device ID: {device_id}"
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
|
||||
Reference in New Issue
Block a user