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,5 +1,4 @@
"""Support for monitoring the local system."""
from datetime import datetime
import logging
import os
import socket
@ -193,7 +192,7 @@ class SystemMonitorSensor(Entity):
counters = psutil.net_io_counters(pernic=True)
if self.argument in counters:
counter = counters[self.argument][IO_COUNTER[self.type]]
now = datetime.now()
now = dt_util.utcnow()
if self._last_value and self._last_value < counter:
self._state = round(
(counter - self._last_value)