# -*- coding: utf-8 -*-

from . import errors


class Singleton(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]


class Thermostat(metaclass=Singleton):
    MIN_TEMP = 0
    MAX_TEMP = 35

    def __init__(self):
        self._is_on = False
        self._current_temp = 0.0
        self._user_temp_range = (0.0, 0.0)

    def run(self):
        low, high = self.user_temp_range
        if self.current_temp < low:
            print('Thermostat is heating.')
        elif self.current_temp > high:
            print('Thermostat is cooling.')
        else:
            print('Thermostat is inactive.')

    @classmethod
    def validate_temp(cls, value):
        if value < cls.MIN_TEMP:
            raise errors.TemperatureValidationError('Temperature cannot be below {}'.format(cls.MIN_TEMP))
        if value > cls.MAX_TEMP:
            raise errors.TemperatureValidationError('Temperature cannot be above {}'.format(cls.MAX_TEMP))

    @property
    def is_on(self):
        return self._is_on

    @property
    def current_temp(self):
        return self._current_temp

    @current_temp.setter
    def current_temp(self, value):
        self.validate_temp(value)
        self._current_temp = value

    @property
    def user_temp_range(self):
        return self._user_temp_range

    @user_temp_range.setter
    def user_temp_range(self, temp_range):
        low, high = temp_range
        if high < low:
            raise errors.TemperatureValidationError('Invalid range.')
        self.validate_temp(low)
        self.validate_temp(high)
        self._user_temp_range = temp_range

# -*- coding: utf-8 -*-

from . import errors


class Singleton(type):
    _instances = {}

    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
        return cls._instances[cls]


class Thermostat(metaclass=Singleton):
    MIN_TEMPERATURE = 0
    MAX_TEMPERATURE = 35

    def __init__(self):
        self._is_on = False
        self._current_temperature = 0.0
        self._temperature_range = (0.0, 0.0)

    def run(self):
        low, high = self.temperature_range
        if self.current_temperature < low:
            print('Thermostat is heating.')
        elif self.current_temperature > high:
            print('Thermostat is cooling.')
        else:
            print('Thermostat is inactive.')

    @classmethod
    def validate_temperature(cls, value):
        if value < cls.MIN_TEMPERATURE:
            raise errors.TemperatureValidationError('Temperature cannot be below {}'.format(cls.MIN_TEMPERATURE))
        if value > cls.MAX_TEMPERATURE:
            raise errors.TemperatureValidationError('Temperature cannot be above {}'.format(cls.MAX_TEMPERATURE))

    @property
    def is_on(self):
        return self._is_on

    @property
    def current_temperature(self):
        return self._current_temperature

    @current_temperature.setter
    def current_temperature(self, value):
        self.validate_temperature(value)
        self._current_temperature = value

    @property
    def temperature_range(self):
        return self._temperature_range

    @temperature_range.setter
    def temperature_range(self, t_range):
        low, high = t_range
        if high < low:
            raise errors.TemperatureValidationError('Invalid range.')
        self.validate_temperature(low)
        self.validate_temperature(high)
        self._temperature_range = t_range

Rename variables to be more clear.