8
8
from homeassistant .config_entries import ConfigEntry
9
9
from homeassistant .const import TIME_MINUTES
10
10
from homeassistant .core import HomeAssistant
11
- from homeassistant .helpers import device_registry , entity_registry
11
+ from homeassistant .helpers import device_registry , entity_component , entity_registry
12
+
12
13
import voluptuous as vol
13
14
import websockets
14
15
@@ -202,9 +203,14 @@ async def update(self, cp_id: str):
202
203
dr = device_registry .async_get (self .hass )
203
204
identifiers = {(DOMAIN , cp_id )}
204
205
dev = dr .async_get_device (identifiers )
205
- for ent in entity_registry .async_entries_for_device (er , dev ):
206
- if ent .platform == SENSOR :
207
- self .hass .async_create_task (ent .update ())
206
+ # _LOGGER.info("Device id: %s updating", dev.name)
207
+ for ent in entity_registry .async_entries_for_device (er , dev .id ):
208
+ if SENSOR in ent .entity_id :
209
+ # _LOGGER.info("Entity id: %s updating", ent.entity_id)
210
+ self .hass .async_create_task (
211
+ entity_component .async_update_entity (self .hass , ent .entity_id )
212
+ )
213
+
208
214
209
215
def device_info (self ):
210
216
"""Return device information."""
@@ -646,7 +652,7 @@ async def async_update_device_info(self, boot_info: dict):
646
652
647
653
_LOGGER .debug ("Updating device info %s: %s" , self .central .cpid , boot_info )
648
654
649
- dr = await device_registry .async_get_registry (self .hass )
655
+ dr = device_registry .async_get (self .hass )
650
656
651
657
serial = boot_info .get (om .charge_point_serial_number .name , None )
652
658
@@ -723,7 +729,7 @@ def on_boot_notification(self, **kwargs):
723
729
)
724
730
725
731
asyncio .create_task (self .async_update_device_info (kwargs ))
726
-
732
+ self . hass . async_create_task ( self . central . update ( self . central . cpid ))
727
733
return call_result .BootNotificationPayload (
728
734
current_time = datetime .now (tz = timezone .utc ).isoformat (),
729
735
interval = 30 ,
@@ -752,6 +758,7 @@ def on_status_notification(self, connector_id, error_code, status, **kwargs):
752
758
def on_firmware_status (self , status , ** kwargs ):
753
759
"""Handle firmware status notification."""
754
760
self ._metrics [cstat .firmware_status .value ] = status
761
+ self .hass .async_create_task (self .central .update (self .central .cpid ))
755
762
return call_result .FirmwareStatusNotificationPayload ()
756
763
757
764
@on (Action .Authorize )
@@ -768,6 +775,7 @@ def on_start_transaction(self, connector_id, id_tag, meter_start, **kwargs):
768
775
self ._metrics [cstat .stop_reason .value ] = ""
769
776
self ._metrics [csess .transaction_id .value ] = self ._transactionId
770
777
self ._metrics [csess .meter_start .value ] = int (meter_start ) / 1000
778
+ self .hass .async_create_task (self .central .update (self .central .cpid ))
771
779
return call_result .StartTransactionPayload (
772
780
id_tag_info = {om .status .value : AuthorizationStatus .accepted .value },
773
781
transaction_id = self ._transactionId ,
@@ -789,6 +797,7 @@ def on_stop_transaction(self, meter_stop, timestamp, transaction_id, **kwargs):
789
797
self ._metrics [Measurand .power_active_import .value ] = 0
790
798
if Measurand .power_reactive_import .value in self ._metrics :
791
799
self ._metrics [Measurand .power_reactive_import .value ] = 0
800
+ self .hass .async_create_task (self .central .update (self .central .cpid ))
792
801
return call_result .StopTransactionPayload (
793
802
id_tag_info = {om .status .value : AuthorizationStatus .accepted .value }
794
803
)
@@ -804,7 +813,7 @@ def on_heartbeat(self, **kwargs):
804
813
"""Handle a Heartbeat."""
805
814
now = datetime .now (tz = timezone .utc ).isoformat ()
806
815
self ._metrics [cstat .heartbeat .value ] = now
807
- self ._units [ cstat . heartbeat . value ] = "time"
816
+ self .hass . async_create_task ( self . central . update ( self . central . cpid ))
808
817
return call_result .HeartbeatPayload (current_time = now )
809
818
810
819
def get_metric (self , measurand : str ):
0 commit comments