1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Change datetime.now() to dt_util.now() (#26582)

* Change datetime.now() to dt_util.now() in cases where the functionality should stay the same

These changes should not affect the functionality, rather cleanup our codebase.

In general we would like integrations to not to use datetime.now() unless there's a very good
reason for it, rather use our own dt_util.now() which makes the code aware of our current time
zone.

* Use datetime.utcnow() for season sensor to get offset-naive utc time

* Revert "Use datetime.utcnow() for season sensor to get offset-naive utc time"

This reverts commit 5f36463d9c7d52f8e11ffcec7e57dfbc7b21bdd1.

* BOM sensor last_updated should be UTC as well

* Run black

* Remove unused last_partition_update variable
This commit is contained in:
Tsvi Mostovicz
2019-09-19 09:39:09 +03:00
committed by Martin Hjelmare
parent fccbaf3805
commit 80136f3591
16 changed files with 46 additions and 41 deletions

View File

@@ -1,9 +1,10 @@
"""This component provides HA switch support for Ring Door Bell/Chimes."""
import logging
from datetime import datetime, timedelta
from datetime import timedelta
from homeassistant.components.light import Light
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.core import callback
import homeassistant.util.dt as dt_util
from . import DATA_RING_STICKUP_CAMS, SIGNAL_UPDATE_RING
@@ -41,7 +42,7 @@ class RingLight(Light):
self._device = device
self._unique_id = self._device.id
self._light_on = False
self._no_updates_until = datetime.now()
self._no_updates_until = dt_util.utcnow()
async def async_added_to_hass(self):
"""Register callbacks."""
@@ -77,7 +78,7 @@ class RingLight(Light):
"""Update light state, and causes HASS to correctly update."""
self._device.lights = new_state
self._light_on = new_state == ON_STATE
self._no_updates_until = datetime.now() + SKIP_UPDATES_DELAY
self._no_updates_until = dt_util.utcnow() + SKIP_UPDATES_DELAY
self.async_schedule_update_ha_state(True)
def turn_on(self, **kwargs):
@@ -90,7 +91,7 @@ class RingLight(Light):
def update(self):
"""Update current state of the light."""
if self._no_updates_until > datetime.now():
if self._no_updates_until > dt_util.utcnow():
_LOGGER.debug("Skipping update...")
return