Skip to content

Commit

Permalink
force date into default timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkywafer committed Jan 7, 2022
1 parent 312b8ba commit 116c457
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions custom_components/anniversaries/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from homeassistant.helpers.entity import Entity, generate_entity_id
from homeassistant.components.sensor import ENTITY_ID_FORMAT
from homeassistant.helpers import template as templater
import homeassistant.util.dt as dt_util

from homeassistant.const import (
CONF_NAME,
Expand Down Expand Up @@ -73,6 +74,7 @@ def __init__(self, hass, config):
self._template_sensor = True
else:
self._date, self._unknown_year = validate_date(config.get(CONF_DATE))
self._date = self._date.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE)
if self._show_half_anniversary:
self._half_date = self._date + relativedelta(months=+6)
self._icon_normal = config.get(CONF_ICON_NORMAL)
Expand Down Expand Up @@ -146,6 +148,7 @@ async def async_update(self):
try:
template_date = templater.Template(self._date_template, self.hass).async_render()
self._date, self._unknown_year = validate_date(template_date)
self._date = self._date.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE)
except:
self._state = "Invalid Template"
return
Expand All @@ -170,6 +173,7 @@ async def async_update(self):

if self._unknown_year:
self._date = datetime(nextDate.year, nextDate.month, nextDate.day)
self._date = self._date.replace(tzinfo=dt_util.DEFAULT_TIME_ZONE)

if daysRemaining == 0:
self._icon = self._icon_today
Expand Down

0 comments on commit 116c457

Please sign in to comment.