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:
committed by
Martin Hjelmare
parent
fccbaf3805
commit
80136f3591
@@ -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.switch import SwitchDevice
|
||||
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
|
||||
|
||||
@@ -72,14 +73,14 @@ class SirenSwitch(BaseRingSwitch):
|
||||
def __init__(self, device):
|
||||
"""Initialize the switch for a device with a siren."""
|
||||
super().__init__(device, "siren")
|
||||
self._no_updates_until = datetime.now()
|
||||
self._no_updates_until = dt_util.utcnow()
|
||||
self._siren_on = False
|
||||
|
||||
def _set_switch(self, new_state):
|
||||
"""Update switch state, and causes HASS to correctly update."""
|
||||
self._device.siren = new_state
|
||||
self._siren_on = new_state > 0
|
||||
self._no_updates_until = datetime.now() + SKIP_UPDATES_DELAY
|
||||
self._no_updates_until = dt_util.utcnow() + SKIP_UPDATES_DELAY
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
@@ -102,7 +103,7 @@ class SirenSwitch(BaseRingSwitch):
|
||||
|
||||
def update(self):
|
||||
"""Update state of the siren."""
|
||||
if self._no_updates_until > datetime.now():
|
||||
if self._no_updates_until > dt_util.utcnow():
|
||||
_LOGGER.debug("Skipping update...")
|
||||
return
|
||||
self._siren_on = self._device.siren > 0
|
||||
|
||||
Reference in New Issue
Block a user