Skip to content

Commit 2e16dc3

Browse files
committed
enable / disable
1 parent 94e070c commit 2e16dc3

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

zha/application/platforms/websocket_api.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@ async def refresh_state(
100100
await execute_platform_entity_command(server, client, command, "async_update")
101101

102102

103+
class PlatformEntityEnableCommand(PlatformEntityCommand):
104+
"""Platform entity enable command."""
105+
106+
command: Literal[APICommands.PLATFORM_ENTITY_ENABLE] = (
107+
APICommands.PLATFORM_ENTITY_ENABLE
108+
)
109+
110+
111+
@decorators.websocket_command(PlatformEntityEnableCommand)
112+
@decorators.async_response
113+
async def enable(
114+
server: Server, client: Client, command: PlatformEntityEnableCommand
115+
) -> None:
116+
"""Enable the platform entity."""
117+
await execute_platform_entity_command(server, client, command, "enable")
118+
119+
120+
class PlatformEntityDisableCommand(PlatformEntityCommand):
121+
"""Platform entity disable command."""
122+
123+
command: Literal[APICommands.PLATFORM_ENTITY_DISABLE] = (
124+
APICommands.PLATFORM_ENTITY_DISABLE
125+
)
126+
127+
128+
@decorators.websocket_command(PlatformEntityDisableCommand)
129+
@decorators.async_response
130+
async def disable(
131+
server: Server, client: Client, command: PlatformEntityDisableCommand
132+
) -> None:
133+
"""Disable the platform entity."""
134+
await execute_platform_entity_command(server, client, command, "disable")
135+
136+
103137
# pylint: disable=import-outside-toplevel
104138
def load_platform_entity_apis(server: Server) -> None:
105139
"""Load the ws apis for all platform entities types."""
@@ -128,6 +162,8 @@ def load_platform_entity_apis(server: Server) -> None:
128162
)
129163

130164
register_api_command(server, refresh_state)
165+
register_api_command(server, enable)
166+
register_api_command(server, disable)
131167
load_alarm_control_panel_api(server)
132168
load_button_api(server)
133169
load_climate_api(server)

zha/websocket/const.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class APICommands(StrEnum):
4747
LOCK_ENAABLE_USER_CODE = "lock_enable_user_lock_code"
4848
LOCK_DISABLE_USER_CODE = "lock_disable_user_lock_code"
4949
LOCK_CLEAR_USER_CODE = "lock_clear_user_lock_code"
50+
LOCK_RESTORE_EXTERNAL_STATE_ATTRIBUTES = "lock_restore_external_state_attributes"
5051

5152
CLIMATE_SET_TEMPERATURE = "climate_set_temperature"
5253
CLIMATE_SET_HVAC_MODE = "climate_set_hvac_mode"
@@ -77,10 +78,15 @@ class APICommands(StrEnum):
7778
ALARM_CONTROL_PANEL_TRIGGER = "alarm_control_panel_trigger"
7879

7980
SELECT_SELECT_OPTION = "select_select_option"
81+
SELECT_RESTORE_EXTERNAL_STATE_ATTRIBUTES = (
82+
"select_restore_external_state_attributes"
83+
)
8084

8185
NUMBER_SET_VALUE = "number_set_value"
8286

8387
PLATFORM_ENTITY_REFRESH_STATE = "platform_entity_refresh_state"
88+
PLATFORM_ENTITY_ENABLE = "platform_entity_enable"
89+
PLATFORM_ENTITY_DISABLE = "platform_entity_disable"
8490

8591
CLIENT_LISTEN = "client_listen"
8692
CLIENT_LISTEN_RAW_ZCL = "client_listen_raw_zcl"

0 commit comments

Comments
 (0)