From caa24121032f901896ff9da355f1b9e060368b50 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 23 May 2022 14:57:09 +0200 Subject: [PATCH] Adjust device_automation type hints in philips_js (#72137) --- .../components/philips_js/device_trigger.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/philips_js/device_trigger.py b/homeassistant/components/philips_js/device_trigger.py index a48f9e58331..69a5932576f 100644 --- a/homeassistant/components/philips_js/device_trigger.py +++ b/homeassistant/components/philips_js/device_trigger.py @@ -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}")