78
78
gather_with_limited_concurrency ,
79
79
)
80
80
from zha .event import EventBase
81
+ from zha .websocket import ZHAWebSocketException
81
82
from zha .websocket .client .client import Client
82
83
from zha .websocket .client .helpers import (
83
84
AlarmControlPanelHelper ,
113
114
114
115
if TYPE_CHECKING :
115
116
from zha .application .platforms .events import EntityStateChangedEvent
116
- from zha .websocket .server .api .model import (
117
- WebSocketCommand ,
118
- WebSocketCommandResponse ,
119
- )
120
117
from zha .zigbee .model import ExtendedDeviceInfo , ZHAEvent
121
118
122
119
BLOCK_LOG_TIMEOUT : Final [int ] = 60
@@ -913,10 +910,10 @@ def __init__(self, config: ZHAData) -> None:
913
910
self ._client : Client = Client (
914
911
self ._ws_server_url , aiohttp_session = config .ws_client_config .aiohttp_session
915
912
)
913
+ self ._state : State
916
914
self ._devices : dict [EUI64 , WebSocketClientDevice ] = {}
917
915
self ._groups : dict [int , WebSocketClientGroup ] = {}
918
916
self .coordinator_zha_device : WebSocketClientDevice = None # type: ignore[assignment]
919
- self ._state : State
920
917
self .lights : LightHelper = LightHelper (self ._client )
921
918
self .switches : SwitchHelper = SwitchHelper (self ._client )
922
919
self .sirens : SirenHelper = SirenHelper (self ._client )
@@ -965,9 +962,10 @@ async def connect(self) -> None:
965
962
try :
966
963
async with timeout (CONNECT_TIMEOUT ):
967
964
await self ._client .connect ()
968
- except Exception as err :
965
+ except TimeoutError as err :
969
966
_LOGGER .exception ("Unable to connect to the ZHA wss" , exc_info = err )
970
- raise err
967
+ await self ._client .disconnect ()
968
+ raise ZHAWebSocketException from err
971
969
972
970
async def disconnect (self ) -> None :
973
971
"""Disconnect from the websocket server."""
@@ -992,10 +990,6 @@ def create_and_track_task(self, coroutine: Coroutine) -> asyncio.Task:
992
990
task .add_done_callback (self ._tasks .remove )
993
991
return task
994
992
995
- async def send_command (self , command : WebSocketCommand ) -> WebSocketCommandResponse :
996
- """Send a command and get a response."""
997
- return await self ._client .async_send_command (command )
998
-
999
993
async def load_devices (self ) -> None :
1000
994
"""Restore ZHA devices from zigpy application state."""
1001
995
response_devices = await self .devices_helper .get_devices ()
@@ -1104,7 +1098,7 @@ def handle_state_changed(self, event: EntityStateChangedEvent) -> None:
1104
1098
def handle_zha_event (self , event : ZHAEvent ) -> None :
1105
1099
"""Handle a zha_event from the websocket server."""
1106
1100
_LOGGER .debug ("zha_event: %s" , event )
1107
- device = self .devices .get (event .device . ieee )
1101
+ device = self .devices .get (event .device_ieee )
1108
1102
if device is None :
1109
1103
_LOGGER .warning ("Received zha_event from unknown device: %s" , event )
1110
1104
return
0 commit comments