Skip to content

Commit

Permalink
Merge pull request #22 from ruuvi-friends/general-cleanup
Browse files Browse the repository at this point in the history
General cleanup
  • Loading branch information
sergioisidoro authored Mar 27, 2021
2 parents 99ae9f9 + 3e187d6 commit e390532
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions custom_components/ruuvi/sensor.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import datetime
import logging
import time
import collections
from typing import Optional

import voluptuous as vol
import homeassistant.helpers.config_validation as cv

from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import TEMP_CELSIUS, PERCENTAGE, PRESSURE_HPA
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.event import call_later
from homeassistant.helpers.entity import Entity
from homeassistant.util import dt
import homeassistant.helpers.config_validation as cv

from homeassistant.const import (
CONF_FORCE_UPDATE, CONF_MONITORED_CONDITIONS,
CONF_NAME, CONF_MAC, CONF_SENSORS, STATE_UNKNOWN
CONF_MONITORED_CONDITIONS,
CONF_NAME, CONF_MAC, CONF_SENSORS, STATE_UNKNOWN,
TEMP_CELSIUS, PERCENTAGE, PRESSURE_HPA
)

from simple_ruuvitag.ruuvi import RuuviTagClient
Expand Down Expand Up @@ -158,11 +157,11 @@ def set_state(self, state):
_LOGGER.debug(f"Updated {self.update_time} {self.name}: {self.state}")

self.schedule_update_ha_state()
call_later(self.hass, EXPIRE_AFTER, self.expire_state_if_old)

def expire_state_if_old(self, delay):
state_age_seconds = (dt.utcnow() - self.update_time) / datetime.timedelta(seconds=1)
if state_age_seconds >= EXPIRE_AFTER:
_LOGGER.debug(f"{self.name}: Expire state due to age")
self._state = STATE_UNKNOWN
self.schedule_update_ha_state()
# call_later(self.hass, EXPIRE_AFTER, self.expire_state_if_old)

# def expire_state_if_old(self, delay):
# state_age_seconds = (dt.utcnow() - self.update_time) / datetime.timedelta(seconds=1)
# if state_age_seconds >= EXPIRE_AFTER:
# _LOGGER.debug(f"{self.name}: Expire state due to age")
# self._state = STATE_UNKNOWN
# self.schedule_update_ha_state()

0 comments on commit e390532

Please sign in to comment.