Skip to content

Commit e8d871d

Browse files
authored
Ignore first update if bad per input entity (pnbruckner#12)
Bump version to 2.1.0
1 parent 8793269 commit e8d871d

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

custom_components/composite/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from .const import CONF_TIME_AS, DOMAIN, TZ_DEVICE_LOCAL, TZ_DEVICE_UTC
1414

15-
__version__ = '2.0.0'
15+
__version__ = '2.1.0'
1616

1717
CONF_TZ_FINDER = 'tz_finder'
1818
DEFAULT_TZ_FINDER = 'timezonefinderL==4.0.2'

custom_components/composite/device_tracker.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
ATTR_LAST_ENTITY_ID = 'last_entity_id'
3636
ATTR_TIME_ZONE = 'time_zone'
3737

38+
INACTIVE = 'inactive'
39+
ACTIVE = 'active'
3840
WARNED = 'warned'
41+
STATUS = 'status'
3942
SEEN = 'seen'
4043
SOURCE_TYPE = ATTR_SOURCE_TYPE
4144
DATA = 'data'
@@ -79,7 +82,7 @@ def __init__(self, hass, config, see):
7982
self._entities = {}
8083
for entity_id in entities:
8184
self._entities[entity_id] = {
82-
WARNED: False,
85+
STATUS: INACTIVE,
8386
SEEN: None,
8487
SOURCE_TYPE: None,
8588
DATA: None}
@@ -91,40 +94,35 @@ def __init__(self, hass, config, see):
9194
self._req_movement = config[CONF_REQ_MOVEMENT]
9295
self._lock = threading.Lock()
9396
self._prev_seen = None
94-
self._init_complete = False
9597

9698
self._remove = track_state_change(
9799
hass, entities, self._update_info)
98100

99101
for entity_id in entities:
100102
self._update_info(entity_id, None, hass.states.get(entity_id))
101103

102-
def init_complete(event):
103-
self._init_complete = True
104-
105-
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, init_complete)
106-
107104
def _bad_entity(self, entity_id, message):
108105
msg = '{} {}'.format(entity_id, message)
109106
# Has there already been a warning for this entity?
110-
if self._entities[entity_id][WARNED]:
107+
if self._entities[entity_id][STATUS] == WARNED:
111108
_LOGGER.error(msg)
112109
self._remove()
113110
self._entities.pop(entity_id)
114111
# Are there still any entities to watch?
115112
if len(self._entities):
116113
self._remove = track_state_change(
117114
self._hass, self._entities.keys(), self._update_info)
118-
# Don't warn during init.
119-
elif self._init_complete:
115+
# Only warn if this is not the first state change for the entity.
116+
elif self._entities[entity_id][STATUS] == ACTIVE:
120117
_LOGGER.warning(msg)
121-
self._entities[entity_id][WARNED] = True
118+
self._entities[entity_id][STATUS] = WARNED
122119
else:
123120
_LOGGER.debug(msg)
121+
self._entities[entity_id][STATUS] = ACTIVE
124122

125123
def _good_entity(self, entity_id, seen, source_type, data):
126124
self._entities[entity_id].update({
127-
WARNED: False,
125+
STATUS: ACTIVE,
128126
SEEN: seen,
129127
SOURCE_TYPE: source_type,
130128
DATA: data})

0 commit comments

Comments
 (0)