3535ATTR_LAST_ENTITY_ID = 'last_entity_id'
3636ATTR_TIME_ZONE = 'time_zone'
3737
38+ INACTIVE = 'inactive'
39+ ACTIVE = 'active'
3840WARNED = 'warned'
41+ STATUS = 'status'
3942SEEN = 'seen'
4043SOURCE_TYPE = ATTR_SOURCE_TYPE
4144DATA = '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