5
5
from abc import abstractmethod
6
6
import asyncio
7
7
from contextlib import suppress
8
+ import functools
8
9
from functools import cached_property
9
10
import logging
10
11
from typing import TYPE_CHECKING , Any , Generic , Literal , TypeVar , final
29
30
30
31
if TYPE_CHECKING :
31
32
from zha .zigbee .cluster_handlers import ClusterHandler
32
- from zha .zigbee .device import Device
33
+ from zha .zigbee .device import Device , WebSocketClientDevice
33
34
from zha .zigbee .endpoint import Endpoint
34
35
from zha .zigbee .group import Group
35
36
@@ -483,10 +484,13 @@ async def async_update(self, _: Any | None = None) -> None:
483
484
class WebSocketClientEntity (BaseEntity , Generic [BaseEntityInfoType ]):
484
485
"""Entity repsentation for the websocket client."""
485
486
486
- def __init__ (self , entity_info : BaseEntityInfoType ) -> None :
487
+ def __init__ (
488
+ self , entity_info : BaseEntityInfoType , device : WebSocketClientDevice
489
+ ) -> None :
487
490
"""Initialize the websocket client entity."""
488
491
super ().__init__ (entity_info .unique_id )
489
492
self .PLATFORM = entity_info .platform
493
+ self ._device : WebSocketClientDevice = device
490
494
self ._entity_info : BaseEntityInfoType = entity_info
491
495
self ._attr_enabled = self ._entity_info .enabled
492
496
self ._attr_fallback_name = self ._entity_info .fallback_name
@@ -498,6 +502,11 @@ def __init__(self, entity_info: BaseEntityInfoType) -> None:
498
502
self ._attr_device_class = self ._entity_info .device_class
499
503
self ._attr_state_class = self ._entity_info .state_class
500
504
505
+ @functools .cached_property
506
+ def info_object (self ) -> BaseEntityInfoType :
507
+ """Return a representation of the alarm control panel."""
508
+ return self ._entity_info
509
+
501
510
@property
502
511
def state (self ) -> dict [str , Any ]:
503
512
"""Return the arguments to use in the command."""
@@ -507,3 +516,8 @@ def state(self) -> dict[str, Any]:
507
516
def state (self , value : dict [str , Any ]) -> None :
508
517
"""Set the state of the entity."""
509
518
self ._entity_info .state = value
519
+
520
+ async def async_update (self ) -> None :
521
+ """Retrieve latest state."""
522
+ self .debug ("polling current state" )
523
+ await self ._device .gateway .entities .refresh_state (self ._entity_info )
0 commit comments