Exemplo n.º 1
0
    def test_dyson_set_temperature(self):
        """Test set climate temperature."""
        device = _get_device_heat_on()
        device.temp_unit = TEMP_CELSIUS
        entity = dyson.DysonPureHotCoolLinkDevice(device)
        assert not entity.should_poll

        # Without target temp.
        kwargs = {}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_not_called()

        kwargs = {ATTR_TEMPERATURE: 23}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_called_with(heat_mode=HeatMode.HEAT_ON,
                                      heat_target=HeatTarget.celsius(23))

        # Should clip the target temperature between 1 and 37 inclusive.
        kwargs = {ATTR_TEMPERATURE: 50}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_called_with(heat_mode=HeatMode.HEAT_ON,
                                      heat_target=HeatTarget.celsius(37))

        kwargs = {ATTR_TEMPERATURE: -5}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_called_with(heat_mode=HeatMode.HEAT_ON,
                                      heat_target=HeatTarget.celsius(1))
Exemplo n.º 2
0
    def test_dyson_set_temperature(self):
        """Test set climate temperature."""
        device = _get_device_heat_on()
        device.temp_unit = TEMP_CELSIUS
        entity = dyson.DysonPureHotCoolLinkDevice(device)
        assert not entity.should_poll

        # Without target temp.
        kwargs = {}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_not_called()

        kwargs = {ATTR_TEMPERATURE: 23}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_called_with(
            heat_mode=HeatMode.HEAT_ON,
            heat_target=HeatTarget.celsius(23))

        # Should clip the target temperature between 1 and 37 inclusive.
        kwargs = {ATTR_TEMPERATURE: 50}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_called_with(
            heat_mode=HeatMode.HEAT_ON,
            heat_target=HeatTarget.celsius(37))

        kwargs = {ATTR_TEMPERATURE: -5}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_called_with(
            heat_mode=HeatMode.HEAT_ON,
            heat_target=HeatTarget.celsius(1))
    def test_heat_target_celsius(self):
        self.assertEqual(HeatTarget.celsius(25), "2980")

        with self.assertRaises(DysonInvalidTargetTemperatureException) as ex:
            HeatTarget.celsius(38)
        invalid_target_exception = ex.exception
        self.assertEqual(invalid_target_exception.temperature_unit,
                         DysonInvalidTargetTemperatureException.CELSIUS)
        self.assertEqual(invalid_target_exception.current_value, 38)
        self.assertEqual(invalid_target_exception.__repr__(),
                         "38 is not a valid temperature target. "
                         "It must be between 1 to 37 inclusive.")
Exemplo n.º 4
0
def _get_device_cool():
    """Return a device with state of cooling."""
    device = mock.Mock(spec=DysonPureHotCoolLink)
    device.name = "Device_name"
    device.state.tilt = TiltState.TILT_FALSE.value
    device.state.focus_mode = FocusMode.FOCUS_OFF.value
    device.state.heat_target = HeatTarget.celsius(12)
    device.state.heat_mode = HeatMode.HEAT_OFF.value
    device.state.heat_state = HeatState.HEAT_STATE_OFF.value
    device.environmental_state.temperature = 288
    device.environmental_state.humidity = 53
    return device
Exemplo n.º 5
0
    def test_dyson_set_temperature_when_cooling_mode(self):
        """Test set climate temperature when heating is off."""
        device = _get_device_cool()
        device.temp_unit = TEMP_CELSIUS
        entity = dyson.DysonPureHotCoolLinkDevice(device)
        entity.schedule_update_ha_state = mock.Mock()

        kwargs = {ATTR_TEMPERATURE: 23}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_called_with(heat_mode=HeatMode.HEAT_ON,
                                      heat_target=HeatTarget.celsius(23))
Exemplo n.º 6
0
def _get_device_cool():
    """Return a device with state of cooling."""
    device = mock.Mock(spec=DysonPureHotCoolLink)
    device.name = "Device_name"
    device.state.tilt = TiltState.TILT_FALSE.value
    device.state.focus_mode = FocusMode.FOCUS_OFF.value
    device.state.heat_target = HeatTarget.celsius(12)
    device.state.heat_mode = HeatMode.HEAT_OFF.value
    device.state.heat_state = HeatState.HEAT_STATE_OFF.value
    device.environmental_state.temperature = 288
    device.environmental_state.humidity = 53
    return device
Exemplo n.º 7
0
    def test_dyson_set_temperature_when_cooling_mode(self):
        """Test set climate temperature when heating is off."""
        device = _get_device_cool()
        device.temp_unit = TEMP_CELSIUS
        entity = dyson.DysonPureHotCoolLinkDevice(device)
        entity.schedule_update_ha_state = mock.Mock()

        kwargs = {ATTR_TEMPERATURE: 23}
        entity.set_temperature(**kwargs)
        set_config = device.set_configuration
        set_config.assert_called_with(
            heat_mode=HeatMode.HEAT_ON,
            heat_target=HeatTarget.celsius(23))
Exemplo n.º 8
0
 def set_temperature(self, **kwargs):
     """Set new target temperature."""
     target_temp = kwargs.get(ATTR_TEMPERATURE)
     if target_temp is None:
         return
     target_temp = int(target_temp)
     _LOGGER.debug("Set %s temperature %s", self.name, target_temp)
     # Limit the target temperature into acceptable range.
     target_temp = min(self.max_temp, target_temp)
     target_temp = max(self.min_temp, target_temp)
     from libpurecoollink.const import HeatTarget, HeatMode
     self._device.set_configuration(
         heat_target=HeatTarget.celsius(target_temp),
         heat_mode=HeatMode.HEAT_ON)
Exemplo n.º 9
0
 def set_temperature(self, **kwargs):
     """Set new target temperature."""
     target_temp = kwargs.get(ATTR_TEMPERATURE)
     if target_temp is None:
         return
     target_temp = int(target_temp)
     _LOGGER.debug("Set %s temperature %s", self.name, target_temp)
     # Limit the target temperature into acceptable range.
     target_temp = min(self.max_temp, target_temp)
     target_temp = max(self.min_temp, target_temp)
     from libpurecoollink.const import HeatTarget, HeatMode
     self._device.set_configuration(
         heat_target=HeatTarget.celsius(target_temp),
         heat_mode=HeatMode.HEAT_ON)
 def test_set_configuration_hot(self, mocked_connect, mocked_publish):
     device = DysonPureHotCoolLink({
         "Active":
         True,
         "Serial":
         "device-id-1",
         "Name":
         "device-1",
         "ScaleUnit":
         "SU01",
         "Version":
         "21.03.08",
         "LocalCredentials":
         "1/aJ5t52WvAfn+z+fjDuef86kQDQPefbQ6/70ZGysII1K"
         "e1i0ZHakFH84DZuxsSQ4KTT2vbCm7uYeTORULKLKQ==",
         "AutoUpdate":
         True,
         "NewVersionAvailable":
         False,
         "ProductType":
         Hot
     })
     network_device = NetworkDevice('device-1', 'host', 1111)
     device._add_network_device(network_device)
     device._current_state = DysonPureCoolState(
         open("tests/data/state_hot.json", "r").read())
     device.connection_callback(True)
     device.state_data_available()
     device.sensor_data_available()
     connected = device.auto_connect()
     self.assertTrue(connected)
     self.assertEqual(mocked_connect.call_count, 1)
     device.set_configuration(fan_mode=FanMode.FAN,
                              oscillation=Oscillation.OSCILLATION_ON,
                              fan_speed=FanSpeed.FAN_SPEED_3,
                              night_mode=NightMode.NIGHT_MODE_OFF,
                              quality_target=QualityTarget.QUALITY_NORMAL,
                              standby_monitoring=SM.STANDBY_MONITORING_ON,
                              heat_mode=HeatMode.HEAT_ON,
                              focus_mode=FocusMode.FOCUS_ON,
                              heat_target=HeatTarget.celsius(25))
     self.assertEqual(mocked_publish.call_count, 3)
     self.assertEqual(
         device.__repr__(),
         "DysonPureHotCoolLink(serial=device-id-1,active=True,"
         "name=device-1,version=21.03.08,auto_update=True,"
         "new_version_available=False,product_type=455,"
         "network_device=NetworkDevice(name=device-1,"
         "address=host,port=1111))")
     device.disconnect()
Exemplo n.º 11
0
        print("Turning Dyson Off")
        devices[0].set_configuration(fan_mode=FanMode.OFF)
    elif ("oscillate" in command):
        if (command[-1] == "n"):
            devices[0].set_configuration(
                oscillation=Oscillation.OSCILLATION_ON)
        elif (command[-1] == "f"):
            devices[0].set_configuration(
                oscillation=Oscillation.OSCILLATION_OFF)
    elif ("night" in command):
        if (command[-1] == "n"):
            devices[0].set_configuration(night_mode=NightMode.NIGHT_MODE_ON)
        elif (command[-1] == "f"):
            devices[0].set_configuration(night_mode=NightMode.NIGHT_MODE_OFF)
    else:
        # At this point, we're dealing with parameters with numbers (speed, heat and sleep)
        if ("speed" in command):
            parameter = command.split()[-1]
            print("Setting Speed to " + parameter)
            devices[0].set_configuration(fan_speed=FanSpeed["FAN_SPEED_" +
                                                            parameter])
        elif ("heat" in command):
            parameter = command.split()[-1]
            print("Setting Heat to " + parameter + "C")
            devices[0].set_configuration(
                heat_target=HeatTarget.celsius(parameter))
        elif ("sleep" in command):
            parameter = int(command.split()[-1])
            print("Sleeping in " + parameter + " minutes")
            devices[0].set_configuration(sleep_timer=parameter)