7878 gather_with_limited_concurrency ,
7979)
8080from zha .event import EventBase
81+ from zha .websocket import ZHAWebSocketException
8182from zha .websocket .client .client import Client
8283from zha .websocket .client .helpers import (
8384 AlarmControlPanelHelper ,
113114
114115if TYPE_CHECKING :
115116 from zha .application .platforms .events import EntityStateChangedEvent
116- from zha .websocket .server .api .model import (
117- WebSocketCommand ,
118- WebSocketCommandResponse ,
119- )
120117 from zha .zigbee .model import ExtendedDeviceInfo , ZHAEvent
121118
122119BLOCK_LOG_TIMEOUT : Final [int ] = 60
@@ -913,10 +910,10 @@ def __init__(self, config: ZHAData) -> None:
913910 self ._client : Client = Client (
914911 self ._ws_server_url , aiohttp_session = config .ws_client_config .aiohttp_session
915912 )
913+ self ._state : State
916914 self ._devices : dict [EUI64 , WebSocketClientDevice ] = {}
917915 self ._groups : dict [int , WebSocketClientGroup ] = {}
918916 self .coordinator_zha_device : WebSocketClientDevice = None # type: ignore[assignment]
919- self ._state : State
920917 self .lights : LightHelper = LightHelper (self ._client )
921918 self .switches : SwitchHelper = SwitchHelper (self ._client )
922919 self .sirens : SirenHelper = SirenHelper (self ._client )
@@ -965,9 +962,10 @@ async def connect(self) -> None:
965962 try :
966963 async with timeout (CONNECT_TIMEOUT ):
967964 await self ._client .connect ()
968- except Exception as err :
965+ except TimeoutError as err :
969966 _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
971969
972970 async def disconnect (self ) -> None :
973971 """Disconnect from the websocket server."""
@@ -992,10 +990,6 @@ def create_and_track_task(self, coroutine: Coroutine) -> asyncio.Task:
992990 task .add_done_callback (self ._tasks .remove )
993991 return task
994992
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-
999993 async def load_devices (self ) -> None :
1000994 """Restore ZHA devices from zigpy application state."""
1001995 response_devices = await self .devices_helper .get_devices ()
@@ -1104,7 +1098,7 @@ def handle_state_changed(self, event: EntityStateChangedEvent) -> None:
11041098 def handle_zha_event (self , event : ZHAEvent ) -> None :
11051099 """Handle a zha_event from the websocket server."""
11061100 _LOGGER .debug ("zha_event: %s" , event )
1107- device = self .devices .get (event .device . ieee )
1101+ device = self .devices .get (event .device_ieee )
11081102 if device is None :
11091103 _LOGGER .warning ("Received zha_event from unknown device: %s" , event )
11101104 return
0 commit comments