    def _check_key(self, key):
        """
        Check if the given key has been used recently.

        Returns -1 if the message should be suppressed,
        but if the message should be logged it returns the number of attempted uses
        since last time it was sent - which might be zero.
        """
        if key in self._keycache:
            # key exists, check timestamps
            cache = self._keycache[key]
            if cache["stamp"] < MONOTONIC_TIME() - self._interval:
                # It's time to emit the message
                count = cache["count"]
                cache["count"] = 0
                cache["stamp"] = MONOTONIC_TIME()
                return count
            # We sent this message recently, don't spam
            cache["count"] += 1
            return -1
        else:
            # Key is completely new, store the new stamp and let it through
            self._keycache[key] = {
                "stamp": MONOTONIC_TIME(),
                "count": 0,
            }
            return 0
Check if the given key has been used recently.

Returns -1 if the message should be suppressed,
but if the message should be logged it returns the number of attempted uses
since last time it was sent - which might be zero.
custom_components/bermuda/log_spam_less.py