9
9
from pydantic import Field
10
10
from zigpy .types .named import EUI64
11
11
12
- from zha .websocket .const import DURATION , GROUPS , APICommands
12
+ from zha .websocket .const import GROUPS , APICommands
13
13
from zha .websocket .server .api import decorators , register_api_command
14
14
from zha .websocket .server .api .model import (
15
15
GetApplicationStateResponse ,
16
16
GetDevicesResponse ,
17
+ GroupsResponse ,
18
+ PermitJoiningResponse ,
17
19
ReadClusterAttributesResponse ,
20
+ UpdateGroupResponse ,
18
21
WebSocketCommand ,
19
22
WriteClusterAttributeResponse ,
20
23
)
@@ -150,7 +153,14 @@ async def get_groups(
150
153
group .info_object
151
154
) # maybe we should change the group_id type...
152
155
_LOGGER .info ("groups: %s" , groups )
153
- client .send_result_success (command , {GROUPS : groups })
156
+ client .send_result_success (
157
+ command ,
158
+ GroupsResponse (
159
+ ** command .model_dump (exclude = "model_class_name" ),
160
+ groups = groups ,
161
+ success = True ,
162
+ ),
163
+ )
154
164
155
165
156
166
class PermitJoiningCommand (WebSocketCommand ):
@@ -169,10 +179,13 @@ async def permit_joining(
169
179
"""Permit joining devices to the Zigbee network."""
170
180
# TODO add permit with code support
171
181
await gateway .application_controller .permit (command .duration , command .ieee )
172
- client .send_result_success (
173
- command ,
174
- {DURATION : command .duration },
182
+ response = PermitJoiningResponse (
183
+ ** command .model_dump (exclude = "model_class_name" ),
184
+ success = True ,
185
+ duration = command .duration ,
186
+ ieee = command .ieee ,
175
187
)
188
+ client .send_result_success (command , response )
176
189
177
190
178
191
class RemoveDeviceCommand (WebSocketCommand ):
@@ -358,7 +371,12 @@ async def create_group(
358
371
members = command .members
359
372
group_id = command .group_id
360
373
group : Group = await gateway .async_create_zigpy_group (group_name , members , group_id )
361
- client .send_result_success (command , {"group" : group .info_object })
374
+ response = UpdateGroupResponse (
375
+ ** command .model_dump (exclude = "model_class_name" ),
376
+ group = group .info_object ,
377
+ success = True ,
378
+ )
379
+ client .send_result_success (command , response )
362
380
363
381
364
382
class RemoveGroupsCommand (WebSocketCommand ):
@@ -416,7 +434,12 @@ async def add_group_members(
416
434
if not group :
417
435
client .send_result_error (command , "G1" , "ZHA Group not found" )
418
436
return
419
- client .send_result_success (command , {GROUP : group .info_object })
437
+ response = UpdateGroupResponse (
438
+ ** command .model_dump (exclude = "model_class_name" ),
439
+ group = group .info_object ,
440
+ success = True ,
441
+ )
442
+ client .send_result_success (command , response )
420
443
421
444
422
445
class RemoveGroupMembersCommand (AddGroupMembersCommand ):
@@ -443,7 +466,12 @@ async def remove_group_members(
443
466
if not group :
444
467
client .send_result_error (command , "G1" , "ZHA Group not found" )
445
468
return
446
- client .send_result_success (command , {GROUP : group .info_object })
469
+ response = UpdateGroupResponse (
470
+ ** command .model_dump (exclude = "model_class_name" ),
471
+ group = group .info_object ,
472
+ success = True ,
473
+ )
474
+ client .send_result_success (command , response )
447
475
448
476
449
477
class StopServerCommand (WebSocketCommand ):
0 commit comments