Add event platform to SmartThings (#141066)

* Add event platform to SmartThings

* Add event platform to SmartThings

* Fix
This commit is contained in:
Joost Lekkerkerker 2025-03-21 16:20:42 +01:00 committed by GitHub
parent a9cbc72ce5
commit f84a46680d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 882 additions and 6 deletions

View File

@ -73,6 +73,7 @@ PLATFORMS = [
Platform.BINARY_SENSOR,
Platform.CLIMATE,
Platform.COVER,
Platform.EVENT,
Platform.FAN,
Platform.LIGHT,
Platform.LOCK,

View File

@ -32,14 +32,17 @@ class SmartThingsEntity(Entity):
device: FullDevice,
rooms: dict[str, str],
capabilities: set[Capability],
*,
component: str = MAIN,
) -> None:
"""Initialize the instance."""
self.client = client
self.capabilities = capabilities
self.component = component
self._internal_state: dict[Capability | str, dict[Attribute | str, Status]] = {
capability: device.status[MAIN][capability]
capability: device.status[component][capability]
for capability in capabilities
if capability in device.status[MAIN]
if capability in device.status[component]
}
self.device = device
self._attr_unique_id = device.device.device_id
@ -84,7 +87,7 @@ class SmartThingsEntity(Entity):
self.async_on_remove(
self.client.add_device_capability_event_listener(
self.device.device.device_id,
MAIN,
self.component,
capability,
self._update_handler,
)
@ -98,7 +101,7 @@ class SmartThingsEntity(Entity):
def supports_capability(self, capability: Capability) -> bool:
"""Test if device supports a capability."""
return capability in self.device.status[MAIN]
return capability in self.device.status[self.component]
def get_attribute_value(self, capability: Capability, attribute: Attribute) -> Any:
"""Get the value of a device attribute."""
@ -123,5 +126,5 @@ class SmartThingsEntity(Entity):
if argument is not None:
kwargs["argument"] = argument
await self.client.execute_device_command(
self.device.device.device_id, capability, command, MAIN, **kwargs
self.device.device.device_id, capability, command, self.component, **kwargs
)

View File

@ -0,0 +1,63 @@
"""Support for events through the SmartThings cloud API."""
from __future__ import annotations
from typing import cast
from pysmartthings import Attribute, Capability, Component, DeviceEvent, SmartThings
from homeassistant.components.event import EventDeviceClass, EventEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import FullDevice, SmartThingsConfigEntry
from .entity import SmartThingsEntity
async def async_setup_entry(
hass: HomeAssistant,
entry: SmartThingsConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Add events for a config entry."""
entry_data = entry.runtime_data
async_add_entities(
SmartThingsButtonEvent(entry_data.client, entry_data.rooms, device, component)
for device in entry_data.devices.values()
for component in device.device.components
if Capability.BUTTON in component.capabilities
)
class SmartThingsButtonEvent(SmartThingsEntity, EventEntity):
"""Define a SmartThings event."""
_attr_device_class = EventDeviceClass.BUTTON
_attr_translation_key = "button"
def __init__(
self,
client: SmartThings,
rooms: dict[str, str],
device: FullDevice,
component: Component,
) -> None:
"""Init the class."""
super().__init__(
client, device, rooms, {Capability.BUTTON}, component=component.id
)
self._attr_name = component.label
self._attr_unique_id = (
f"{device.device.device_id}_{component.id}_{Capability.BUTTON}"
)
@property
def event_types(self) -> list[str]:
"""Return the event types."""
return self.get_attribute_value(
Capability.BUTTON, Attribute.SUPPORTED_BUTTON_VALUES
)
def _update_handler(self, event: DeviceEvent) -> None:
self._trigger_event(cast(str, event.value))
self.async_write_ha_state()

View File

@ -46,6 +46,38 @@
"name": "Valve"
}
},
"event": {
"button": {
"state": {
"pushed": "Pushed",
"held": "Held",
"double": "Double",
"pushed_2x": "Pushed 2x",
"pushed_3x": "Pushed 3x",
"pushed_4x": "Pushed 4x",
"pushed_5x": "Pushed 5x",
"pushed_6x": "Pushed 6x",
"down": "Down",
"down_2x": "Down 2x",
"down_3x": "Down 3x",
"down_4x": "Down 4x",
"down_5x": "Down 5x",
"down_6x": "Down 6x",
"down_hold": "Down hold",
"up": "Up",
"up_2x": "Up 2x",
"up_3x": "Up 3x",
"up_4x": "Up 4x",
"up_5x": "Up 5x",
"up_6x": "Up 6x",
"up_hold": "Up hold",
"swipe_up": "Swipe up",
"swipe_down": "Swipe down",
"swipe_left": "Swipe left",
"swipe_right": "Swipe right"
}
}
},
"sensor": {
"lighting_mode": {
"name": "Activity lighting mode"

View File

@ -55,6 +55,7 @@ async def trigger_update(
attribute: Attribute,
value: str | float | dict[str, Any] | list[Any] | None,
data: dict[str, Any] | None = None,
component: str = MAIN,
) -> None:
"""Trigger an update."""
event = DeviceEvent(
@ -62,7 +63,7 @@ async def trigger_update(
"abc",
"abc",
device_id,
MAIN,
component,
capability,
attribute,
value,

View File

@ -131,6 +131,7 @@ def mock_smartthings() -> Generator[AsyncMock]:
"fake_fan",
"generic_fan_3_speed",
"heatit_ztrm3_thermostat",
"heatit_zpushwall",
"generic_ef00_v1",
"bosch_radiator_thermostat_ii",
"im_speaker_ai_0001",

View File

@ -0,0 +1,116 @@
{
"components": {
"button4": {
"button": {
"button": {
"value": "pushed",
"timestamp": "2025-02-10T08:01:11.326Z"
},
"numberOfButtons": {
"value": 1,
"timestamp": "2023-12-04T16:51:16.695Z"
},
"supportedButtonValues": {
"value": ["pushed", "held", "down_hold"],
"timestamp": "2023-12-04T16:51:16.717Z"
}
}
},
"button5": {
"button": {
"button": {
"value": "pushed",
"timestamp": "2025-03-09T16:37:40.792Z"
},
"numberOfButtons": {
"value": 1,
"timestamp": "2023-12-04T16:51:16.762Z"
},
"supportedButtonValues": {
"value": ["pushed", "held", "down_hold"],
"timestamp": "2023-12-04T16:51:16.813Z"
}
}
},
"button2": {
"button": {
"button": {
"value": "pushed",
"timestamp": "2025-02-10T08:00:57.171Z"
},
"numberOfButtons": {
"value": 1,
"timestamp": "2023-12-04T16:51:16.861Z"
},
"supportedButtonValues": {
"value": ["pushed", "held", "down_hold"],
"timestamp": "2023-12-04T16:51:16.906Z"
}
}
},
"button3": {
"button": {
"button": {
"value": "pushed",
"timestamp": "2025-01-30T05:53:00.663Z"
},
"numberOfButtons": {
"value": 1,
"timestamp": "2023-12-04T16:51:16.852Z"
},
"supportedButtonValues": {
"value": ["pushed", "held", "down_hold"],
"timestamp": "2023-12-04T16:51:16.848Z"
}
}
},
"button6": {
"button": {
"button": {
"value": "pushed",
"timestamp": "2024-10-02T13:11:07.346Z"
},
"numberOfButtons": {
"value": 1,
"timestamp": "2023-12-04T16:51:16.816Z"
},
"supportedButtonValues": {
"value": ["pushed", "held", "down_hold"],
"timestamp": "2023-12-04T16:51:16.848Z"
}
}
},
"main": {
"refresh": {},
"battery": {
"quantity": {
"value": null
},
"battery": {
"value": 100,
"unit": "%",
"timestamp": "2025-03-10T10:32:19.528Z"
},
"type": {
"value": null
}
}
},
"button1": {
"button": {
"button": {
"value": "pushed",
"timestamp": "2025-01-30T05:52:46.718Z"
},
"numberOfButtons": {
"value": 1,
"timestamp": "2023-12-04T16:51:16.717Z"
},
"supportedButtonValues": {
"value": ["pushed", "held", "down_hold"],
"timestamp": "2023-12-04T16:51:16.767Z"
}
}
}
}
}

View File

@ -0,0 +1,155 @@
{
"items": [
{
"deviceId": "5e5b97f3-3094-44e6-abc0-f61283412d6a",
"name": "heatit-zpushwall",
"label": "Livingroom smart switch",
"manufacturerName": "SmartThingsCommunity",
"presentationId": "52933933-7123-3315-a441-92d65df5f031",
"deviceManufacturerCode": "019B-0004-2403",
"locationId": "c85a9f8a-5d2e-4cdd-8bdb-bc49ba4a3544",
"ownerId": "7b68139b-d068-45d8-bf27-961320350024",
"roomId": "56e43461-2f7d-4c43-ba7c-29465f991289",
"components": [
{
"id": "main",
"label": "main",
"capabilities": [
{
"id": "battery",
"version": 1
},
{
"id": "refresh",
"version": 1
}
],
"categories": [
{
"name": "RemoteController",
"categoryType": "manufacturer"
}
]
},
{
"id": "button1",
"label": "button1",
"capabilities": [
{
"id": "button",
"version": 1
}
],
"categories": [
{
"name": "RemoteController",
"categoryType": "manufacturer"
}
]
},
{
"id": "button2",
"label": "button2",
"capabilities": [
{
"id": "button",
"version": 1
}
],
"categories": [
{
"name": "RemoteController",
"categoryType": "manufacturer"
}
]
},
{
"id": "button3",
"label": "button3",
"capabilities": [
{
"id": "button",
"version": 1
}
],
"categories": [
{
"name": "RemoteController",
"categoryType": "manufacturer"
}
]
},
{
"id": "button4",
"label": "button4",
"capabilities": [
{
"id": "button",
"version": 1
}
],
"categories": [
{
"name": "RemoteController",
"categoryType": "manufacturer"
}
]
},
{
"id": "button5",
"label": "button5",
"capabilities": [
{
"id": "button",
"version": 1
}
],
"categories": [
{
"name": "RemoteController",
"categoryType": "manufacturer"
}
]
},
{
"id": "button6",
"label": "button6",
"capabilities": [
{
"id": "button",
"version": 1
}
],
"categories": [
{
"name": "RemoteController",
"categoryType": "manufacturer"
}
]
}
],
"createTime": "2023-12-04T16:51:15.774Z",
"parentDeviceId": "4869d882-e898-40c3-a198-7611b72187a5",
"profile": {
"id": "2d6e59af-63df-3102-8515-66f3d75c9323"
},
"zwave": {
"networkId": "12",
"driverId": "1d39c140-ce10-490d-bf52-4de7b72caab6",
"executingLocally": true,
"hubId": "4869d882-e898-40c3-a198-7611b72187a5",
"networkSecurityLevel": "ZWAVE_S2_AUTHENTICATED",
"provisioningState": "NONFUNCTIONAL",
"manufacturerId": 411,
"productType": 4,
"productId": 9219
},
"type": "ZWAVE",
"restrictionTier": 0,
"allowed": null,
"executionContext": "LOCAL",
"relationships": []
}
],
"_links": {}
}

View File

@ -0,0 +1,361 @@
# serializer version: 1
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button1-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'event_types': list([
'pushed',
'held',
'down_hold',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'event',
'entity_category': None,
'entity_id': 'event.livingroom_smart_switch_button1',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
'original_icon': None,
'original_name': 'button1',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'button',
'unique_id': '5e5b97f3-3094-44e6-abc0-f61283412d6a_button1_button',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button1-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'button',
'event_type': None,
'event_types': list([
'pushed',
'held',
'down_hold',
]),
'friendly_name': 'Livingroom smart switch button1',
}),
'context': <ANY>,
'entity_id': 'event.livingroom_smart_switch_button1',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button2-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'event_types': list([
'pushed',
'held',
'down_hold',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'event',
'entity_category': None,
'entity_id': 'event.livingroom_smart_switch_button2',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
'original_icon': None,
'original_name': 'button2',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'button',
'unique_id': '5e5b97f3-3094-44e6-abc0-f61283412d6a_button2_button',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button2-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'button',
'event_type': None,
'event_types': list([
'pushed',
'held',
'down_hold',
]),
'friendly_name': 'Livingroom smart switch button2',
}),
'context': <ANY>,
'entity_id': 'event.livingroom_smart_switch_button2',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button3-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'event_types': list([
'pushed',
'held',
'down_hold',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'event',
'entity_category': None,
'entity_id': 'event.livingroom_smart_switch_button3',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
'original_icon': None,
'original_name': 'button3',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'button',
'unique_id': '5e5b97f3-3094-44e6-abc0-f61283412d6a_button3_button',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button3-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'button',
'event_type': None,
'event_types': list([
'pushed',
'held',
'down_hold',
]),
'friendly_name': 'Livingroom smart switch button3',
}),
'context': <ANY>,
'entity_id': 'event.livingroom_smart_switch_button3',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button4-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'event_types': list([
'pushed',
'held',
'down_hold',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'event',
'entity_category': None,
'entity_id': 'event.livingroom_smart_switch_button4',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
'original_icon': None,
'original_name': 'button4',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'button',
'unique_id': '5e5b97f3-3094-44e6-abc0-f61283412d6a_button4_button',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button4-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'button',
'event_type': None,
'event_types': list([
'pushed',
'held',
'down_hold',
]),
'friendly_name': 'Livingroom smart switch button4',
}),
'context': <ANY>,
'entity_id': 'event.livingroom_smart_switch_button4',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button5-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'event_types': list([
'pushed',
'held',
'down_hold',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'event',
'entity_category': None,
'entity_id': 'event.livingroom_smart_switch_button5',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
'original_icon': None,
'original_name': 'button5',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'button',
'unique_id': '5e5b97f3-3094-44e6-abc0-f61283412d6a_button5_button',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button5-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'button',
'event_type': None,
'event_types': list([
'pushed',
'held',
'down_hold',
]),
'friendly_name': 'Livingroom smart switch button5',
}),
'context': <ANY>,
'entity_id': 'event.livingroom_smart_switch_button5',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button6-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'event_types': list([
'pushed',
'held',
'down_hold',
]),
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'event',
'entity_category': None,
'entity_id': 'event.livingroom_smart_switch_button6',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <EventDeviceClass.BUTTON: 'button'>,
'original_icon': None,
'original_name': 'button6',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'button',
'unique_id': '5e5b97f3-3094-44e6-abc0-f61283412d6a_button6_button',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[heatit_zpushwall][event.livingroom_smart_switch_button6-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'button',
'event_type': None,
'event_types': list([
'pushed',
'held',
'down_hold',
]),
'friendly_name': 'Livingroom smart switch button6',
}),
'context': <ANY>,
'entity_id': 'event.livingroom_smart_switch_button6',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---

View File

@ -992,6 +992,39 @@
'via_device_id': None,
})
# ---
# name: test_devices[heatit_zpushwall]
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'config_entries_subentries': <ANY>,
'configuration_url': 'https://account.smartthings.com',
'connections': set({
}),
'disabled_by': None,
'entry_type': None,
'hw_version': None,
'id': <ANY>,
'identifiers': set({
tuple(
'smartthings',
'5e5b97f3-3094-44e6-abc0-f61283412d6a',
),
}),
'is_new': False,
'labels': set({
}),
'manufacturer': None,
'model': None,
'model_id': None,
'name': 'Livingroom smart switch',
'name_by_user': None,
'primary_config_entry': <ANY>,
'serial_number': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_devices[heatit_ztrm3_thermostat]
DeviceRegistryEntrySnapshot({
'area_id': None,

View File

@ -6578,6 +6578,55 @@
'state': '21.0',
})
# ---
# name: test_all_entities[heatit_zpushwall][sensor.livingroom_smart_switch_battery-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.livingroom_smart_switch_battery',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
'original_icon': None,
'original_name': 'Battery',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '5e5b97f3-3094-44e6-abc0-f61283412d6a.battery',
'unit_of_measurement': '%',
})
# ---
# name: test_all_entities[heatit_zpushwall][sensor.livingroom_smart_switch_battery-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'battery',
'friendly_name': 'Livingroom smart switch Battery',
'unit_of_measurement': '%',
}),
'context': <ANY>,
'entity_id': 'sensor.livingroom_smart_switch_battery',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '100',
})
# ---
# name: test_all_entities[heatit_ztrm3_thermostat][sensor.hall_thermostat_energy-entry]
EntityRegistryEntrySnapshot({
'aliases': set({

View File

@ -0,0 +1,61 @@
"""Test for the SmartThings event platform."""
from unittest.mock import AsyncMock
from freezegun.api import FrozenDateTimeFactory
from pysmartthings import Attribute, Capability
import pytest
from syrupy import SnapshotAssertion
from homeassistant.const import STATE_UNKNOWN, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from . import setup_integration, snapshot_smartthings_entities, trigger_update
from tests.common import MockConfigEntry
async def test_all_entities(
hass: HomeAssistant,
snapshot: SnapshotAssertion,
devices: AsyncMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test all entities."""
await setup_integration(hass, mock_config_entry)
snapshot_smartthings_entities(hass, entity_registry, snapshot, Platform.EVENT)
@pytest.mark.parametrize("device_fixture", ["heatit_zpushwall"])
async def test_state_update(
hass: HomeAssistant,
devices: AsyncMock,
mock_config_entry: MockConfigEntry,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test state 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
)
await trigger_update(
hass,
devices,
"5e5b97f3-3094-44e6-abc0-f61283412d6a",
Capability.BUTTON,
Attribute.BUTTON,
"pushed",
component="button1",
)
assert (
hass.states.get("event.livingroom_smart_switch_button1").state
== "2023-10-21T00:00:00.000+00:00"
)