Adjust device_automation type hints in philips_js (#72137)

This commit is contained in:
epenet 2022-05-23 14:57:09 +02:00 committed by GitHub
parent bcc3c93b4e
commit caa2412103
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,6 @@
"""Provides device automations for control of device."""
from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant.components.automation import (
@ -12,6 +10,7 @@ from homeassistant.components.automation import (
from homeassistant.components.device_automation import DEVICE_TRIGGER_BASE_SCHEMA
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.typing import ConfigType
@ -30,7 +29,7 @@ TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, Any]]:
) -> list[dict[str, str]]:
"""List device triggers for device."""
triggers = []
triggers.append(
@ -50,18 +49,18 @@ async def async_attach_trigger(
config: ConfigType,
action: AutomationActionType,
automation_info: AutomationTriggerInfo,
) -> CALLBACK_TYPE | None:
) -> CALLBACK_TYPE:
"""Attach a trigger."""
trigger_data = automation_info["trigger_data"]
registry: dr.DeviceRegistry = dr.async_get(hass)
if config[CONF_TYPE] == TRIGGER_TYPE_TURN_ON:
if (trigger_type := config[CONF_TYPE]) == TRIGGER_TYPE_TURN_ON:
variables = {
"trigger": {
**trigger_data,
"platform": "device",
"domain": DOMAIN,
"device_id": config[CONF_DEVICE_ID],
"description": f"philips_js '{config[CONF_TYPE]}' event",
"description": f"philips_js '{trigger_type}' event",
}
}
@ -73,4 +72,4 @@ async def async_attach_trigger(
if coordinator:
return coordinator.turn_on.async_attach(action, variables)
return None
raise HomeAssistantError(f"Unhandled trigger type {trigger_type}")