async def async_set_percentage(self, percentage: int) -> None: """Set the speed percentage of the fan.""" if percentage == 0: await self.async_turn_off() return on_level = math.ceil(percentage_to_ranged_value(SPEED_RANGE, percentage)) await self._insteon_device.async_on(group=2, on_level=on_level)
async def async_set_percentage(self, percentage: int) -> None: """Set the percentage of the fan. This method is a coroutine. """ percentage_payload = math.ceil( percentage_to_ranged_value(self._speed_range, percentage)) mqtt_payload = self._command_templates[ATTR_PERCENTAGE]( percentage_payload) # Legacy are deprecated in the schema, support will be removed after a quarter (2021.7) if self._feature_legacy_speeds: if percentage: await self.async_set_speed( percentage_to_ordered_list_item( self._legacy_speeds_list_no_off, percentage, )) elif SPEED_OFF in self._legacy_speeds_list: await self.async_set_speed(SPEED_OFF) if self._feature_percentage: mqtt.async_publish( self.opp, self._topic[CONF_PERCENTAGE_COMMAND_TOPIC], mqtt_payload, self._config[CONF_QOS], self._config[CONF_RETAIN], ) if self._optimistic_percentage: self._percentage = percentage self.async_write_op_state()
def set_percentage(self, percentage: int) -> None: """Set the speed percentage of the fan.""" if percentage == 0: self.turn_off() return dyson_speed = INT_VALUE_TO_DYSON_SPEED[math.ceil( percentage_to_ranged_value(SPEED_RANGE, percentage))] self.set_dyson_speed(dyson_speed)
async def async_set_percentage(self, percentage: int) -> None: """Set node to speed percentage for the ISY994 fan device.""" if percentage == 0: await self._node.turn_off() return isy_speed = math.ceil( percentage_to_ranged_value(SPEED_RANGE, percentage)) await self._node.turn_on(val=isy_speed)
def set_percentage(self, percentage): """Set the speed percentage of the fan.""" if percentage is None: # Value 255 tells device to return to previous value zwave_speed = 255 elif percentage == 0: zwave_speed = 0 else: zwave_speed = math.ceil( percentage_to_ranged_value(SPEED_RANGE, percentage)) self.node.set_dimmer(self.values.primary.value_id, zwave_speed)
async def async_set_percentage(self, percentage: int) -> None: """Set the speed percentage of the fan.""" if percentage is None: await self._device.switch_on(set_status=True) elif percentage == 0: await self._device.switch_off(set_status=True) else: value = math.ceil( percentage_to_ranged_value(SPEED_RANGE, percentage)) await self._device.set_fan_speed(value, set_status=True) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates self.async_write_op_state()
async def async_set_percentage(self, percentage: int | None) -> None: """Set the speed percentage of the fan.""" target_value = self.get_zwave_value("targetValue") if percentage is None: # Value 255 tells device to return to previous value zwave_speed = 255 elif percentage == 0: zwave_speed = 0 else: zwave_speed = math.ceil( percentage_to_ranged_value(SPEED_RANGE, percentage)) await self.info.node.async_set_value(target_value, zwave_speed)
def set_percentage(self, percentage: int) -> None: """Set the fan_mode of the Humidifier.""" if percentage is None: named_speed = self._last_fan_on_mode elif percentage == 0: named_speed = WEMO_FAN_OFF else: named_speed = math.ceil( percentage_to_ranged_value(SPEED_RANGE, percentage)) with self._wemo_exception_handler("set speed"): self.wemo.set_state(named_speed) self.schedule_update_op_state()
def set_percentage(self, percentage): """Set the speed of the device.""" if percentage == 0: self.smartfan.turn_off() return if not self.smartfan.is_on: self.smartfan.turn_on() self.smartfan.manual_mode() self.smartfan.change_fan_speed( math.ceil(percentage_to_ranged_value(SPEED_RANGE, percentage)) ) self.schedule_update_op_state()
def set_percentage(self, percentage: int) -> None: """Set the speed percentage of the fan.""" _LOGGER.debug("Set the fan percentage to %s", percentage) if percentage == 0: self.turn_off() return fan_speed = math.ceil( percentage_to_ranged_value(SPEED_RANGE, percentage)) if not self._smarty.set_fan_speed(fan_speed): raise OpenPeerPowerError( f"Failed to set the fan speed percentage to {percentage}") self._smarty_fan_speed = fan_speed self.schedule_update_op_state()
async def test_percentage_to_ranged_value_small(): """Test a small range of low and high values convert a percentage to a single value.""" range = (1, 6) assert math.ceil(percentage_to_ranged_value(range, 16)) == 1 assert math.ceil(percentage_to_ranged_value(range, 33)) == 2 assert math.ceil(percentage_to_ranged_value(range, 50)) == 3 assert math.ceil(percentage_to_ranged_value(range, 66)) == 4 assert math.ceil(percentage_to_ranged_value(range, 83)) == 5 assert math.ceil(percentage_to_ranged_value(range, 100)) == 6
def set_percentage(self, percentage: int): """Set fan speed percentage.""" _LOGGER.debug("Changing fan speed percentage to %s", percentage) if percentage is None: cmd = CMD_FAN_MODE_LOW elif percentage == 0: cmd = CMD_FAN_MODE_AWAY else: speed = math.ceil(percentage_to_ranged_value(SPEED_RANGE, percentage)) cmd = CMD_MAPPING[speed] self._ccb.comfoconnect.cmd_rmi_request(cmd) # Update current mode self.schedule_update_op_state()
async def test_percentage_to_ranged_value_large(): """Test a large range of low and high values convert a percentage to a single value.""" range = (1, 255) assert percentage_to_ranged_value(range, 100) == 255 assert percentage_to_ranged_value(range, 50) == 127.5 assert percentage_to_ranged_value(range, 4) == 10.2 assert math.ceil(percentage_to_ranged_value(range, 100)) == 255 assert math.ceil(percentage_to_ranged_value(range, 50)) == 128 assert math.ceil(percentage_to_ranged_value(range, 4)) == 11
async def async_set_percentage(self, percentage: int) -> None: """Set the desired speed for the fan.""" _LOGGER.debug("async_set_percentage called with percentage %s", percentage) if percentage == 0: await self.async_turn_off() return bond_speed = math.ceil( percentage_to_ranged_value(self._speed_range, percentage)) _LOGGER.debug( "async_set_percentage converted percentage %s to bond speed %s", percentage, bond_speed, ) await self._hub.bond.action(self._device.device_id, Action.set_speed(bond_speed))
async def async_set_percentage(self, percentage: int | None) -> None: """Set the speed percenage of the fan.""" fan_mode = math.ceil(percentage_to_ranged_value(SPEED_RANGE, percentage)) await self._async_set_fan_mode(fan_mode)