1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 17:49:37 +01:00

Avoid blocking IO in TRIGGERcmd (#151396)

This commit is contained in:
Russell VanderMey
2025-09-01 04:19:35 -04:00
committed by GitHub
parent edc48e0604
commit 8faeb1fe98
6 changed files with 13 additions and 6 deletions
@@ -8,6 +8,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import httpx_client
from .const import CONF_TOKEN
@@ -20,9 +21,12 @@ type TriggercmdConfigEntry = ConfigEntry[ha.Hub]
async def async_setup_entry(hass: HomeAssistant, entry: TriggercmdConfigEntry) -> bool:
"""Set up TRIGGERcmd from a config entry."""
hass_client = httpx_client.get_async_client(hass)
hub = ha.Hub(entry.data[CONF_TOKEN])
status_code = await client.async_connection_test(entry.data[CONF_TOKEN])
await hub.async_init(hass_client)
status_code = await client.async_connection_test(
entry.data[CONF_TOKEN], hass_client
)
if status_code != 200:
raise ConfigEntryNotReady
@@ -12,6 +12,7 @@ import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import httpx_client
from .const import CONF_TOKEN, DOMAIN
@@ -32,8 +33,9 @@ async def validate_input(hass: HomeAssistant, data: dict) -> str:
if not token_data["id"]:
raise InvalidToken
hass_client = httpx_client.get_async_client(hass)
try:
await client.async_connection_test(data[CONF_TOKEN])
await client.async_connection_test(data[CONF_TOKEN], hass_client)
except Exception as e:
raise TRIGGERcmdConnectionError from e
else:
@@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/triggercmd",
"integration_type": "hub",
"iot_class": "cloud_polling",
"requirements": ["triggercmd==0.0.27"]
"requirements": ["triggercmd==0.0.36"]
}
@@ -82,5 +82,6 @@ class TRIGGERcmdSwitch(SwitchEntity):
"params": params,
"sender": "Home Assistant",
},
self._switch.hub.httpx_client,
)
_LOGGER.debug("TRIGGERcmd trigger response: %s", r.json())
+1 -1
View File
@@ -2978,7 +2978,7 @@ tplink-omada-client==1.4.4
transmission-rpc==7.0.3
# homeassistant.components.triggercmd
triggercmd==0.0.27
triggercmd==0.0.36
# homeassistant.components.twinkly
ttls==1.8.3
+1 -1
View File
@@ -2452,7 +2452,7 @@ tplink-omada-client==1.4.4
transmission-rpc==7.0.3
# homeassistant.components.triggercmd
triggercmd==0.0.27
triggercmd==0.0.36
# homeassistant.components.twinkly
ttls==1.8.3