    def _cached_ratelimit(self, statevalue: Any, fast_falling=True, fast_rising=False, interval=None):
        """
        Uses the CONF_UPDATE_INTERVAL and other logic to return either the given statevalue
        or an older, cached value. Helps to reduce excess sensor churn without compromising latency.

        Mostly suitable for MEASUREMENTS, but should work with strings, too.
        If interval is specified the cache will use that (in seconds), otherwise the deafult is
        the CONF_UPPDATE_INTERVAL (typically suitable for fast-close slow-far sensors)
        """
        if interval is not None:
            self.bermuda_update_interval = interval

        nowstamp = MONOTONIC_TIME()
        if (
            (self.bermuda_last_stamp < nowstamp - self.bermuda_update_interval)  # Cache is stale
            or (self._device.ref_power_changed > nowstamp + 2)  # ref power changed in last 2sec
            or (self.bermuda_last_state is None)  # Nothing compares to you.
            or (statevalue is None)  # or you.
            or (fast_falling and statevalue < self.bermuda_last_state)  # (like Distance)
            or (fast_rising and statevalue > self.bermuda_last_state)  # (like RSSI)
        ):
            # Publish the new value and update cache
            self.bermuda_last_stamp = nowstamp
            self.bermuda_last_state = statevalue
            return statevalue
        else:
            # Send the cached value, don't update cache
            return self.bermuda_last_state
Uses the CONF_UPDATE_INTERVAL and other logic to return either the given statevalue
or an older, cached value. Helps to reduce excess sensor churn without compromising latency.

Mostly suitable for MEASUREMENTS, but should work with strings, too.
If interval is specified the cache will use that (in seconds), otherwise the deafult is
the CONF_UPPDATE_INTERVAL (typically suitable for fast-close slow-far sensors)
custom_components/bermuda/entity.py