def test_get_mode_set_mode():
    temp_controller = TemperatureController(20, 1, Mode.OFF)
    assert temp_controller.get_mode() == Mode.OFF
    temp_controller.set_mode(Mode.HEATER)
    assert temp_controller.get_mode() == Mode.HEATER
    temp_controller.set_mode(Mode.COOLER)
    assert temp_controller.get_mode() == Mode.COOLER
class Thermostat():
    def __init__(self, update_server):
        self.temperature_controller = TemperatureController(set_temperature=20,
                                                            mode=Mode.COOLER)
        self.sensor_controller = SensorController()
        self.mqtt_controller = DataController()
        self.user_interface = UserInterface()
        self.unit_controller = UnitController()
        self.update_server = update_server
        self.command_subscriber = CommandSubscriber("192.168.3.2",
                                                    self.handle_command)
        self.current_display_data = None

    def startup(self):
        pass

    def run(self):
        self.command_subscriber.subscribe()
        while True:
            current_temperature = self.sensor_controller.get_temperature()
            current_state = self.temperature_controller.handle_new_reading(
                current_temperature)
            current_humidity = self.sensor_controller.get_humidity()
            converted_data = self.unit_controller.convert({
                "temperature":
                current_temperature,
                "set_temperature":
                self.temperature_controller.get_set_temperature(),
                "humidity":
                current_humidity,
                "mode":
                self.temperature_controller.get_mode(),
                "state":
                current_state
            })
            self.mqtt_controller.publish_data(converted_data)
            self.update_server(converted_data)
            self.command_subscriber.command_loop()
            self.current_display_data = converted_data
            time.sleep(1)

    def handle_command(self, command):
        command_type = command.get('command')
        if command_type == "SET_TEMPERATURE":
            self.temperature_controller.update_set_temperature(
                self.unit_controller.convert_incomming(
                    command['data']['temperature']))
        elif command_type == "SET_MODE":
            self.temperature_controller.set_mode(Mode(command['data']['mode']))

    def update_set_temperature(self, set_temperature):
        converted_temp = UnitController.convert_f_to_c(set_temperature)
        self.temperature_controller.update_set_temperature(converted_temp)
        self.update_server({
            "temperature":
            self.current_display_data.get('temperature'),
            "set_temperature":
            set_temperature,
            "humidity":
            self.current_display_data.get('humidity'),
            "mode":
            self.temperature_controller.get_mode(),
            "state":
            self.current_display_data.get('state')
        })

    def shutdown(self):
        print('Shutting Down')
        self.temperature_controller.shutdown()