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) )
async def test_dyson_set_temperature(mocked_login, mocked_devices, hass): """Test set climate temperature.""" await async_setup_component(hass, DYSON_DOMAIN, _get_config()) await hass.async_block_till_done() device = mocked_devices.return_value[0] device.temp_unit = TEMP_CELSIUS # Without correct target temp. await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: "climate.temp_name", ATTR_TARGET_TEMP_HIGH: 25.0, ATTR_TARGET_TEMP_LOW: 15.0, }, True, ) set_config = device.set_configuration assert set_config.call_count == 0 await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: "climate.temp_name", ATTR_TEMPERATURE: 23}, True, ) set_config = device.set_configuration assert set_config.call_args == call( heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(23) ) # Should clip the target temperature between 1 and 37 inclusive. await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: "climate.temp_name", ATTR_TEMPERATURE: 50}, True, ) set_config = device.set_configuration assert set_config.call_args == call( heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(37) ) await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: "climate.temp_name", ATTR_TEMPERATURE: -5}, True, ) set_config = device.set_configuration assert set_config.call_args == call( heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(1) )
async def test_purehotcool_set_temperature(devices, login, hass): """Test set temperature.""" device = devices.return_value[0] await async_setup_component(hass, DYSON_DOMAIN, _get_config()) await hass.async_block_till_done() state = hass.states.get("climate.living_room") attributes = state.attributes min_temp = attributes[ATTR_MIN_TEMP] max_temp = attributes[ATTR_MAX_TEMP] await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: "climate.bed_room", ATTR_TEMPERATURE: 23 }, True, ) device.set_heat_target.assert_not_called() await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: "climate.living_room", ATTR_TEMPERATURE: 23 }, True, ) assert device.set_heat_target.call_count == 1 device.set_heat_target.assert_called_with("2960") await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: "climate.living_room", ATTR_TEMPERATURE: min_temp - 1 }, True, ) assert device.set_heat_target.call_count == 2 device.set_heat_target.assert_called_with(HeatTarget.celsius(min_temp)) await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: "climate.living_room", ATTR_TEMPERATURE: max_temp + 1 }, True, ) assert device.set_heat_target.call_count == 3 device.set_heat_target.assert_called_with(HeatTarget.celsius(max_temp))
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.")
class DysonClimateEntity(DysonEntity, ClimateEntity): """Representation of a Dyson climate fan.""" @property def supported_features(self): """Return the list of supported features.""" return SUPPORT_FLAGS @property def temperature_unit(self): """Return the unit of measurement.""" return TEMP_CELSIUS @property def current_temperature(self): """Return the current temperature.""" if (self._device.environmental_state and self._device.environmental_state.temperature): temperature_kelvin = self._device.environmental_state.temperature return float(f"{temperature_kelvin - 273:.1f}") return None @property def target_temperature(self): """Return the target temperature.""" heat_target = int(self._device.state.heat_target) / 10 return int(heat_target - 273) @property def current_humidity(self): """Return the current humidity.""" # Humidity equaling to 0 means invalid value so we don't check for None here # https://github.com/home-assistant/core/pull/45172#discussion_r559069756 if (self._device.environmental_state and self._device.environmental_state.humidity): return self._device.environmental_state.humidity return None @property def min_temp(self): """Return the minimum temperature.""" return 1 @property def max_temp(self): """Return the maximum temperature.""" return 37 def set_temperature(self, **kwargs): """Set new target temperature.""" if (target_temp := kwargs.get(ATTR_TEMPERATURE)) is None: _LOGGER.error("Missing target temperature %s", kwargs) 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) self.set_heat_target(HeatTarget.celsius(target_temp))
def _get_device_cool(): """Return a device with state of cooling.""" device = mock.Mock(spec=DysonPureHotCoolLink) load_mock_device(device) 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 return device
def test_heat_target(self, mocked_connect, mocked_publish): connected = self._device.auto_connect() self.assertTrue(connected) self.assertEqual(mocked_connect.call_count, 1) self._device.set_heat_target(HeatTarget.celsius(24)) self.assertEqual(mocked_publish.call_count, 3) self._device.disconnect()
def _get_device_heat_on(): """Return a device with state of heating.""" device = mock.Mock(spec=DysonPureHotCoolLink) load_mock_device(device) device.serial = "YY-YYYYY-YY" device.state.heat_target = HeatTarget.celsius(23) device.state.heat_mode = HeatMode.HEAT_ON.value device.state.heat_state = HeatState.HEAT_STATE_ON.value device.environmental_state.temperature = 289 device.environmental_state.humidity = 53 return device
def set_temperature(self, **kwargs): """Set new target temperature.""" target_temp = kwargs.get(ATTR_TEMPERATURE) if target_temp is None: _LOGGER.error("Missing target temperature %s", kwargs) 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) self._device.set_heat_target(HeatTarget.celsius(target_temp))
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))
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
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) 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()
async def test_dyson_set_temperature_when_cooling_mode( mocked_login, mocked_devices, hass ): """Test set climate temperature when heating is off.""" await async_setup_component(hass, DYSON_DOMAIN, _get_config()) await hass.async_block_till_done() device = mocked_devices.return_value[0] device.temp_unit = TEMP_CELSIUS await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: "climate.temp_name", ATTR_TEMPERATURE: 23}, True, ) set_config = device.set_configuration assert set_config.call_args == call( heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(23) )