1
1
"""Representation of a OCCP Entities."""
2
+
2
3
from __future__ import annotations
3
4
4
5
import asyncio
5
6
from collections import defaultdict
6
- from datetime import datetime , timedelta , timezone
7
+ from datetime import datetime , timedelta , UTC
7
8
import json
8
9
import logging
9
10
from math import sqrt
@@ -784,8 +785,7 @@ async def start_transaction(self):
784
785
return False
785
786
786
787
async def stop_transaction (self ):
787
- """
788
- Request remote stop of current transaction.
788
+ """Request remote stop of current transaction.
789
789
790
790
Leaves charger in finishing state until unplugged.
791
791
Use reset() to make the charger available again for remote start
@@ -836,9 +836,9 @@ async def update_firmware(self, firmware_url: str, wait_time: int = 0):
836
836
url = schema (firmware_url )
837
837
except vol .MultipleInvalid as e :
838
838
_LOGGER .debug ("Failed to parse url: %s" , e )
839
- update_time = (
840
- datetime . now ( tz = timezone . utc ) + timedelta ( hours = wait_time )
841
- ). strftime ( "%Y-%m-%dT%H:%M:%SZ" )
839
+ update_time = (datetime . now ( tz = UTC ) + timedelta ( hours = wait_time )). strftime (
840
+ "%Y-%m-%dT%H:%M:%SZ"
841
+ )
842
842
req = call .UpdateFirmware (location = url , retrieve_date = update_time )
843
843
resp = await self .call (req )
844
844
_LOGGER .info ("Response: %s" , resp )
@@ -875,9 +875,7 @@ async def data_transfer(self, vendor_id: str, message_id: str = "", data: str =
875
875
data ,
876
876
resp .data ,
877
877
)
878
- self ._metrics [cdet .data_response .value ].value = datetime .now (
879
- tz = timezone .utc
880
- )
878
+ self ._metrics [cdet .data_response .value ].value = datetime .now (tz = UTC )
881
879
self ._metrics [cdet .data_response .value ].extra_attr = {message_id : resp .data }
882
880
return True
883
881
else :
@@ -897,9 +895,7 @@ async def get_configuration(self, key: str = ""):
897
895
if resp .configuration_key :
898
896
value = resp .configuration_key [0 ][om .value .value ]
899
897
_LOGGER .debug ("Get Configuration for %s: %s" , key , value )
900
- self ._metrics [cdet .config_response .value ].value = datetime .now (
901
- tz = timezone .utc
902
- )
898
+ self ._metrics [cdet .config_response .value ].value = datetime .now (tz = UTC )
903
899
self ._metrics [cdet .config_response .value ].extra_attr = {key : value }
904
900
return value
905
901
if resp .unknown_key :
@@ -994,7 +990,7 @@ async def monitor_connection(self):
994
990
self ._metrics [cstat .latency_ping .value ].value = latency_ping
995
991
self ._metrics [cstat .latency_pong .value ].value = latency_pong
996
992
997
- except asyncio . TimeoutError as timeout_exception :
993
+ except TimeoutError as timeout_exception :
998
994
_LOGGER .debug (
999
995
f"Connection latency from '{ self .central .csid } ' to '{ self .id } ': ping={ latency_ping } ms, pong={ latency_pong } ms" ,
1000
996
)
@@ -1027,7 +1023,7 @@ async def run(self, tasks):
1027
1023
self .tasks = [asyncio .ensure_future (task ) for task in tasks ]
1028
1024
try :
1029
1025
await asyncio .gather (* self .tasks )
1030
- except asyncio . TimeoutError :
1026
+ except TimeoutError :
1031
1027
pass
1032
1028
except websockets .exceptions .WebSocketException as websocket_exception :
1033
1029
_LOGGER .debug (f"Connection closed to '{ self .id } ': { websocket_exception } " )
@@ -1258,9 +1254,9 @@ def on_meter_values(self, connector_id: int, meter_value: dict, **kwargs):
1258
1254
self ._metrics [measurand ].value = float (value )
1259
1255
self ._metrics [measurand ].unit = unit
1260
1256
if location is not None :
1261
- self ._metrics [measurand ].extra_attr [
1262
- om . location . value
1263
- ] = location
1257
+ self ._metrics [measurand ].extra_attr [om . location . value ] = (
1258
+ location
1259
+ )
1264
1260
if context is not None :
1265
1261
self ._metrics [measurand ].extra_attr [om .context .value ] = context
1266
1262
processed_keys .append (idx )
@@ -1295,7 +1291,7 @@ def on_meter_values(self, connector_id: int, meter_value: dict, **kwargs):
1295
1291
def on_boot_notification (self , ** kwargs ):
1296
1292
"""Handle a boot notification."""
1297
1293
resp = call_result .BootNotification (
1298
- current_time = datetime .now (tz = timezone . utc ).strftime ("%Y-%m-%dT%H:%M:%SZ" ),
1294
+ current_time = datetime .now (tz = UTC ).strftime ("%Y-%m-%dT%H:%M:%SZ" ),
1299
1295
interval = 3600 ,
1300
1296
status = RegistrationStatus .accepted .value ,
1301
1297
)
@@ -1333,12 +1329,12 @@ def on_status_notification(self, connector_id, error_code, status, **kwargs):
1333
1329
self ._metrics [cstat .status_connector .value ].value = status
1334
1330
self ._metrics [cstat .error_code_connector .value ].value = error_code
1335
1331
if connector_id >= 1 :
1336
- self ._metrics [cstat .status_connector .value ].extra_attr [
1337
- connector_id
1338
- ] = status
1339
- self ._metrics [cstat .error_code_connector .value ].extra_attr [
1340
- connector_id
1341
- ] = error_code
1332
+ self ._metrics [cstat .status_connector .value ].extra_attr [connector_id ] = (
1333
+ status
1334
+ )
1335
+ self ._metrics [cstat .error_code_connector .value ].extra_attr [connector_id ] = (
1336
+ error_code
1337
+ )
1342
1338
if (
1343
1339
status == ChargePointStatus .suspended_ev .value
1344
1340
or status == ChargePointStatus .suspended_evse .value
@@ -1489,14 +1485,14 @@ def on_stop_transaction(self, meter_stop, timestamp, transaction_id, **kwargs):
1489
1485
def on_data_transfer (self , vendor_id , ** kwargs ):
1490
1486
"""Handle a Data transfer request."""
1491
1487
_LOGGER .debug ("Data transfer received from %s: %s" , self .id , kwargs )
1492
- self ._metrics [cdet .data_transfer .value ].value = datetime .now (tz = timezone . utc )
1488
+ self ._metrics [cdet .data_transfer .value ].value = datetime .now (tz = UTC )
1493
1489
self ._metrics [cdet .data_transfer .value ].extra_attr = {vendor_id : kwargs }
1494
1490
return call_result .DataTransfer (status = DataTransferStatus .accepted .value )
1495
1491
1496
1492
@on (Action .heartbeat )
1497
1493
def on_heartbeat (self , ** kwargs ):
1498
1494
"""Handle a Heartbeat."""
1499
- now = datetime .now (tz = timezone . utc )
1495
+ now = datetime .now (tz = UTC )
1500
1496
self ._metrics [cstat .heartbeat .value ].value = now
1501
1497
self .hass .async_create_task (self .central .update (self .central .cpid ))
1502
1498
return call_result .Heartbeat (current_time = now .strftime ("%Y-%m-%dT%H:%M:%SZ" ))
0 commit comments