Added better handling if we did not get a value for the numeric check
parent
4eba1250e9
commit
8e89308a15
|
@ -7,29 +7,27 @@ Offers state listening automation rules.
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.helpers.event import track_state_change
|
from homeassistant.helpers.event import track_state_change
|
||||||
from homeassistant.const import MATCH_ALL
|
|
||||||
|
|
||||||
|
|
||||||
CONF_ENTITY_ID = "state_entity_id"
|
CONF_ENTITY_ID = "state_entity_id"
|
||||||
CONF_BELOW = "state_below"
|
CONF_BELOW = "state_below"
|
||||||
CONF_ABOVE = "state_above"
|
CONF_ABOVE = "state_above"
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
def register(hass, config, action):
|
def register(hass, config, action):
|
||||||
""" Listen for state changes based on `config`. """
|
""" Listen for state changes based on `config`. """
|
||||||
entity_id = config.get(CONF_ENTITY_ID)
|
entity_id = config.get(CONF_ENTITY_ID)
|
||||||
|
|
||||||
if entity_id is None:
|
if entity_id is None:
|
||||||
logging.getLogger(__name__).error(
|
_LOGGER.error("Missing configuration key %s", CONF_ENTITY_ID)
|
||||||
"Missing configuration key %s", CONF_ENTITY_ID)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
below = config.get(CONF_BELOW)
|
below = config.get(CONF_BELOW)
|
||||||
above = config.get(CONF_ABOVE)
|
above = config.get(CONF_ABOVE)
|
||||||
|
|
||||||
if below is None and above is None:
|
if below is None and above is None:
|
||||||
logging.getLogger(__name__).error(
|
_LOGGER.error("Missing configuration key %s or %s", CONF_BELOW, CONF_ABOVE)
|
||||||
"Missing configuration key %s or %s", CONF_BELOW, CONF_ABOVE)
|
|
||||||
|
|
||||||
def numeric_in_range(value, range_start, range_end):
|
def numeric_in_range(value, range_start, range_end):
|
||||||
""" Checks if value is inside the range
|
""" Checks if value is inside the range
|
||||||
|
@ -38,6 +36,11 @@ def register(hass, config, action):
|
||||||
:param range_end:
|
:param range_end:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
_LOGGER.warn("Missing value in numeric check")
|
||||||
|
return False
|
||||||
|
|
||||||
value = float(value)
|
value = float(value)
|
||||||
|
|
||||||
if range_start is not None and range_end is not None:
|
if range_start is not None and range_end is not None:
|
||||||
|
|
Loading…
Reference in New Issue