Skip to content

Commit 0c6dda1

Browse files
committed
commands
1 parent 2e16dc3 commit 0c6dda1

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

zha/websocket/client/helpers.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@
4949
LockDisableUserLockCodeCommand,
5050
LockEnableUserLockCodeCommand,
5151
LockLockCommand,
52+
LockRestoreExternalStateAttributesCommand,
5253
LockSetUserLockCodeCommand,
5354
LockUnlockCommand,
5455
)
5556
from zha.application.platforms.model import BaseEntityInfo, BasePlatformEntityInfo
5657
from zha.application.platforms.number.websocket_api import NumberSetValueCommand
57-
from zha.application.platforms.select.websocket_api import SelectSelectOptionCommand
58+
from zha.application.platforms.select.websocket_api import (
59+
SelectRestoreExternalStateAttributesCommand,
60+
SelectSelectOptionCommand,
61+
)
5862
from zha.application.platforms.siren.websocket_api import (
5963
SirenTurnOffCommand,
6064
SirenTurnOnCommand,
@@ -63,7 +67,11 @@
6367
SwitchTurnOffCommand,
6468
SwitchTurnOnCommand,
6569
)
66-
from zha.application.platforms.websocket_api import PlatformEntityRefreshStateCommand
70+
from zha.application.platforms.websocket_api import (
71+
PlatformEntityDisableCommand,
72+
PlatformEntityEnableCommand,
73+
PlatformEntityRefreshStateCommand,
74+
)
6775
from zha.application.websocket_api import (
6876
AddGroupMembersCommand,
6977
CreateGroupCommand,
@@ -552,6 +560,20 @@ async def disable_user_lock_code(
552560
)
553561
return await self._client.async_send_command(command)
554562

563+
async def restore_external_state_attributes(
564+
self,
565+
lock_platform_entity: BasePlatformEntityInfo,
566+
state: Literal["locked", "unlocked"] | None,
567+
) -> WebSocketCommandResponse:
568+
"""Restore external state attributes."""
569+
ensure_platform_entity(lock_platform_entity, Platform.LOCK)
570+
command = LockRestoreExternalStateAttributesCommand(
571+
ieee=lock_platform_entity.device_ieee,
572+
unique_id=lock_platform_entity.unique_id,
573+
state=state,
574+
)
575+
return await self._client.async_send_command(command)
576+
555577

556578
class NumberHelper:
557579
"""Helper to issue number commands."""
@@ -596,6 +618,20 @@ async def select_option(
596618
)
597619
return await self._client.async_send_command(command)
598620

621+
async def restore_external_state_attributes(
622+
self,
623+
select_platform_entity: BasePlatformEntityInfo,
624+
state: str | None,
625+
) -> WebSocketCommandResponse:
626+
"""Restore external state attributes."""
627+
ensure_platform_entity(select_platform_entity, Platform.SELECT)
628+
command = SelectRestoreExternalStateAttributesCommand(
629+
ieee=select_platform_entity.device_ieee,
630+
unique_id=select_platform_entity.unique_id,
631+
state=state,
632+
)
633+
return await self._client.async_send_command(command)
634+
599635

600636
class ClimateHelper:
601637
"""Helper to issue climate commands."""
@@ -768,6 +804,28 @@ async def refresh_state(
768804
)
769805
return await self._client.async_send_command(command)
770806

807+
async def enable(
808+
self, platform_entity: BasePlatformEntityInfo
809+
) -> WebSocketCommandResponse:
810+
"""Enable a platform entity."""
811+
command = PlatformEntityEnableCommand(
812+
ieee=platform_entity.device_ieee,
813+
unique_id=platform_entity.unique_id,
814+
platform=platform_entity.platform,
815+
)
816+
return await self._client.async_send_command(command)
817+
818+
async def disable(
819+
self, platform_entity: BasePlatformEntityInfo
820+
) -> WebSocketCommandResponse:
821+
"""Disable a platform entity."""
822+
command = PlatformEntityDisableCommand(
823+
ieee=platform_entity.device_ieee,
824+
unique_id=platform_entity.unique_id,
825+
platform=platform_entity.platform,
826+
)
827+
return await self._client.async_send_command(command)
828+
771829

772830
class ClientHelper:
773831
"""Helper to send client specific commands."""

zha/websocket/server/api/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class WebSocketCommand(BaseModel):
3636
APICommands.CLIENT_LISTEN,
3737
APICommands.BUTTON_PRESS,
3838
APICommands.PLATFORM_ENTITY_REFRESH_STATE,
39+
APICommands.PLATFORM_ENTITY_ENABLE,
40+
APICommands.PLATFORM_ENTITY_DISABLE,
3941
APICommands.ALARM_CONTROL_PANEL_DISARM,
4042
APICommands.ALARM_CONTROL_PANEL_ARM_HOME,
4143
APICommands.ALARM_CONTROL_PANEL_ARM_AWAY,
@@ -58,13 +60,15 @@ class WebSocketCommand(BaseModel):
5860
APICommands.SIREN_TURN_ON,
5961
APICommands.SIREN_TURN_OFF,
6062
APICommands.SELECT_SELECT_OPTION,
63+
APICommands.SELECT_RESTORE_EXTERNAL_STATE_ATTRIBUTES,
6164
APICommands.NUMBER_SET_VALUE,
6265
APICommands.LOCK_CLEAR_USER_CODE,
6366
APICommands.LOCK_SET_USER_CODE,
6467
APICommands.LOCK_ENAABLE_USER_CODE,
6568
APICommands.LOCK_DISABLE_USER_CODE,
6669
APICommands.LOCK_LOCK,
6770
APICommands.LOCK_UNLOCK,
71+
APICommands.LOCK_RESTORE_EXTERNAL_STATE_ATTRIBUTES,
6872
APICommands.LIGHT_TURN_OFF,
6973
APICommands.LIGHT_TURN_ON,
7074
APICommands.FAN_SET_PERCENTAGE,
@@ -118,6 +122,7 @@ class ErrorResponse(WebSocketCommandResponse):
118122
"error.lock_clear_user_lock_code",
119123
"error.lock_disable_user_lock_code",
120124
"error.lock_enable_user_lock_code",
125+
"error.lock_restore_external_state_attributes",
121126
"error.fan_turn_on",
122127
"error.fan_turn_off",
123128
"error.fan_set_percentage",
@@ -142,10 +147,13 @@ class ErrorResponse(WebSocketCommandResponse):
142147
"error.alarm_control_panel_arm_night",
143148
"error.alarm_control_panel_trigger",
144149
"error.select_select_option",
150+
"error.select_restore_external_state_attributes",
145151
"error.siren_turn_on",
146152
"error.siren_turn_off",
147153
"error.number_set_value",
148154
"error.platform_entity_refresh_state",
155+
"error.platform_entity_enable",
156+
"error.platform_entity_disable",
149157
"error.client_listen",
150158
"error.client_listen_raw_zcl",
151159
"error.client_disconnect",
@@ -172,6 +180,7 @@ class DefaultResponse(WebSocketCommandResponse):
172180
"lock_clear_user_lock_code",
173181
"lock_disable_user_lock_code",
174182
"lock_enable_user_lock_code",
183+
"lock_restore_external_state_attributes",
175184
"fan_turn_on",
176185
"fan_turn_off",
177186
"fan_set_percentage",
@@ -196,10 +205,13 @@ class DefaultResponse(WebSocketCommandResponse):
196205
"alarm_control_panel_arm_night",
197206
"alarm_control_panel_trigger",
198207
"select_select_option",
208+
"select_restore_external_state_attributes",
199209
"siren_turn_on",
200210
"siren_turn_off",
201211
"number_set_value",
202212
"platform_entity_refresh_state",
213+
"platform_entity_enable",
214+
"platform_entity_disable",
203215
"client_listen",
204216
"client_listen_raw_zcl",
205217
"client_disconnect",

0 commit comments

Comments
 (0)