@@ -274,54 +274,50 @@ def _calc_state(self) -> None:
274274 entity_state
275275 and entity_state != STATE_UNKNOWN
276276 and entity_state != STATE_UNAVAILABLE
277- and self ._state_lower_limit is not None
278- and self ._state_upper_limit is not None
279277 ):
280278 if (
281- float ( entity_state ) < self ._state_lower_limit
282- or float ( entity_state ) > self ._state_upper_limit
279+ self ._state_lower_limit is not None
280+ and self ._state_upper_limit is not None
283281 ):
284- state_is_on = True
285- entities_on .append (entity_id )
286- LOGGER .debug (
287- "State %s is below lower limit %s and above upper limit %s for %s" ,
288- entity_state ,
289- self ._state_lower_limit ,
290- self ._state_upper_limit ,
291- entity_id ,
292- )
293- else :
294- if (
295- entity_state
296- and entity_state != STATE_UNKNOWN
297- and entity_state != STATE_UNAVAILABLE
298- and self ._state_lower_limit
299- and float (entity_state ) < self ._state_lower_limit
300- ):
301- state_is_on = True
302- entities_on .append (entity_id )
303- LOGGER .debug (
304- "State %s is below lower limit %s for %s" ,
305- entity_state ,
306- self ._state_lower_limit ,
307- entity_id ,
308- )
309-
310- if (
311- entity_state
312- and entity_state != STATE_UNKNOWN
313- and entity_state != STATE_UNAVAILABLE
314- and self ._state_upper_limit
315- and float (entity_state ) > self ._state_upper_limit
316- ):
317- state_is_on = True
318- entities_on .append (entity_id )
319- LOGGER .debug (
320- "State %s is above upper limit %s for %s" ,
321- entity_state ,
322- self ._state_upper_limit ,
323- entity_id ,
324- )
282+ if (
283+ float (entity_state ) < self ._state_lower_limit
284+ or float (entity_state ) > self ._state_upper_limit
285+ ):
286+ state_is_on = True
287+ entities_on .append (entity_id )
288+ LOGGER .debug (
289+ "State %s is below lower limit %s and above upper limit %s for %s" ,
290+ entity_state ,
291+ self ._state_lower_limit ,
292+ self ._state_upper_limit ,
293+ entity_id ,
294+ )
295+ else :
296+ if (
297+ self ._state_lower_limit
298+ and float (entity_state ) < self ._state_lower_limit
299+ ):
300+ state_is_on = True
301+ entities_on .append (entity_id )
302+ LOGGER .debug (
303+ "State %s is below lower limit %s for %s" ,
304+ entity_state ,
305+ self ._state_lower_limit ,
306+ entity_id ,
307+ )
308+
309+ if (
310+ self ._state_upper_limit
311+ and float (entity_state ) > self ._state_upper_limit
312+ ):
313+ state_is_on = True
314+ entities_on .append (entity_id )
315+ LOGGER .debug (
316+ "State %s is above upper limit %s for %s" ,
317+ entity_state ,
318+ self ._state_upper_limit ,
319+ entity_id ,
320+ )
325321
326322 except ValueError :
327323 LOGGER .error (
0 commit comments