async def test_non_standard_speed_list(hass: core.HomeAssistant): """Tests that the device is registered with custom speed list if number of supported speeds differs form 3.""" await setup_platform( hass, FAN_DOMAIN, ceiling_fan("name-1"), bond_device_id="test-device-id", props={"max_speed": 6}, ) with patch_bond_device_state(): with patch_bond_action() as mock_set_speed_low: await turn_fan_on(hass, "fan.name_1", percentage=100 / 6 * 2) mock_set_speed_low.assert_called_once_with( "test-device-id", Action.set_speed(2) ) with patch_bond_action() as mock_set_speed_medium: await turn_fan_on(hass, "fan.name_1", percentage=100 / 6 * 4) mock_set_speed_medium.assert_called_once_with( "test-device-id", Action.set_speed(4) ) with patch_bond_action() as mock_set_speed_high: await turn_fan_on(hass, "fan.name_1", percentage=100) mock_set_speed_high.assert_called_once_with( "test-device-id", Action.set_speed(6) )
async def test_turn_on_fan_with_percentage_6_speeds(hass: core.HomeAssistant): """Tests that turn on command delegates to set speed API.""" await setup_platform( hass, FAN_DOMAIN, ceiling_fan("name-1"), bond_device_id="test-device-id", props={"max_speed": 6}, ) with patch_bond_action() as mock_set_speed, patch_bond_device_state(): await turn_fan_on(hass, "fan.name_1", percentage=10) mock_set_speed.assert_called_with("test-device-id", Action.set_speed(1)) mock_set_speed.reset_mock() with patch_bond_action() as mock_set_speed, patch_bond_device_state(): await turn_fan_on(hass, "fan.name_1", percentage=50) mock_set_speed.assert_called_with("test-device-id", Action.set_speed(3)) mock_set_speed.reset_mock() with patch_bond_action() as mock_set_speed, patch_bond_device_state(): await turn_fan_on(hass, "fan.name_1", percentage=100) mock_set_speed.assert_called_with("test-device-id", Action.set_speed(6))
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) )