mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Only trigger events on button updates in SmartThings (#141720)
Only trigger events on button updates
This commit is contained in:
parent
df2a94bb5b
commit
d88f7b8600
@ -58,5 +58,6 @@ class SmartThingsButtonEvent(SmartThingsEntity, EventEntity):
|
||||
)
|
||||
|
||||
def _update_handler(self, event: DeviceEvent) -> None:
|
||||
self._trigger_event(cast(str, event.value))
|
||||
self.async_write_ha_state()
|
||||
if event.attribute is Attribute.BUTTON:
|
||||
self._trigger_event(cast(str, event.value))
|
||||
super()._update_handler(event)
|
||||
|
@ -7,6 +7,7 @@ from pysmartthings import Attribute, Capability
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.event import ATTR_EVENT_TYPES
|
||||
from homeassistant.const import STATE_UNKNOWN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -59,3 +60,40 @@ async def test_state_update(
|
||||
hass.states.get("event.livingroom_smart_switch_button1").state
|
||||
== "2023-10-21T00:00:00.000+00:00"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["heatit_zpushwall"])
|
||||
async def test_supported_button_values_update(
|
||||
hass: HomeAssistant,
|
||||
devices: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test supported button values update."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
freezer.move_to("2023-10-21")
|
||||
|
||||
assert (
|
||||
hass.states.get("event.livingroom_smart_switch_button1").state == STATE_UNKNOWN
|
||||
)
|
||||
assert hass.states.get("event.livingroom_smart_switch_button1").attributes[
|
||||
ATTR_EVENT_TYPES
|
||||
] == ["pushed", "held", "down_hold"]
|
||||
|
||||
await trigger_update(
|
||||
hass,
|
||||
devices,
|
||||
"5e5b97f3-3094-44e6-abc0-f61283412d6a",
|
||||
Capability.BUTTON,
|
||||
Attribute.SUPPORTED_BUTTON_VALUES,
|
||||
["pushed", "held", "down_hold", "pushed_2x"],
|
||||
component="button1",
|
||||
)
|
||||
|
||||
assert (
|
||||
hass.states.get("event.livingroom_smart_switch_button1").state == STATE_UNKNOWN
|
||||
)
|
||||
assert hass.states.get("event.livingroom_smart_switch_button1").attributes[
|
||||
ATTR_EVENT_TYPES
|
||||
] == ["pushed", "held", "down_hold", "pushed_2x"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user