33# Copyright 2020-2021, Stefan Valouch (svalouch)
44# SPDX-License-Identifier: GPL-3.0-only
55
6- import pytz
76import struct
87from datetime import datetime
98from typing import overload , Dict , Tuple , Union
1716
1817from .types import DataType , EventEntry
1918
20- timezone = pytz .timezone ('Europe/Berlin' )
21-
2219# pylint: disable=invalid-name
2320def CRC16 (data : Union [bytes , bytearray ]) -> int :
2421 '''
@@ -189,12 +186,12 @@ def _decode_timeseries(data: bytes) -> Tuple[datetime, Dict[datetime, int]]:
189186 '''
190187 Helper function to decode the timeseries type.
191188 '''
192- timestamp = timezone . localize ( datetime .utcfromtimestamp (struct .unpack ('>I' , data [0 :4 ])[0 ]) )
189+ timestamp = datetime .utcfromtimestamp (struct .unpack ('>I' , data [0 :4 ])[0 ])
193190 tsval : Dict [datetime , int ] = dict ()
194191 assert len (data ) % 4 == 0 , 'Data should be divisible by 4'
195192 assert int (len (data ) / 4 % 2 ) == 1 , 'Data should be an even number of 4-byte pairs plus the starting timestamp'
196193 for pair in range (0 , int (len (data ) / 4 - 1 ), 2 ):
197- pair_ts = timezone . localize ( datetime .utcfromtimestamp (struct .unpack ('>I' , data [4 + pair * 4 :4 + pair * 4 + 4 ])[0 ]) )
194+ pair_ts = datetime .utcfromtimestamp (struct .unpack ('>I' , data [4 + pair * 4 :4 + pair * 4 + 4 ])[0 ])
198195 pair_val = struct .unpack ('>f' , data [4 + pair * 4 + 4 :4 + pair * 4 + 4 + 4 ])[0 ]
199196 tsval [pair_ts ] = pair_val
200197 return timestamp , tsval
@@ -204,15 +201,15 @@ def _decode_event_table(data: bytes) -> Tuple[datetime, Dict[datetime, EventEntr
204201 '''
205202 Helper function to decode the event table type.
206203 '''
207- timestamp = timezone . localize ( datetime .utcfromtimestamp (struct .unpack ('>I' , data [0 :4 ])[0 ]) )
204+ timestamp = datetime .utcfromtimestamp (struct .unpack ('>I' , data [0 :4 ])[0 ])
208205 tabval : Dict [datetime , EventEntry ] = dict ()
209206 assert len (data ) % 4 == 0
210207 assert (len (data ) - 4 ) % 20 == 0
211208 for pair in range (0 , int (len (data ) / 4 - 1 ), 5 ):
212209 # this is most likely a single byte of information, but this is not sure yet
213210 # entry_type = bytes([struct.unpack('>I', data[4 + pair * 4:4 + pair * 4 + 4])[0]]).decode('ascii')
214211 entry_type = struct .unpack ('>I' , data [4 + pair * 4 :4 + pair * 4 + 4 ])[0 ]
215- timestamp = timezone . localize ( datetime .utcfromtimestamp (struct .unpack ('>I' , data [4 + pair * 4 + 4 :4 + pair * 4 + 8 ])[0 ]) )
212+ timestamp = datetime .utcfromtimestamp (struct .unpack ('>I' , data [4 + pair * 4 + 4 :4 + pair * 4 + 8 ])[0 ])
216213 element2 = struct .unpack ('>I' , data [4 + pair * 4 + 8 :4 + pair * 4 + 12 ])[0 ]
217214 element3 = struct .unpack ('>I' , data [4 + pair * 4 + 12 :4 + pair * 4 + 16 ])[0 ]
218215 element4 = struct .unpack ('>I' , data [4 + pair * 4 + 16 :4 + pair * 4 + 20 ])[0 ]
@@ -227,8 +224,8 @@ def _decode_event_table(data: bytes) -> Tuple[datetime, Dict[datetime, EventEntr
227224 # value_old=value_old, value_new=value_new)
228225 # the rest is assumed to be range-based events
229226 # else:
230- # timestamp_end = timezone.localize( datetime.utcfromtimestamp(
231- # struct.unpack('>I', data[4 + pair * 4 + 12:4 + pair * 4 + 16])[0]))
227+ # timestamp_end = datetime.utcfromtimestamp(
228+ # struct.unpack('>I', data[4 + pair * 4 + 12:4 + pair * 4 + 16])[0])
232229 # object_id = struct.unpack('>I', data[4 + pair * 4 + 16:4 + pair * 4 + 20])[0]
233230 # tabval[timestamp] = EventEntry(timestamp=timestamp, object_id=object_id, entry_type=entry_type,
234231 # timestamp_end=timestamp_end)
0 commit comments