Skip to content

Commit

Permalink
Correctly convert timestamp received from api to datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
fsaris committed Apr 13, 2024
1 parent f67a030 commit d5ac878
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion custom_components/zonneplan_one/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import Optional, Any
from voluptuous.validators import Number
from datetime import datetime
from pytz import timezone


from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
Expand Down Expand Up @@ -282,7 +284,13 @@ def _value_from_coordinator(self):
# Converting value is only needed when value isn't None or 0
if value:
if self.entity_description.device_class == SensorDeviceClass.TIMESTAMP:
value = dt_util.parse_datetime(str(value))
if isinstance(value, str):
value = dt_util.parse_datetime(value)
else:
tz = timezone('Europe/Amsterdam')
value = datetime.fromtimestamp(value/1000000)
value.replace(tzinfo=tz)
value = value.astimezone(tz)

if self.entity_description.value_factor:
value = value * self.entity_description.value_factor
Expand Down

0 comments on commit d5ac878

Please sign in to comment.