import functools
import time


def dec_check_power(func):
    """
    Decorator to check for LCD power before doing function.
    """

    @functools.wraps(func)
    def wrapper(self, *args, **kwargs):
        tries = 0
        while not self.state and tries < self.POWER_TRIES:
            time.sleep(self.POWER_WAIT_TIME)
            tries += 1

        return func(self, *args, **kwargs)

    return wrapper