<commit_before>"""
homeassistant.components.automation.state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Offers state listening automation rules.
"""
import logging

from homeassistant.helpers.event import track_state_change
from homeassistant.const import MATCH_ALL


CONF_ENTITY_ID = "state_entity_id"
CONF_BELOW = "state_below"
CONF_ABOVE = "state_above"


def register(hass, config, action):
    """ Listen for state changes based on `config`. """
    entity_id = config.get(CONF_ENTITY_ID)

    if entity_id is None:
        logging.getLogger(__name__).error(
            "Missing configuration key %s", CONF_ENTITY_ID)
        return False

    below = config.get(CONF_BELOW)
    above = config.get(CONF_ABOVE)

    if below is None and above is None:
        logging.getLogger(__name__).error(
            "Missing configuration key %s or %s", CONF_BELOW, CONF_ABOVE)

    def numeric_in_range(value, range_start, range_end):
        """ Checks if value is inside the range
        :param value:
        :param range_start:
        :param range_end:
        :return:
        """
        value = float(value)

        if range_start is not None and range_end is not None:
            return float(range_start) < value < float(range_end)
        elif range_end is not None:
            return value < float(range_end)
        else:<commit_msg>Added better handling if we did not get a value for the numeric check<commit_after>"""
homeassistant.components.automation.state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Offers state listening automation rules.
"""
import logging

from homeassistant.helpers.event import track_state_change


CONF_ENTITY_ID = "state_entity_id"
CONF_BELOW = "state_below"
CONF_ABOVE = "state_above"

_LOGGER = logging.getLogger(__name__)

def register(hass, config, action):
    """ Listen for state changes based on `config`. """
    entity_id = config.get(CONF_ENTITY_ID)

    if entity_id is None:
        _LOGGER.error("Missing configuration key %s", CONF_ENTITY_ID)
        return False

    below = config.get(CONF_BELOW)
    above = config.get(CONF_ABOVE)

    if below is None and above is None:
        _LOGGER.error("Missing configuration key %s or %s", CONF_BELOW, CONF_ABOVE)

    def numeric_in_range(value, range_start, range_end):
        """ Checks if value is inside the range
        :param value:
        :param range_start:
        :param range_end:
        :return:
        """

        if value is None:
            _LOGGER.warn("Missing value in numeric check")
            return False

        value = float(value)

        if range_start is not None and range_end is not None:
            return float(range_start) < value < float(range_end)
        elif range_end is not None:
            return value < float(range_end)
        else:
{'fraction_non_alphanumeric': 0.1085243553008596, 'fraction_numerical': 0.0, 'mean_word_length': 3.0071736011477763, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '8291', 'n_tokens_mistral': 841, 'n_tokens_neox': 819, 'n_words': 243}