Skip to content

Commit

Permalink
fix: other vmoto soco timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
drakhart committed May 3, 2023
1 parent 8a14d8a commit c365138
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 15 deletions.
2 changes: 0 additions & 2 deletions custom_components/super_soco_custom/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@
POWER_OFF_DISTANCE_THRESHOLD_METERS = 16
POWER_ON_UPDATE_SECONDS = 5
SECONDS_IN_A_MINUTE = 60
SECONDS_IN_AN_HOUR = 3600
SIGNAL_MAX_STRENGTH = 4 # It goes from 0 to 4
SUPER_SOCO = "super_soco"
SWITCH_REFRESH_SLEEP_SECONDS = 10
UTC_TO_SHANGHAI_HOURS_DIFFERENCE = 8
VMOTO_SOCO = "vmoto_soco"

# Directions of travel
Expand Down
4 changes: 0 additions & 4 deletions custom_components/super_soco_custom/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ async def _async_update_data(self):
DATA_ECU_BATTERY: device_data[DATA_ECU_BATTERY],
DATA_LAST_GPS_TIME: parse_timestamp(
device_data[DATA_LAST_GPS_TIME],
False,
),
DATA_MODEL_NAME: self._user_data[DATA_USER_BIND_DEVICE][
DATA_MODEL_NAME
Expand Down Expand Up @@ -453,11 +452,9 @@ async def _get_last_trip_data(self) -> dict:
),
DATA_LAST_TRIP_BEGIN_TIME: parse_timestamp(
trip[DATA_LAST_TRIP_BEGIN_TIME],
True,
),
DATA_LAST_TRIP_END_TIME: parse_timestamp(
trip[DATA_LAST_TRIP_END_TIME],
True,
),
DATA_LAST_TRIP_RIDE_DISTANCE: round(
trip[DATA_LAST_TRIP_MILEAGE], DISTANCE_ROUNDING_DECIMALS
Expand Down Expand Up @@ -548,7 +545,6 @@ async def _get_last_warning_data(self) -> dict:
data = {
DATA_LAST_WARNING_TIME: parse_timestamp(
warning[DATA_CREATE_TIME],
False,
),
}
else:
Expand Down
7 changes: 1 addition & 6 deletions custom_components/super_soco_custom/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
DEFAULT_FLOAT,
METERS_IN_EARTH_RADIUS,
MILLISECONDS_IN_A_SECOND,
SECONDS_IN_AN_HOUR,
UTC_TO_SHANGHAI_HOURS_DIFFERENCE,
)


Expand Down Expand Up @@ -77,10 +75,7 @@ def parse_date(date_string: str) -> datetime:
return datetime.strptime(clean_string, "%d/%m/%Y %H:%M%z")


def parse_timestamp(timestampMilliseconds: int, fix_timezone: bool = False) -> datetime:
def parse_timestamp(timestampMilliseconds: int) -> datetime:
timestamp = timestampMilliseconds / MILLISECONDS_IN_A_SECOND

if fix_timezone:
timestamp += UTC_TO_SHANGHAI_HOURS_DIFFERENCE * SECONDS_IN_AN_HOUR

return datetime.fromtimestamp(timestamp, tz=pytz.UTC)
3 changes: 0 additions & 3 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ def test_calculate_course():

def test_parse_timestamp():
"""Test parse_timestamp."""
assert parse_timestamp(1681423654000, True) == datetime.datetime(
2023, 4, 14, 6, 7, 34, tzinfo=pytz.UTC
)
assert parse_timestamp(1681423654000) == datetime.datetime(
2023, 4, 13, 22, 7, 34, tzinfo=pytz.UTC
)

0 comments on commit c365138

Please sign in to comment.