Use time.monotonic instead of time.time where appropriate (#31780)

This commit is contained in:
Ville Skyttä authored and GitHub committed 2020-02-13 22:57:07 +01:00
1 parent fbbb29a6ec
commit 3018e8ff47
8 files changed
+21 -23

No files matched your search

+3 -3
View File
@@ -1,6 +1,6 @@
"""Support for Verisure locks."""
import logging
from time import sleep, time
from time import monotonic, sleep
from homeassistant.components.lock import LockDevice
from homeassistant.const import ATTR_CODE, STATE_LOCKED, STATE_UNLOCKED
@@ -71,7 +71,7 @@ class VerisureDoorlock(LockDevice):
def update(self):
"""Update lock status."""
if time() - self._change_timestamp < 10:
if monotonic() - self._change_timestamp < 10:
return
hub.update_overview()
status = hub.get_first(
@@ -131,4 +131,4 @@ class VerisureDoorlock(LockDevice):
transaction = hub.session.get_lock_state_transaction(transaction_id)
if transaction["result"] == "OK":
self._state = state
self._change_timestamp = time()
self._change_timestamp = monotonic()
+4 -4
View File
@@ -1,6 +1,6 @@
"""Support for Verisure Smartplugs."""
import logging
from time import time
from time import monotonic
from homeassistant.components.switch import SwitchDevice
@@ -44,7 +44,7 @@ class VerisureSmartplug(SwitchDevice):
@property
def is_on(self):
"""Return true if on."""
if time() - self._change_timestamp < 10:
if monotonic() - self._change_timestamp < 10:
return self._state
self._state = (
hub.get_first(
@@ -67,13 +67,13 @@ class VerisureSmartplug(SwitchDevice):
"""Set smartplug status on."""
hub.session.set_smartplug_state(self._device_label, True)
self._state = True
self._change_timestamp = time()
self._change_timestamp = monotonic()
def turn_off(self, **kwargs):
"""Set smartplug status off."""
hub.session.set_smartplug_state(self._device_label, False)
self._state = False
self._change_timestamp = time()
self._change_timestamp = monotonic()
# pylint: disable=no-self-use
def update(self):