Remove deprecated device trigger from nanoleaf (#188656)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Martin Hjelmare
2026-10-26 13:19:00 +01:00
committed by GitHub
co-authored by Claude
parent 54a29725d9
commit f28afd9635
3 changed files with 0 additions and 226 deletions
@@ -1,86 +0,0 @@
"""Provides device triggers for Nanoleaf."""
import probatio
from homeassistant.components.device_automation import (
DEVICE_TRIGGER_BASE_SCHEMA,
DeviceNotFound,
)
from homeassistant.components.homeassistant.triggers import event as event_trigger
from homeassistant.components.homeassistant.triggers.event import EventTriggerArgument
from homeassistant.const import (
CONF_DEVICE_ID,
CONF_DOMAIN,
CONF_EVENT,
CONF_PLATFORM,
CONF_TYPE,
)
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.trigger import TriggerActionType, TriggerInfo
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN, NANOLEAF_EVENT, TOUCH_GESTURE_TRIGGER_MAP, TOUCH_MODELS
TRIGGER_TYPES = TOUCH_GESTURE_TRIGGER_MAP.values()
TRIGGER_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
{
probatio.Required(CONF_DOMAIN): DOMAIN,
probatio.Required(CONF_DEVICE_ID): str,
probatio.Required(CONF_TYPE): probatio.In(TRIGGER_TYPES),
}
)
async def async_get_triggers(
hass: HomeAssistant, device_id: str
) -> list[dict[str, str]]:
"""List device triggers for Nanoleaf devices."""
device_registry = dr.async_get(hass)
device_entry = device_registry.async_get(device_id, include_child_devices=False)
if device_entry is None:
raise DeviceNotFound(f"Device ID {device_id} is not valid")
if device_entry.model not in TOUCH_MODELS:
return []
return [
{
CONF_PLATFORM: "device",
CONF_DOMAIN: DOMAIN,
CONF_DEVICE_ID: device_id,
CONF_TYPE: trigger_type,
}
for trigger_type in TRIGGER_TYPES
]
async def async_attach_trigger(
hass: HomeAssistant,
config: ConfigType,
action: TriggerActionType,
trigger_info: TriggerInfo,
) -> CALLBACK_TYPE:
"""Attach a trigger."""
async_create_issue(
hass,
DOMAIN,
"deprecated_device_trigger_nanoleaf",
is_fixable=False,
breaks_in_ha_version="2025.1.0",
severity=IssueSeverity.WARNING,
translation_key="deprecated_device_trigger",
)
event_config = event_trigger.TRIGGER_SCHEMA(
{
EventTriggerArgument.PLATFORM: CONF_EVENT,
EventTriggerArgument.EVENT_TYPE: NANOLEAF_EVENT,
EventTriggerArgument.EVENT_DATA: {
CONF_TYPE: config[CONF_TYPE],
CONF_DEVICE_ID: config[CONF_DEVICE_ID],
},
}
)
return await event_trigger.async_attach_trigger(
hass, event_config, action, trigger_info, platform_type="device"
)
@@ -37,16 +37,6 @@
}
}
},
"device_automation": {
"trigger_type": {
"double_tap": "[%key:component::nanoleaf::entity::event::touch::state_attributes::event_type::state::double_tap%]",
"single_tap": "[%key:component::nanoleaf::entity::event::touch::state_attributes::event_type::state::single_tap%]",
"swipe_down": "[%key:component::nanoleaf::entity::event::touch::state_attributes::event_type::state::swipe_down%]",
"swipe_left": "[%key:component::nanoleaf::entity::event::touch::state_attributes::event_type::state::swipe_left%]",
"swipe_right": "[%key:component::nanoleaf::entity::event::touch::state_attributes::event_type::state::swipe_right%]",
"swipe_up": "[%key:component::nanoleaf::entity::event::touch::state_attributes::event_type::state::swipe_up%]"
}
},
"entity": {
"event": {
"touch": {
@@ -79,11 +69,5 @@
"invalid_token": {
"message": "The access token for the Nanoleaf device is invalid. Please reauthenticate."
}
},
"issues": {
"deprecated_device_trigger": {
"description": "The Nanoleaf device trigger is deprecated and will be removed in a future release. You can now use the gesture event entity to build automations.",
"title": "Nanoleaf device trigger is deprecated"
}
}
}
@@ -1,124 +0,0 @@
"""Tests for Nanoleaf device triggers."""
from unittest.mock import AsyncMock
from aionanoleaf2 import TouchEvent
import pytest
from pytest_homeassistant.common import MockConfigEntry, async_get_device_automations
from pytest_unordered import unordered
from homeassistant.components import automation
from homeassistant.components.device_automation import (
DeviceAutomationType,
DeviceNotFound,
)
from homeassistant.components.nanoleaf import DOMAIN
from homeassistant.components.nanoleaf.device_trigger import async_get_triggers
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import device_registry as dr, issue_registry as ir
from homeassistant.setup import async_setup_component
from . import setup_integration
TRIGGER_TYPES = [
"single_tap",
"double_tap",
"swipe_up",
"swipe_down",
"swipe_left",
"swipe_right",
]
@pytest.mark.parametrize(
("model", "expected_types"),
[
pytest.param("NL29", TRIGGER_TYPES, id="touch"),
pytest.param("NL22", [], id="no_touch"),
],
)
async def test_get_triggers(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
model: str,
expected_types: list[str],
) -> None:
"""Test the triggers of a Nanoleaf device depend on its touch support."""
config_entry = MockConfigEntry(domain=DOMAIN)
config_entry.add_to_hass(hass)
device_entry = device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
identifiers={(DOMAIN, "ABCDEF123456")},
model=model,
)
triggers = await async_get_device_automations(
hass, DeviceAutomationType.TRIGGER, device_entry.id
)
assert triggers == unordered(
[
{
"platform": "device",
"domain": DOMAIN,
"device_id": device_entry.id,
"type": trigger_type,
"metadata": {},
}
for trigger_type in expected_types
]
)
async def test_get_triggers_unknown_device(hass: HomeAssistant) -> None:
"""Test getting the triggers of an unknown device."""
with pytest.raises(DeviceNotFound):
await async_get_triggers(hass, "unknown")
async def test_if_fires_on_gesture(
hass: HomeAssistant,
mock_nanoleaf: AsyncMock,
mock_config_entry: MockConfigEntry,
device_registry: dr.DeviceRegistry,
issue_registry: ir.IssueRegistry,
service_calls: list[ServiceCall],
) -> None:
"""Test the trigger firing on a matching touch gesture."""
mock_nanoleaf.model = "NL42"
await setup_integration(hass, mock_config_entry)
device_entry = device_registry.async_get_device_by_identifier(
(DOMAIN, "ABCDEF123456"), mock_config_entry.entry_id
)
assert device_entry
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {
"platform": "device",
"domain": DOMAIN,
"device_id": device_entry.id,
"type": "swipe_up",
},
"action": {
"service": "test.automation",
"data_template": {"some": "{{ trigger.event.data.type }}"},
},
},
]
},
)
assert issue_registry.async_get_issue(DOMAIN, "deprecated_device_trigger_nanoleaf")
touch_callback = mock_nanoleaf.listen_events.call_args.kwargs["touch_callback"]
await touch_callback(TouchEvent({"gesture": 3, "panelId": -1}))
await hass.async_block_till_done()
assert len(service_calls) == 0
await touch_callback(TouchEvent({"gesture": 2, "panelId": -1}))
await hass.async_block_till_done()
assert len(service_calls) == 1
assert service_calls[0].data["some"] == "swipe_up"